Skip to content

feat(admin): access-control foundation + audit log (#28) - #42

Closed
serge-ivo wants to merge 1 commit into
mainfrom
feat/admin-foundation
Closed

feat(admin): access-control foundation + audit log (#28)#42
serge-ivo wants to merge 1 commit into
mainfrom
feat/admin-foundation

Conversation

@serge-ivo

Copy link
Copy Markdown
Contributor

Closes #28. First slice of the PAGS Admin Portal epic #27.

What

Wires up the previously-unused requireAdmin and adds the operator plumbing every other admin issue builds on.

  • Defense-in-depth auth. requireAdmin now resolves admin from: session role → live users.roles read (freshly granted/revoked admin takes effect immediately; no stale-token lockout) → ADMIN_ALLOWLIST env break-glass (by uid, bootstraps the first admin). New isAdmin() helper.
  • Cloudflare Access perimeter. lib/cf-access.ts middleware on /v1/admin/* verifies Cf-Access-Jwt-Assertion (RS256 vs team JWKS). Inert until CF_ACCESS_TEAM_DOMAIN + CF_ACCESS_AUD are set — turn on before real onboarding, no code change.
  • Audit log. admin_audit_log (migration 0049) + recordAdminAction() / listAdminAudit() so every future privileged mutation is recorded (closes the audit-trail gap PAS still has). Operator bootstrapped as admin idempotently.
  • New route group. 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.

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

[Admin] Foundation: access control gating + admin-action audit log

2 participants