Repository navigation
Phase 5: the role-administration surface over @pegma/authorization-admin - #51
Conversation
Adopts the extracted tenth package (authorization pins 0.3.0 -> 0.4.0): - Admin mapped in policy version pegma.dev-policy-2 to the four admin.* permissions the surface checks; a role nothing checked is now checked. - /api/admin/*: principal detail with managedBy labels, audited lifecycle history, assign (Support/Admin only, real principals only), revoke with the package's last-administrator guard surfaced as typed 409s; role checks per request, fail-closed 503 on store errors; durable pegma.admin.role.mutate limiter; CSRF + same-origin on mutations. - One-time Admin bootstrap: PEGMA_ADMIN_BOOTSTRAP_PRINCIPALS seeds via ensureSeededAssignment on an authenticated admin-surface touch, before the permission check, fresh opaque ids per attempt (history is the already-seeded signal); the surface reports bootstrapArmed while set. - /staff/roles UI: lookup by exact principal id, grants with revoke (system-managed locked), assign with Admin confirmation, history. - Session/CSRF/JSON primitives extracted verbatim to api-auth.ts — the admin API is their second consumer; support-api behavior unchanged. - role-holder-index.v1: host implementation of the package's by-role holder-index port (superset-with-verification recipe). 202 node + 2 D1 tests green (7 new), tsc and astro check clean. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
There was a problem hiding this comment.
Pull request overview
Implements Phase 5 of docs/ROLE_ADOPTION_PLAN.md by adding an Admin-gated role administration surface over @pegma/authorization-admin@0.4.0, including a Worker /api/admin/* API and a /staff/roles UI for pegma.dev.
Changes:
- Adds
/api/admin/*role-administration API with Admin permission gating, audited assign/revoke, and last-administrator protection via a host holder-index. - Extracts shared session/CSRF/JSON/auth primitives into
worker/src/api-auth.tsand reuses them from the Support API. - Updates policy/version pins and docs to include
@pegma/authorization-admin@0.4.0and the new Admin role mapping.
Reviewed changes
Copilot reviewed 15 out of 16 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| worker/src/support-desk.ts | Adds durable rate limiter factory for admin role mutations; adds admin bootstrap env var to runtime env. |
| worker/src/support-api.ts | Switches Support API to shared api-auth primitives (auth/CSRF/JSON parsing/helpers). |
| worker/src/support-access.ts | Introduces Admin role + admin.* permission mapping; bumps policy version to pegma.dev-policy-2. |
| worker/src/role-holder-index.ts | Adds host implementation of RoleHolderIndex for by-role holder listing. |
| worker/src/role-bootstrap.ts | Adds parsing for PEGMA_ADMIN_BOOTSTRAP_PRINCIPALS alongside existing Support bootstrap parsing. |
| worker/src/index.ts | Wires /api/admin/* routing; composes admin API, holder index, and admin mutation limiter; updates authorization identity pin. |
| worker/src/api-auth.ts | New shared auth/CSRF/same-origin/JSON/error primitives for Support + Admin APIs. |
| worker/src/admin-api.ts | New Admin API implementing principal lookup, role assignment/revocation, and audit history over @pegma/authorization-admin. |
| worker/src/admin-api.test.ts | Adds tests covering admin access gating, bootstrap seeding, principal views/history, mutations, last-admin guard, and CSRF. |
| src/pages/staff/roles.astro | Adds /staff/roles UI shell for Admin role management. |
| public/staff-roles.js | Adds client-side admin UI logic for lookup, assign, revoke, and history rendering. |
| src/data/recipe-backlog.ts | Updates catalog recipe backlog pin for @pegma/authorization-identity@0.4.0. |
| package.json | Adds @pegma/authorization-admin@0.4.0; bumps @pegma/authorization-* packages to 0.4.0. |
| package-lock.json | Locks updated Pegma authorization package versions and adds @pegma/authorization-admin@0.4.0. |
| docs/SUPPORT_COMPOSITION.md | Updates composition inventory + storage table entries for role-holder index and staff roles surface. |
| docs/ROLE_ADOPTION_PLAN.md | Marks Phase 5 executed and documents the Phase 5 activation details. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e2fa24079a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
- readJson keeps the original contract byte-for-byte after all: request_too_large (not payload_too_large) on both 413 boundaries, and the try/finally reader.releaseLock() the extraction had dropped. - The scheduled maintenance sweep now includes the admin mutation limiter, so expired pegma.admin.role.mutate counters are swept from D1 like the support limiters' counters. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Executes docs/ROLE_ADOPTION_PLAN.md Phase 5 in its recorded activation order, composing the freshly published
@pegma/authorization-admin@0.4.0(pegma-dev/authorization-core#31). One admin tool per site — this instance administers pegma.dev only.Activation order, as planned
Adminmapped: policy advances topegma.dev-policy-2, mappingAdminto the fouradmin.*permissions the surface checks (admin.principal.read/role.assign/role.revoke/audit.read).PEGMA_ADMIN_BOOTSTRAP_PRINCIPALSseeds a real audited assignment via the package'sensureSeededAssignmenton an authenticated admin-surface touch — before the permission check, because the first administrator does not hold the role yet. Fresh opaque ids per attempt; lifecycle history is the already-seeded signal, so a revoked administrator stays revoked while the var lingers (test-pinned). The surface shows a standing warning while the var is set.Admin, guard meaningful from the first request.Pieces
/api/admin/*(worker): principal detail withmanagedBylabels, audited history, assign (Support/Admin allowlist, real principals only), revoke with the guard's typed refusals surfaced as 409s (last_administrator,system_managed, …) andcompensatedreported when the cross-instance race fires. Role checks re-resolve per request; store errors are a fail-closed 503; mutations take CSRF + same-origin + a durablepegma.admin.role.mutatelimiter (30/h)./staff/roles(site): lookup by exact principal id (email search deliberately stays out — Identity has no by-email surface), grants view with revoke buttons (system-managed rows locked), assign with an extra confirmation for Admin, ISO-timestamped history.api-auth.ts: the session/CSRF/JSON primitives extracted verbatim from the support API at their second consumer; emitted log events unchanged, support suite untouched and green.role-holder-index.v1: host implementation of the package's by-role holder-index port per the upstream-blessed recipe.Verification
202 node + 2 D1 tests green (7 new: fail-closed access order, bootstrap seed + history-durable revocation, principal views, history, mutation refusal matrix, last-administrator 409, CSRF).
tscandastro checkclean.After merge (operational, mirrors the Support seed you ran)
'a41f406e-6e58-4090-b5b9-62bf7a8ab65d' | npx wrangler secret put PEGMA_ADMIN_BOOTSTRAP_PRINCIPALS(CI deploys the worker on merge).🤖 Generated with Claude Code