Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,10 @@ jobs:
- name: Validate config
run: npm run validate

- name: Test configuration and verify Workspace SSO GitHub IDs
env:
GH_TOKEN: ${{ github.token }}
run: npm test -- --verify-github-ids

- name: Check formatting
run: npm run format:check
15 changes: 14 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Infrastructure as Code for managing access to MCP community resources using Pulu
- **Google Workspace Groups**: Automatically syncs group memberships for @modelcontextprotocol.io email accounts
- **Email Groups**: Groups with `isEmailGroup: true` accept emails from anyone (including external users) and notify all members. External posts are moderated for security.
- **Google Workspace User Accounts**: Provisions @modelcontextprotocol.io accounts for members of roles with `provisionUser: true` (directly, or via a role nested under one through `github.parent` — e.g. SDK teams under `sdk-maintainers`, working groups under `working-groups`)
- **GitHub sign-in for Google Workspace**: Cloudflare Access is the SAML identity provider for Google Workspace, so allowlisted maintainers sign in to their `@modelcontextprotocol.io` account with GitHub. The allowlist and account mapping come from [`src/config/workspaceSso.ts`](src/config/workspaceSso.ts) and `users.ts`. See [GitHub sign-in for Google Workspace](#github-sign-in-for-google-workspace) below.
- **Discord**: Syncs the Discord roles declared in [`src/config/roles.ts`](src/config/roles.ts) to the members' Discord IDs in `users.ts`, and manages the settings of the channels declared in [`src/config/channels.ts`](src/config/channels.ts), including thread-only forum/media channels. See [Discord channels](#discord-channels) below.
- **Cloudflare Access (security-room)**: Syncs the Cloudflare Zero Trust Access policy that decides who can sign in to `securityroom.modelcontextprotocol.io` from the roles declared in [`src/config/accessPolicies.ts`](src/config/accessPolicies.ts). See [Cloudflare Access (security-room)](#cloudflare-access-security-room) below.
- **npm & PyPI Package Publishing Access** (declared, not applied): Expected registry access is declared in [`src/config/packageAccess.ts`](src/config/packageAccess.ts) and drift against the live npm registry is detected by CI — but changes are applied manually by a maintainer. See [npm & PyPI Package Publishing Access](#npm--pypi-package-publishing-access) below for why and how.
Expand Down Expand Up @@ -126,6 +127,18 @@ Channels listed in [`src/config/channels.ts`](src/config/channels.ts) are manage
- With `cloudflare:importExistingPolicies: "true"` in `Pulumi.prod.yaml`, the first deploy imports the existing `Maintainers` policy (by its `cloudflarePolicyId`) as-is, ignoring its rule lists.
- Then set the flag to `"false"` in a follow-up PR; its preview shows exactly the include-rule changes that the next deploy applies. Leave the flag off from then on.

## GitHub sign-in for Google Workspace

Cloudflare Access acts as the SAML identity provider for Google Workspace. The `workspace-sso` GitHub team's direct membership and the numeric GitHub ID → Workspace email mapping both come from `users.ts`. To enable someone, confirm their `githubUserId` and add `ROLE_IDS.WORKSPACE_SSO` in a reviewed PR. They also need a current Google provisioning role. CI verifies each enabled ID against the configured GitHub login.

**Before assigning the pilot:**

1. Deploy the Access app with its inert defaults. On a throwaway SAML app, inspect the signed NameID for a mapped user and an admitted, unmapped org member (expect `unmapped@access.invalid`). Check the outcome of a transform error and an empty result. Stop if either produces a usable identity. Verify a non-team user is denied by the pilot policy. Record outcomes without sharing signed assertions.
2. Complete the [Access token hardening follow-up](https://github.com/modelcontextprotocol/access/pull/230#discussion_r4729626641) before connecting Google. The token can change the Workspace identity that Cloudflare signs.
3. A Workspace admin creates a **new SAML profile** with the Access SSO URL, entity ID and signing certificate. Keep the legacy profile disabled. Copy the new profile's SP entity ID and ACS URL into `cloudflare:googleSamlEntityId` and `cloudflare:googleSamlAcsUrl` together and deploy. Check the pilot OU's effective post-SSO 2-Step Verification settings before assigning the profile to the OU containing only sambhav@. Verify a fresh Workspace sign-in.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Step 3 says to check the 2-Step Verification settings but not what passes. Can we state it: post-SSO verification applies to SSO profile users, 2SV is enforced and the account is enrolled, and the account has no admin role?


Generated by Claude Code


**Offboarding:** suspend the Workspace account, reset its sign-in cookies and revoke OAuth grants and app passwords as applicable. Revoke the user's Cloudflare Access sessions, remove the Workspace SSO role in `users.ts`, and deploy. The Access app and policy each use one hour. Cloudflare can reuse stored GitHub membership until the global session expires (check the tenant setting), and Google manages its own sessions.

## npm & PyPI Package Publishing Access

Publishing access to the `modelcontextprotocol` npm organization and to the MCP PyPI projects is **config-as-code with human-applied changes** — deliberately outside the Pulumi resource graph:
Expand Down Expand Up @@ -232,7 +245,7 @@ The following secrets must be configured in GitHub Actions for automated deploym
- Keep this secure - if lost, you cannot decrypt your Pulumi state

- **`CLOUDFLARE_ROLE_MANAGEMENT_TOKEN`** (optional, `production` and `preview` environments): Cloudflare token dedicated to Access policy role management, scoped only to **Account → Access: Apps and Policies → Edit** on the MCP Domain Account (not a general-purpose API token)
- Used to manage the Cloudflare Access policy for `securityroom.modelcontextprotocol.io` (see [Cloudflare Access (security-room)](#cloudflare-access-security-room))
- Used to manage the Cloudflare Access policy for `securityroom.modelcontextprotocol.io` (see [Cloudflare Access (security-room)](#cloudflare-access-security-room)) and the Google Workspace sign-in application (see [GitHub sign-in for Google Workspace](#github-sign-in-for-google-workspace))
Comment thread
sambhav marked this conversation as resolved.
Resolved

## Initial Setup

Expand Down
11 changes: 11 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"scripts": {
"build": "tsc",
"validate": "npx ts-node scripts/validate-config.ts",
"test": "npx ts-node scripts/test-config.ts",
"test": "npx ts-node scripts/test-config.ts && ts-node scripts/test-workspace-sso.ts",
"check-package-drift": "npx ts-node scripts/check-package-drift.ts",
"check": "npm run format:check && npm run validate && npm run test",
"format": "prettier --write .",
Expand All @@ -22,6 +22,7 @@
},
"devDependencies": {
"@types/node": "^22.18.6",
"jsonata": "^2.2.1",
"prettier": "^3.7.2",
"ts-node": "^10.9.2",
"typescript": "^5.9.2"
Expand Down
89 changes: 89 additions & 0 deletions scripts/test-workspace-sso.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import assert from 'node:assert/strict';
import { execFileSync } from 'node:child_process';
import { test } from 'node:test';
import jsonata from 'jsonata';
import { ROLE_IDS } from '../src/config/roleIds';
import { MEMBERS } from '../src/config/users';
import type { Member } from '../src/config/utils';
import {
buildNameIdTransform,
getWorkspaceSsoTable,
googleSamlProfile,
UNMAPPED_NAME_ID,
} from '../src/config/workspaceSso';

const pilot: Member = {
github: 'octo',
githubUserId: 42,
googleEmailPrefix: 'octo',
memberOf: [ROLE_IDS.WORKSPACE_SSO, ROLE_IDS.GO_SDK],
};
const email = 'octo@modelcontextprotocol.io';
const identity = { id: 42, idp: { id: 'gh' }, groups: [{ name: 'modelcontextprotocol' }] };

test('the pilot team requires a GitHub identity and a current provisioning role', () => {
assert.deepEqual(getWorkspaceSsoTable([pilot, { ...pilot, memberOf: [] }]), { 42: email });
for (const change of [
{ github: undefined },
{ githubUserId: undefined },
{ githubUserId: -1 },
{ googleEmailPrefix: 'x@evil.com' },
{ googleEmailPrefix: undefined },
{ existingGWSUser: true, memberOf: [ROLE_IDS.WORKSPACE_SSO] },
{ skipGoogleUserProvisioning: true },
])
assert.throws(() => getWorkspaceSsoTable([{ ...pilot, ...change }]));
assert.throws(() => getWorkspaceSsoTable([pilot, { ...pilot, googleEmailPrefix: 'cat' }]));
});

test('NameID uses the numeric ID, GitHub IdP and org', async () => {
const transform = jsonata(buildNameIdTransform({ 42: email }, 'gh'));
for (const id of [42, '42']) assert.equal(await transform.evaluate({ ...identity, id }), email);
for (const change of [
{ id: 43 },
{ id: undefined },
{ id: [42] },
{ id: '__proto__' },
{ idp: { id: 'otp' } },
{ idp: undefined },
{ groups: undefined },
{ groups: [{ name: 'other' }] },
])
assert.equal(await transform.evaluate({ ...identity, ...change }), UNMAPPED_NAME_ID);
assert.equal(await jsonata(buildNameIdTransform({}, 'gh')).evaluate(identity), UNMAPPED_NAME_ID);
});

test('Google requires both profile values after inert bootstrap', () => {
const issuer = 'https://accounts.google.com/samlrp/metadata?rpid=example';
const acs = 'https://accounts.google.com/samlrp/example/acs';
assert.deepEqual(googleSamlProfile(), {
spEntityId: 'https://access.invalid/sp',
consumerServiceUrl: 'https://access.invalid/acs',
});
assert.deepEqual(googleSamlProfile(issuer, acs), { spEntityId: issuer, consumerServiceUrl: acs });
for (const id of [undefined, '', 'google.com', 'google.com/a/example.org'])
assert.throws(() => googleSamlProfile(id, acs));
for (const url of [
undefined,
'https://accounts.google.com/a/example.org/acs',
'https://www.google.com/a/example.org/acs',
])
assert.throws(() => googleSamlProfile(issuer, url));
});

test(
'GitHub IDs resolve to their configured logins',
{ skip: !process.argv.includes('--verify-github-ids') },
() => {
for (const m of MEMBERS.filter((member) => member.memberOf.includes(ROLE_IDS.WORKSPACE_SSO))) {
const login = execFileSync('gh', ['api', `/user/${m.githubUserId}`, '--jq', '.login'], {
encoding: 'utf8',
}).trim();
assert.equal(
login.toLowerCase(),
m.github?.toLowerCase(),
`GitHub user ID ${m.githubUserId} resolves to ${login}`
);
}
}
);
9 changes: 9 additions & 0 deletions scripts/validate-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import { DISCORD_CHANNELS, validateDiscordChannels } from '../src/config/channel
import { getDiscordRolePermissionErrors } from '../src/config/discordPermissions';
import { hasProvisionUserRole, resolveGoogleMemberEmail } from '../src/config/utils';
import type { RoleId } from '../src/config/roleIds';
import { getWorkspaceSsoTable } from '../src/config/workspaceSso';

const roleLookup = buildRoleLookup();

Expand Down Expand Up @@ -445,6 +446,14 @@ for (const role of ROLES) {
}
}

console.log('Validating Workspace SSO members...');
try {
getWorkspaceSsoTable();
} catch (e) {
console.error(`ERROR: ${(e as Error).message}`);
hasErrors = true;
}

if (hasErrors) {
console.error('\nValidation failed! Please fix the errors above.');
process.exit(1);
Expand Down
51 changes: 51 additions & 0 deletions src/cloudflare.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import * as pulumi from '@pulumi/pulumi';
import * as cloudflare from '@pulumi/cloudflare';
import { ACCESS_POLICIES, GITHUB_ORG, getAccessPolicyTeams } from './config/accessPolicies';
import { ROLE_IDS } from './config/roleIds';
import {
buildNameIdTransform,
getWorkspaceSsoTable,
googleSamlProfile,
} from './config/workspaceSso';

const config = new pulumi.Config('cloudflare');
// Cloudflare integration is optional - only enabled if roleManagementToken is configured,
Expand Down Expand Up @@ -65,6 +71,51 @@ if (CLOUDFLARE_ENABLED) {
}
);
});

// GitHub sign-in for Google Workspace: Access is the SAML IdP for Google's SSO
// profile. Workspace SSO team only, GitHub only; the NameID transform picks the account.
const workspaceSsoPolicy = new cloudflare.ZeroTrustAccessPolicy(
'access-policy-workspace-sso',
{
accountId,
name: 'Google Workspace sign-in',
decision: 'allow',
sessionDuration: '1h',
includes: [
{
githubOrganization: {
identityProviderId: githubIdentityProviderId,
name: GITHUB_ORG,
team: ROLE_IDS.WORKSPACE_SSO,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The policy names the team as a string, so it doesn't wait for Pulumi to create it. Can we pass the name from the team resource in github.ts, so the policy only exists once this repo owns the team?


Generated by Claude Code

},
},
],
},
{ provider, ignoreChanges: ['connectionRules'] }
);
new cloudflare.ZeroTrustAccessApplication(
'access-app-workspace-sso',
{
accountId,
name: 'Google Workspace',
type: 'saas',
allowedIdps: [githubIdentityProviderId],
autoRedirectToIdentity: true,
appLauncherVisible: false,
sessionDuration: '1h',
policies: [{ id: workspaceSsoPolicy.id, precedence: 1 }],
saasApp: {
authType: 'saml',
...googleSamlProfile(config.get('googleSamlEntityId'), config.get('googleSamlAcsUrl')),
nameIdFormat: 'email',
nameIdTransformJsonata: buildNameIdTransform(
getWorkspaceSsoTable(),
githubIdentityProviderId
),
},
Comment on lines +105 to +115

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two small additions:


Generated by Claude Code

},
{ provider }
);
}

export const cloudflareAccessPolicyIds = Object.fromEntries(
Expand Down
1 change: 1 addition & 0 deletions src/config/roleIds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const ROLE_IDS = {
MEMBERS: 'members', // Contributor ladder Member tier
MODERATORS: 'moderators',
SECURITY_MANAGERS: 'security-managers', // GitHub (org security_manager role) and the security@ email group
WORKSPACE_SSO: 'workspace-sso',
SECURITY_TEAM: 'security-team', // GitHub only (MCP Security Team; Cloudflare Access to securityroom.modelcontextprotocol.io)
ADMINISTRATORS: 'administrators', // Discord only
COMMUNITY_MANAGERS: 'community-managers', // Discord only
Expand Down
5 changes: 5 additions & 0 deletions src/config/roles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,11 @@ export const ROLES: readonly Role[] = [
github: { team: 'steering-committee' },
// No discord - this is a GitHub-only organizational container
},
{
id: ROLE_IDS.WORKSPACE_SSO,
description: 'Members enabled for Google Workspace SAML sign-in',
github: { team: ROLE_IDS.WORKSPACE_SSO },
},
{
id: ROLE_IDS.ADMINISTRATORS,
description: 'Discord server administrators',
Expand Down
2 changes: 2 additions & 0 deletions src/config/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -980,12 +980,14 @@ export const MEMBERS: readonly Member[] = [
},
{
github: 'sambhav',
githubUserId: 16130816,
email: 'sambhavs.email@gmail.com',
firstName: 'Sambhav',
lastName: 'Kothari',
googleEmailPrefix: 'sambhav',
discord: '840109459212206090',
memberOf: [
ROLE_IDS.WORKSPACE_SSO,
ROLE_IDS.MAINTAINERS,
ROLE_IDS.FILESYSTEMS_WG,
ROLE_IDS.FILESYSTEMS_WG_LEADS,
Expand Down
2 changes: 2 additions & 0 deletions src/config/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import type { Role } from './roles';
export interface Member {
/** GitHub username */
github?: string;
/** Numeric GitHub user ID, confirmed with the member (required for the workspace-sso team) */
githubUserId?: number;
/** Email address (for Google Workspace) */
email?: string;
/** Discord user ID (snowflake) */
Expand Down
70 changes: 70 additions & 0 deletions src/config/workspaceSso.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// GitHub sign-in for Google Workspace via a Cloudflare Access SAML app (src/cloudflare.ts).
// See README "GitHub sign-in for Google Workspace".
import { GITHUB_ORG } from './accessPolicies';
import { ROLE_IDS } from './roleIds';
import { buildRoleLookup } from './roles';
import { MEMBERS } from './users';
import { hasProvisionUserRole, resolveGoogleMemberEmail, type Member } from './utils';

/** NameID for anyone not mapped; `.invalid` (RFC 2606) is never a Workspace account. */
export const UNMAPPED_NAME_ID = 'unmapped@access.invalid';

/** `githubUserId -> Workspace email` for members of the Workspace SSO team; throws on bad config. */
export function getWorkspaceSsoTable(members: readonly Member[] = MEMBERS): Record<string, string> {
const table: Record<string, string> = {};
const roles = buildRoleLookup();
for (const m of members.filter((m) => m.memberOf.includes(ROLE_IDS.WORKSPACE_SSO))) {
if (!m.github || !hasProvisionUserRole(m.memberOf, roles) || m.skipGoogleUserProvisioning) {
throw new Error(
`Workspace SSO: "${m.googleEmailPrefix}" needs a GitHub login and a provisioning role`
);
}
const id = m.githubUserId ?? 0;
if (
!Number.isSafeInteger(id) ||
id <= 0 ||
String(id) in table ||
!/^[a-z0-9][a-z0-9._-]*$/.test(m.googleEmailPrefix ?? '')
) {
throw new Error(
`Workspace SSO: "${m.github}" needs a unique githubUserId and googleEmailPrefix`
);
}
table[String(id)] = resolveGoogleMemberEmail(m)!;
}
return table;
}

/**
* JSONata NameID transform, evaluated against the Access identity: `id` (numeric
* GitHub user ID), `idp.id` (login method), `groups[].name` (GitHub orgs).
* Unmapped inputs evaluate to UNMAPPED_NAME_ID. Literals are JSON-encoded, so config can't inject JSONata.
*/
export function buildNameIdTransform(table: Record<string, string>, githubIdpId: string): string {
return `(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The description says an engine difference fails closed. The expression does, but Cloudflare doesn't document what it sends when a transform errors or returns nothing, and the default NameID is the user's email. If it falls back to that, the allowlist is skipped for any org member whose GitHub email is on our domain.

Before the Google profile is assigned, can you capture the SAML response for an unlisted org member and confirm the NameID is unmapped@access.invalid, then do the same with a deliberately broken transform on a throwaway app? Narrowing the Access policy from the whole org to a dedicated team would also limit the damage if it does fall back.


Generated by Claude Code

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both checks use a throwaway app, so they don't need this merged, and this thread has to be resolved before merge anyway. Can you run them first and post the results here? While the app is up:

  • Use the exact expression from buildNameIdTransform.
  • Save the app once in the dashboard, then read it back through the API to confirm the transform survives.
  • If an error or empty result falls back to the email, try nameIdFormat: 'id' and check that a mapped user still gets the emailAddress format.
  • Keep Google's SP values off the throwaway app, and delete it afterwards.

Generated by Claude Code

$allowed := idp.id = ${JSON.stringify(githubIdpId)} and ${JSON.stringify(GITHUB_ORG)} in groups.name and $type(id) in ["number", "string"];
$email := $allowed ? $lookup(${JSON.stringify(table)}, $string(id));
$type($email) = "string" ? $email : ${JSON.stringify(UNMAPPED_NAME_ID)}
)`;
}

/** Bootstrap without a Google destination until the modern profile supplies both SP values. */
export function googleSamlProfile(spEntityId?: string, consumerServiceUrl?: string) {
if (spEntityId === undefined && consumerServiceUrl === undefined) {
return {
spEntityId: 'https://access.invalid/sp',
consumerServiceUrl: 'https://access.invalid/acs',
};
}
const acs = consumerServiceUrl && new URL(consumerServiceUrl);
if (
!spEntityId?.trim() ||
/^google\.com(?:\/|$)/i.test(spEntityId.trim()) ||
!acs ||
acs.origin !== 'https://accounts.google.com' ||
!acs.pathname.startsWith('/samlrp/')
) {
throw new Error('Set both SP values from the modern Google SAML profile in the Admin console');
}
return { spEntityId, consumerServiceUrl: acs.href };
}
Loading