Skip to content

Commit 9016b96

Browse files
localdenclaude
andauthored
Give collaborator teams the access they declare (#266)
Remove the parent teams that gave registry-collaborators and typescript-sdk-collaborators more than their declared push, and validate that no team is granted less than it inherits. Co-authored-by: Claude <noreply@anthropic.com>
1 parent cca48af commit 9016b96

6 files changed

Lines changed: 152 additions & 9 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ The [contributor ladder](https://modelcontextprotocol.io/community/contributor-l
7979

8080
Things to know when reading the config against the ladder:
8181

82-
- **GitHub child teams inherit their parent's repository access.** WG, IG, and SDK teams nest under `steering-committee` (via `working-groups`, `interest-groups`, and `sdk-maintainers`). Their members therefore get `steering-committee`'s grants, which include `triage` on `modelcontextprotocol`, `.github`, `inspector`, and `quickstart-resources`, and `push` on the archived `docs` repository. `steering-committee` deliberately has no grant on `servers`, so the teams listed there each have their own `triage` grant. Write access on `inspector`, `servers`, and `quickstart-resources` comes from the team that owns each one: `inspector-maintainers` on `inspector`, `reference-servers-maintainers` on `servers`, and `docs-maintainers` on `quickstart-resources`. This is independent of ladder rank. Roles that must not inherit these grants (`members`, `maintainers`, `access-maintainers`, `security-team`) have no parent.
82+
- **GitHub child teams inherit their parent's repository access.** WG, IG, and SDK teams nest under `steering-committee` (via `working-groups`, `interest-groups`, and `sdk-maintainers`). Their members therefore get `steering-committee`'s grants, which include `triage` on `modelcontextprotocol`, `.github`, `inspector`, and `quickstart-resources`, and `push` on the archived `docs` repository. `steering-committee` deliberately has no grant on `servers`, so the teams listed there each have their own `triage` grant. Write access on `inspector`, `servers`, and `quickstart-resources` comes from the team that owns each one: `inspector-maintainers` on `inspector`, `reference-servers-maintainers` on `servers`, and `docs-maintainers` on `quickstart-resources`. This is independent of ladder rank. Roles that must not inherit these grants (`members`, `maintainers`, `access-maintainers`, `security-team`, `registry-collaborators`, `typescript-sdk-collaborators`) have no parent. A child team's grant can't be lower than its parent's on the same repository, and `npm run validate` fails if one is.
8383
- **Some roles have no ladder counterpart.** These are functional or operational roles: `security-managers`, `security-team`, CODEOWNERS teams (`*-auth`, `conformance-auth`), collaborator teams (`registry-collaborators`, `typescript-sdk-collaborators`), `auth-contributors` (`push` on `ext-auth` only, no parent team), `access-maintainers` (`push` on `access` only, no parent team), `csharp-sdk-admin`, Discord-only `administrators` and `community-managers`, and Google email groups.
8484
- **Per-user grants** in `repoAccess.ts` (the `users` lists) are not tied to any ladder role.
8585
- **`security-ig` has `admin` on six repositories** (`docs`, `.github`, `inspector`, `modelcontextprotocol`, `quickstart-resources`, `servers`). This was carried over unchanged from `security-wg` in #170, and reviewing it is tracked as a separate workstream.

‎scripts/test-config.ts‎

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
* Run with: npx ts-node scripts/test-config.ts
66
*/
77

8-
import { ROLES, buildRoleLookup, getRolesForPlatform } from '../src/config/roles';
8+
import { ROLES, buildRoleLookup, getRolesForPlatform, type Role } from '../src/config/roles';
99
import { ROLE_IDS, isValidRoleId } from '../src/config/roleIds';
1010
import { MEMBERS } from '../src/config/users';
11-
import { hasProvisionUserRole } from '../src/config/utils';
11+
import { getIneffectiveGrantErrors, hasProvisionUserRole } from '../src/config/utils';
1212
import {
1313
NPM_ORG,
1414
NPM_PACKAGES,
@@ -18,7 +18,11 @@ import {
1818
NPM_DEFAULT_POLICY,
1919
} from '../src/config/packageAccess';
2020
import { ACCESS_POLICIES, getAccessPolicyTeams } from '../src/config/accessPolicies';
21-
import { REPOSITORY_ACCESS, REPOSITORY_DEFAULTS } from '../src/config/repoAccess';
21+
import {
22+
REPOSITORY_ACCESS,
23+
REPOSITORY_DEFAULTS,
24+
type RepositoryAccess,
25+
} from '../src/config/repoAccess';
2226
import {
2327
DISCORD_CHANNELS,
2428
DISCORD_CHANNEL_FLAG_REQUIRE_TAG,
@@ -103,6 +107,59 @@ test('All GitHub parent references are valid', () =>
103107
return parent && parent.github;
104108
}));
105109

110+
// Test inherited team permissions
111+
const grantRoles: Role[] = [
112+
{ id: ROLE_IDS.STEERING_COMMITTEE, description: '', github: { team: 'top' } },
113+
{
114+
id: ROLE_IDS.SDK_MAINTAINERS,
115+
description: '',
116+
github: { team: 'middle', parent: ROLE_IDS.STEERING_COMMITTEE },
117+
},
118+
{
119+
id: ROLE_IDS.TYPESCRIPT_SDK,
120+
description: '',
121+
github: { team: 'bottom', parent: ROLE_IDS.SDK_MAINTAINERS },
122+
},
123+
];
124+
const grantErrors = (teams: RepositoryAccess['teams']) =>
125+
getIneffectiveGrantErrors([{ repository: 'repo', teams }], grantRoles, []);
126+
test('A grant below the parent team is rejected', () => {
127+
const errors = grantErrors([
128+
{ team: 'middle', permission: 'admin' },
129+
{ team: 'bottom', permission: 'push' },
130+
]);
131+
return errors.length === 1 && /"push" to team "bottom".*"middle" has "admin"/.test(errors[0]);
132+
});
133+
test('A grant below a higher ancestor is rejected when the parent has none', () =>
134+
grantErrors([
135+
{ team: 'bottom', permission: 'pull' },
136+
{ team: 'top', permission: 'triage' },
137+
]).length === 1);
138+
test('A grant equal to or above the parent team is accepted', () =>
139+
grantErrors([
140+
{ team: 'middle', permission: 'push' },
141+
{ team: 'bottom', permission: 'push' },
142+
]).length === 0 &&
143+
grantErrors([
144+
{ team: 'middle', permission: 'triage' },
145+
{ team: 'bottom', permission: 'maintain' },
146+
]).length === 0);
147+
test('A grant below an ancestor organization role is rejected', () =>
148+
getIneffectiveGrantErrors(
149+
[{ repository: 'repo', teams: [{ team: 'bottom', permission: 'push' }] }],
150+
grantRoles,
151+
[{ team: 'top', role: 'all_repo_admin' }]
152+
).length === 1);
153+
test('Collaborator teams have no parent team', () =>
154+
[ROLE_IDS.REGISTRY_COLLABORATORS, ROLE_IDS.TYPESCRIPT_SDK_COLLABORATORS].every(
155+
(id) => roleLookup.get(id)?.github?.parent === undefined
156+
));
157+
test('A parent may be granted less than its child', () =>
158+
grantErrors([
159+
{ team: 'top', permission: 'pull' },
160+
{ team: 'bottom', permission: 'admin' },
161+
]).length === 0);
162+
106163
// Test members
107164
test('MEMBERS array is not empty', () => MEMBERS.length > 0);
108165
test('All members have at least one identifier', () =>

‎scripts/validate-config.ts‎

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
*/
77

88
import { ROLES, buildRoleLookup } from '../src/config/roles';
9+
import { ORG_ROLE_ASSIGNMENTS } from '../src/config/orgRoles';
910
import { REPOSITORY_ACCESS } from '../src/config/repoAccess';
1011
import {
1112
NPM_PACKAGES,
@@ -17,7 +18,11 @@ import { MEMBERS } from '../src/config/users';
1718
import { ACCESS_POLICIES } from '../src/config/accessPolicies';
1819
import { DISCORD_CHANNELS, validateDiscordChannels } from '../src/config/channels';
1920
import { getDiscordRolePermissionErrors } from '../src/config/discordPermissions';
20-
import { hasProvisionUserRole, resolveGoogleMemberEmail } from '../src/config/utils';
21+
import {
22+
getIneffectiveGrantErrors,
23+
hasProvisionUserRole,
24+
resolveGoogleMemberEmail,
25+
} from '../src/config/utils';
2126
import type { RoleId } from '../src/config/roleIds';
2227
import { getWorkspaceSsoTable } from '../src/config/workspaceSso';
2328

@@ -446,6 +451,13 @@ for (const role of ROLES) {
446451
}
447452
}
448453

454+
// Validate that no team is granted less than it inherits from its ancestors
455+
console.log('Validating inherited team permissions in repoAccess.ts...');
456+
for (const error of getIneffectiveGrantErrors(REPOSITORY_ACCESS, ROLES, ORG_ROLE_ASSIGNMENTS)) {
457+
console.error(`ERROR: ${error}`);
458+
hasErrors = true;
459+
}
460+
449461
console.log('Validating Workspace SSO members...');
450462
try {
451463
getWorkspaceSsoTable();

‎src/config/repoAccess.ts‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,10 @@ export const REPOSITORY_ACCESS: RepositoryAccess[] = [
371371
},
372372
{
373373
repository: 'static',
374-
teams: [{ team: 'registry-wg', permission: 'push' }],
374+
teams: [
375+
{ team: 'registry-wg', permission: 'push' },
376+
{ team: 'registry-collaborators', permission: 'push' },
377+
],
375378
},
376379
{
377380
repository: 'core-primitives-wg',

‎src/config/roles.ts‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,10 @@ export const ROLES: readonly Role[] = [
232232
{
233233
id: ROLE_IDS.REGISTRY_COLLABORATORS,
234234
description: 'Registry working group collaborators',
235-
github: { team: 'registry-collaborators', parent: ROLE_IDS.REGISTRY_MAINTAINERS },
235+
// No parent team: must not inherit registry-wg's admin on registry
236+
github: { team: 'registry-collaborators' },
237+
discordImplies: [ROLE_IDS.REGISTRY_MAINTAINERS],
238+
provisionUser: true,
236239
},
237240
{
238241
id: ROLE_IDS.USE_MCP_MAINTAINERS,
@@ -341,8 +344,10 @@ export const ROLES: readonly Role[] = [
341344
{
342345
id: ROLE_IDS.TYPESCRIPT_SDK_COLLABORATORS,
343346
description: 'TypeScript SDK collaborators',
344-
github: { team: 'typescript-sdk-collaborators', parent: ROLE_IDS.TYPESCRIPT_SDK },
345-
// GitHub only
347+
// No parent team: must not inherit typescript-sdk's admin on typescript-sdk
348+
github: { team: 'typescript-sdk-collaborators' },
349+
discordImplies: [ROLE_IDS.TYPESCRIPT_SDK],
350+
provisionUser: true,
346351
},
347352

348353
// ===================

‎src/config/utils.ts‎

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import type { OrgRoleAssignment, OrgRoleName } from './orgRoles';
2+
import type { RepositoryAccess, RepositoryPermission } from './repoAccess';
13
import type { RoleId } from './roleIds';
24
import type { Role } from './roles';
35

@@ -150,3 +152,67 @@ export {
150152
type DiscordConfig,
151153
type GoogleConfig,
152154
} from './roles';
155+
156+
/** Repository permissions, lowest first. */
157+
const PERMISSION_ORDER: readonly RepositoryPermission[] = [
158+
'pull',
159+
'triage',
160+
'push',
161+
'maintain',
162+
'admin',
163+
];
164+
165+
/** Permission each organization role gives on every repository. */
166+
const ORG_ROLE_PERMISSIONS: Partial<Record<OrgRoleName, RepositoryPermission>> = {
167+
all_repo_read: 'pull',
168+
all_repo_triage: 'triage',
169+
all_repo_write: 'push',
170+
all_repo_maintain: 'maintain',
171+
all_repo_admin: 'admin',
172+
};
173+
174+
/**
175+
* Find grants that GitHub ignores. A child team always has at least its
176+
* ancestors' access to a repository, from their grants or their organization
177+
* roles, so declaring a lower permission for the child has no effect.
178+
*/
179+
export function getIneffectiveGrantErrors(
180+
repositories: readonly RepositoryAccess[],
181+
roles: readonly Role[],
182+
orgRoleAssignments: readonly OrgRoleAssignment[]
183+
): string[] {
184+
const rank = (permission: RepositoryPermission | undefined) =>
185+
permission ? PERMISSION_ORDER.indexOf(permission) : -1;
186+
const orgPermissions = new Map(
187+
orgRoleAssignments.map((a) => [a.team, ORG_ROLE_PERMISSIONS[a.role]])
188+
);
189+
const roleById = new Map<RoleId, Role>(roles.map((role) => [role.id, role]));
190+
const roleByTeam = new Map<string, Role>();
191+
for (const role of roles) {
192+
if (role.github) roleByTeam.set(role.github.team, role);
193+
}
194+
195+
const errors: string[] = [];
196+
for (const repo of repositories) {
197+
const permissions = new Map(repo.teams?.map((t) => [t.team, t.permission]));
198+
for (const [team, permission] of permissions) {
199+
const visited = new Set<RoleId>();
200+
let parentId = roleByTeam.get(team)?.github?.parent;
201+
while (parentId && !visited.has(parentId)) {
202+
visited.add(parentId);
203+
const ancestor = roleById.get(parentId)?.github;
204+
const granted = ancestor && permissions.get(ancestor.team);
205+
const fromOrgRole = ancestor && orgPermissions.get(ancestor.team);
206+
const inherited = rank(granted) >= rank(fromOrgRole) ? granted : fromOrgRole;
207+
if (ancestor && rank(permission) < rank(inherited)) {
208+
errors.push(
209+
`Repository "${repo.repository}" grants "${permission}" to team "${team}", but its ` +
210+
`ancestor team "${ancestor.team}" has "${inherited}", which child teams inherit`
211+
);
212+
}
213+
parentId = ancestor?.parent;
214+
}
215+
}
216+
}
217+
return errors;
218+
}

0 commit comments

Comments
 (0)