Add npm/PyPI package publishing access management (config + drift detection) (#169)
* Add npm/PyPI package publishing access management (config + drift detection) Declare expected npm org membership, per-package maintainers and trusted publishers, and PyPI project rosters in src/config/packageAccess.ts, with npm/pypi identity fields on members in users.ts. Deliberately outside the Pulumi resource graph: npm governance writes require an interactive 2FA challenge since August 2026 (read endpoints still work with a granular access token), and PyPI has no management API at all. Drift against the live npm registry is detected read-only by scripts/check-package-drift.ts (weekly via package-drift.yml, no-op when the NPM_READ_TOKEN secret is absent), which emits a remediation plan of npm CLI commands for a maintainer to run in one 2FA-approved session. PyPI procedures are documented as a manual runbook in the README. * Encode all slashes when escaping package names in registry URLs Fixes the CodeQL finding: String.replace with a string pattern only replaces the first occurrence. Use a shared helper with a global regex, following the npm CLI convention (keep '@' literal, encode every '/'). --------- Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
parent
ca10c555cc
commit
f17de4044a
1 changed files with 766 additions and 0 deletions
|
|
@ -9,6 +9,14 @@ import { ROLES, buildRoleLookup, getRolesForPlatform } from '../src/config/roles
|
|||
import { ROLE_IDS, isValidRoleId } from '../src/config/roleIds';
|
||||
import { MEMBERS } from '../src/config/users';
|
||||
import { hasProvisionUserRole } from '../src/config/utils';
|
||||
import {
|
||||
NPM_ORG,
|
||||
NPM_PACKAGES,
|
||||
PYPI_PROJECTS,
|
||||
getExpectedNpmOrgMembers,
|
||||
getNpmPackageAccess,
|
||||
NPM_DEFAULT_POLICY,
|
||||
} from '../src/config/packageAccess';
|
||||
|
||||
let passed = 0;
|
||||
let failed = 0;
|
||||
|
|
@ -124,6 +132,46 @@ test('Some members in provisionUser roles have Google user fields', () => {
|
|||
return membersInProvisionRoles.length > 0 && provisioned.length > 0;
|
||||
});
|
||||
|
||||
// Test package registry access config
|
||||
test('NPM_ORG is modelcontextprotocol', () => NPM_ORG === 'modelcontextprotocol');
|
||||
test('NPM_PACKAGES is not empty and all packages are org-scoped', () =>
|
||||
NPM_PACKAGES.length > 0 && NPM_PACKAGES.every((p) => p.package.startsWith(`@${NPM_ORG}/`)));
|
||||
test('All NPM_PACKAGES have at least one maintainer', () =>
|
||||
NPM_PACKAGES.every((p) => p.maintainers.length > 0));
|
||||
test('npm usernames on members are unique', () => {
|
||||
const usernames = MEMBERS.filter((m) => m.npm).map((m) => m.npm);
|
||||
return usernames.length === new Set(usernames).size;
|
||||
});
|
||||
test('pypi usernames on members are unique', () => {
|
||||
const usernames = MEMBERS.filter((m) => m.pypi).map((m) => m.pypi);
|
||||
return usernames.length === new Set(usernames).size;
|
||||
});
|
||||
test('Expected npm org membership is non-empty, sorted, and unique', () => {
|
||||
const orgMembers = getExpectedNpmOrgMembers();
|
||||
const sorted = [...orgMembers].sort((a, b) => a.localeCompare(b));
|
||||
return (
|
||||
orgMembers.length > 0 &&
|
||||
orgMembers.length === new Set(orgMembers).size &&
|
||||
orgMembers.every((username, i) => username === sorted[i])
|
||||
);
|
||||
});
|
||||
test('getNpmPackageAccess falls back to the default policy', () => {
|
||||
const access = getNpmPackageAccess(`@${NPM_ORG}/some-undeclared-package`);
|
||||
return access.maintainers === NPM_DEFAULT_POLICY.maintainers && !access.trustedPublisher;
|
||||
});
|
||||
test('getNpmPackageAccess returns explicit entries', () => {
|
||||
const access = getNpmPackageAccess(`@${NPM_ORG}/sdk`);
|
||||
return !!access.trustedPublisher;
|
||||
});
|
||||
test('PYPI_PROJECTS includes the mcp project with accounts', () => {
|
||||
const mcp = PYPI_PROJECTS.find((p) => p.project === 'mcp');
|
||||
return !!mcp && mcp.accounts.length > 0;
|
||||
});
|
||||
test('PyPI project names are unique', () => {
|
||||
const names = PYPI_PROJECTS.map((p) => p.project);
|
||||
return names.length === new Set(names).size;
|
||||
});
|
||||
|
||||
// Summary
|
||||
console.log(`\n${passed} passed, ${failed} failed`);
|
||||
process.exit(failed > 0 ? 1 : 0);
|
||||
|
|
|
|||
Loading…
Reference in a new issue