diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 65ea36e..5960ec1 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/README.md b/README.md index d0255af..f473d43 100644 --- a/README.md +++ b/README.md @@ -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. @@ -127,6 +128,16 @@ 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. + +Use a modern Google Workspace SAML profile and keep legacy SSO disabled. Configure the profile with the Cloudflare Access SSO URL, entity ID and signing certificate. Set `cloudflare:googleSamlEntityId` and `cloudflare:googleSamlAcsUrl` together using the values from that profile. With both values unset, the app uses placeholders under the reserved `.invalid` domain. The Access edit token can change which Workspace identity Cloudflare signs. + +For accounts assigned to the profile, confirm that post-SSO verification applies, 2-Step Verification is enforced, and each user is enrolled. Keep Workspace admin accounts outside the assigned organizational unit. + +**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: @@ -233,7 +244,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)) ## Initial Setup diff --git a/package-lock.json b/package-lock.json index 291fae3..b808d20 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,6 +17,7 @@ }, "devDependencies": { "@types/node": "^22.18.6", + "jsonata": "^2.2.1", "prettier": "^3.7.2", "ts-node": "^10.9.2", "typescript": "^5.9.2" @@ -1142,6 +1143,16 @@ "js-yaml": "bin/js-yaml.js" } }, + "node_modules/jsonata": { + "version": "2.3.0", + "resolved": "https://registry.npmjs.org/jsonata/-/jsonata-2.3.0.tgz", + "integrity": "sha512-M2oCpvM32+f70iXmunUmrkASEfSuLkcr/CIZ2VTUOw4+ONSD7Pm9ecw8rocRlX2f/ev/sGgPLjInCZFop7Lhng==", + "dev": true, + "license": "MIT", + "engines": { + "node": ">= 8" + } + }, "node_modules/lodash.camelcase": { "version": "4.3.0", "resolved": "https://registry.npmjs.org/lodash.camelcase/-/lodash.camelcase-4.3.0.tgz", diff --git a/package.json b/package.json index f65c58b..168331c 100644 --- a/package.json +++ b/package.json @@ -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 .", @@ -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" diff --git a/scripts/test-workspace-sso.ts b/scripts/test-workspace-sso.ts new file mode 100644 index 0000000..9801f94 --- /dev/null +++ b/scripts/test-workspace-sso.ts @@ -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}` + ); + } + } +); diff --git a/scripts/validate-config.ts b/scripts/validate-config.ts index e75ccad..bbe9bb2 100644 --- a/scripts/validate-config.ts +++ b/scripts/validate-config.ts @@ -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(); @@ -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); diff --git a/src/cloudflare.ts b/src/cloudflare.ts index 08c4c64..f4ae564 100644 --- a/src/cloudflare.ts +++ b/src/cloudflare.ts @@ -1,6 +1,13 @@ import * as pulumi from '@pulumi/pulumi'; import * as cloudflare from '@pulumi/cloudflare'; import { ACCESS_POLICIES, GITHUB_ORG, getAccessPolicyTeams } from './config/accessPolicies'; +import { githubTeams } from './github'; +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, @@ -65,6 +72,53 @@ 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: githubTeams[ROLE_IDS.WORKSPACE_SSO].slug, + }, + }, + ], + }, + { provider, ignoreChanges: ['connectionRules'] } + ); + new cloudflare.ZeroTrustAccessApplication( + 'access-app-workspace-sso', + { + accountId, + name: 'Google Workspace', + type: 'saas', + allowedIdps: [githubIdentityProviderId], + allowAuthenticateViaWarp: false, + autoRedirectToIdentity: true, + appLauncherVisible: false, + sessionDuration: '1h', + policies: [{ id: workspaceSsoPolicy.id, precedence: 1 }], + saasApp: { + authType: 'saml', + ...googleSamlProfile(config.get('googleSamlEntityId'), config.get('googleSamlAcsUrl')), + nameIdFormat: 'email', + samlAttributeTransformJsonata: '{}', // Google uses the subject NameID alone. + nameIdTransformJsonata: buildNameIdTransform( + getWorkspaceSsoTable(), + githubIdentityProviderId + ), + }, + }, + { provider } + ); } export const cloudflareAccessPolicyIds = Object.fromEntries( diff --git a/src/config/roleIds.ts b/src/config/roleIds.ts index 0be8ace..20e1e59 100644 --- a/src/config/roleIds.ts +++ b/src/config/roleIds.ts @@ -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 diff --git a/src/config/roles.ts b/src/config/roles.ts index ecf7f3c..4cd53ed 100644 --- a/src/config/roles.ts +++ b/src/config/roles.ts @@ -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', diff --git a/src/config/users.ts b/src/config/users.ts index d9f7238..9bf3218 100644 --- a/src/config/users.ts +++ b/src/config/users.ts @@ -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, diff --git a/src/config/utils.ts b/src/config/utils.ts index 4178427..7bf3234 100644 --- a/src/config/utils.ts +++ b/src/config/utils.ts @@ -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) */ diff --git a/src/config/workspaceSso.ts b/src/config/workspaceSso.ts new file mode 100644 index 0000000..2518eb1 --- /dev/null +++ b/src/config/workspaceSso.ts @@ -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 { + const table: Record = {}; + 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, githubIdpId: string): string { + return `( + $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 }; +}