feat(admin): access-control foundation + audit log (#28) - #42
Closed
serge-ivo wants to merge 1 commit into
Closed
Conversation
First slice of the PAGS Admin Portal epic (#27). Wires up the previously unused requireAdmin and adds the operator plumbing everything else builds on: - requireAdmin hardened to defense-in-depth: admin resolves from the session role -> a live users.roles read (no stale-token lockout / instant grant) -> ADMIN_ALLOWLIST env break-glass (by uid). New isAdmin() helper. - Cloudflare Access perimeter (lib/cf-access.ts) as middleware on /v1/admin/*: verifies Cf-Access-Jwt-Assertion (RS256 vs team JWKS). Inert until CF_ACCESS_TEAM_DOMAIN + CF_ACCESS_AUD are set. - admin_audit_log table (migration 0049) + recordAdminAction()/listAdminAudit() so every future privileged mutation is recorded (closes the audit-trail gap PAS still has). Operator account bootstrapped as admin, idempotently. - New /v1/admin route group: GET /v1/admin/me (is-admin probe for the UI) and GET /v1/admin/audit (filterable log reader). - 7 route tests (role/live-role/allowlist/401/403 + audit); typecheck clean. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This was referenced Jul 31, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #28. First slice of the PAGS Admin Portal epic #27.
What
Wires up the previously-unused
requireAdminand adds the operator plumbing every other admin issue builds on.requireAdminnow resolves admin from: session role → liveusers.rolesread (freshly granted/revoked admin takes effect immediately; no stale-token lockout) →ADMIN_ALLOWLISTenv break-glass (by uid, bootstraps the first admin). NewisAdmin()helper.lib/cf-access.tsmiddleware on/v1/admin/*verifiesCf-Access-Jwt-Assertion(RS256 vs team JWKS). Inert untilCF_ACCESS_TEAM_DOMAIN+CF_ACCESS_AUDare set — turn on before real onboarding, no code change.admin_audit_log(migration0049) +recordAdminAction()/listAdminAudit()so every future privileged mutation is recorded (closes the audit-trail gap PAS still has). Operator bootstrapped as admin idempotently.GET /v1/admin/me(is-admin probe the UI calls on load) +GET /v1/admin/audit(filterable reader).Tests
workers/api/src/routes/admin.test.ts— 7 tests: session-role / live-role / allowlist / 401 / 403 / audit read. Typecheck clean; migration + auth + agents suites green (no regressions).Follow-ups (epic #27)
Unblocks the API tickets #30–#34 and infra #29. Best-practice notes for CF-billing-actuals spend live on #32.