Skip to content

Phase 5: the role-administration surface over @pegma/authorization-admin - #51

Merged
FlyOverCoderKY merged 2 commits into
mainfrom
claude/admin-surface
Jul 31, 2026
Merged

FlyOverCoderKY merged 2 commits into
mainfrom
claude/admin-surface

Conversation

@FlyOverCoderKY

Copy link
Copy Markdown
Contributor

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

  1. Admin mapped: policy advances to pegma.dev-policy-2, mapping Admin to the four admin.* permissions the surface checks (admin.principal.read / role.assign / role.revoke / audit.read).
  2. One-time Admin bootstrap: PEGMA_ADMIN_BOOTSTRAP_PRINCIPALS seeds a real audited assignment via the package's ensureSeededAssignment on 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.
  3. The surface ships gated on Admin, guard meaningful from the first request.

Pieces

  • /api/admin/* (worker): principal detail with managedBy labels, audited history, assign (Support/Admin allowlist, real principals only), revoke with the guard's typed refusals surfaced as 409s (last_administrator, system_managed, …) and compensated reported 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 durable pegma.admin.role.mutate limiter (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.
  • Version inventories updated (health detail, catalog recipe, composition doc) — the same class of drift Codex caught on Adopt Authorization Core 0.3.0: history-based bootstrap, marker collection deleted #50.

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). tsc and astro check clean.

After merge (operational, mirrors the Support seed you ran)

  1. Set the secret: 'a41f406e-6e58-4090-b5b9-62bf7a8ab65d' | npx wrangler secret put PEGMA_ADMIN_BOOTSTRAP_PRINCIPALS (CI deploys the worker on merge).
  2. Visit https://pegma.dev/staff/roles signed in — the touch seeds Admin and the panel loads.
  3. Delete the secret; the banner on the page disappears.

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings July 31, 2026 00:52
@cursor

cursor Bot commented Jul 31, 2026

Copy link
Copy Markdown

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.

Copilot AI left a comment

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.

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.ts and reuses them from the Support API.
  • Updates policy/version pins and docs to include @pegma/authorization-admin@0.4.0 and 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.

Comment thread worker/src/api-auth.ts Resolved

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 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".

Comment thread worker/src/index.ts Resolved
Comment thread worker/src/api-auth.ts Resolved
- 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>
@FlyOverCoderKY
FlyOverCoderKY merged commit 9fc8a23 into main Jul 31, 2026
1 check passed
@FlyOverCoderKY
FlyOverCoderKY deleted the claude/admin-surface branch July 31, 2026 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants