Repository navigation
Adopt the stored Support role for staff access (phases 1-3) - #46
Conversation
Implements docs/ROLE_ADOPTION_PLAN.md phases 1-3: - Phase 1: one unified PolicyDocumentV1 (pegma.dev-policy-1) — customer permissions via defaults, staff permissions via the Support role — schema-validated in tests; createRoleStore(store, 'pegma.dev') bound at the worker composition root over the shared D1 store. - Phase 2: the staff gate resolves stored role assignments per request, uncached; the env allowlist is honored beside the role path (and as fallthrough on role-store failure) until Phase 4 deletes it whole. - Phase 3: PEGMA_SUPPORT_BOOTSTRAP_PRINCIPALS seeds a real audited Support assignment (actor system:bootstrap) once per principal, ever — deterministic assignment id keeps a deliberate revocation durable while the env var lingers. Admin role deliberately not mapped yet; it arrives with the Phase 5 management surface. 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.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d43ea7bfa1
ℹ️ 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".
There was a problem hiding this comment.
Pull request overview
Implements phases 1–3 of docs/ROLE_ADOPTION_PLAN.md by introducing a unified authorization policy, binding a D1-backed role store to the worker runtime, and adopting stored Support role assignments for staff authorization (with a one-time bootstrap seeding mechanism).
Changes:
- Add a unified
PolicyDocumentV1(pegma.dev-policy-1) and resolve both customer/staff access through it, with staff gated by the storedSupportrole (plus legacy allowlist fallback). - Bind
createRoleStore(store, 'pegma.dev')into the support runtime and thread the role store through the support API. - Add Phase 3 bootstrap seeding (
PEGMA_SUPPORT_BOOTSTRAP_PRINCIPALS) and expand test coverage for role gating, fallback behavior, and seeding semantics.
Reviewed changes
Copilot reviewed 9 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| worker/src/support-desk.ts | Binds the audited role store into the support runtime composition. |
| worker/src/support-api.ts | Switches staff authorization to prefer role-store resolution with allowlist fallback; triggers bootstrap seeding on authenticated touches. |
| worker/src/support-api.test.ts | Adds tests for policy schema validation, role-based staff access, fallback matrix, and bootstrap seeding durability. |
| worker/src/support-access.ts | Introduces unified policy + role-based staff access resolution (staffAccessContextFromRoles). |
| worker/src/role-bootstrap.ts | Adds one-time bootstrap seeding utilities and env parsing for bootstrap principals. |
| worker/src/index.ts | Wires role store + bootstrap principal parsing into the support handler. |
| package.json | Adds exact pinned dependencies for authorization policy/schema validation and role storage. |
| package-lock.json | Locks the newly added Pegma authorization packages. |
| docs/SUPPORT_COMPOSITION.md | Updates composition docs to reflect stored-role staff access, bootstrap seeding, and legacy allowlist deprecation path. |
| docs/ROLE_ADOPTION_PLAN.md | Marks phases 1–3 as completed. |
Comments suppressed due to low confidence (2)
worker/src/support-desk.ts:35
- RoleStore is aliased to InMemoryStorageAdapter, which is a confusing dependency type name for a D1-backed role store and couples the host surface to a specific exported type. Prefer deriving the type from createRoleStore’s return type so the host stays aligned if the library changes its exported adapter type names.
/** The audited role store surface createRoleStore returns. */
export type RoleStore = InMemoryStorageAdapter;
worker/src/role-bootstrap.ts:33
- BootstrapRoleStore is currently derived from the dependency type name InMemoryStorageAdapter. To avoid coupling to that specific exported name (and the misleading "InMemory" label), derive the surface from createRoleStore’s return type so it stays aligned with the actual role-store contract.
/** The role-store surface the bootstrap needs. */
export type BootstrapRoleStore = Pick<
InMemoryStorageAdapter,
'getRoleAssignment' | 'listActiveRoleAssignments' | 'grantRoleAssignmentWithAudit'
>;
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
…f, derived store types - Bootstrap "already seeded" now lives in a host marker collection (support-bootstrap.markers.v1) written whenever the seed converges — including when Support is already held through another assignment, where the role store refuses a second active tuple and previously left no trace, so revoking that assignment while the env var lingered would have re-granted on the next touch (Codex P1). Grant-before-marker order keeps a crash between the two self-healing. - The legacy allowlist gate now requires the same queue-read permission proof as the role path; allowlisting alone never outranks the policy. - RoleStore / BootstrapRoleStore derive from createRoleStore's return type instead of naming the library's InMemoryStorageAdapter. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Implements docs/ROLE_ADOPTION_PLAN.md phases 1–3 (plan merged in #45). Phase 4 — deleting the allowlist — is deliberately a separate follow-up PR, gated on the live bootstrap seed demonstrably granting
Support(lockout-safe order).Phase 1 — policy + role store binding
PolicyDocumentV1(pegma.dev-policy-1): customer support permissions granted viadefaultsto any authenticated account (unchanged semantics), staff permissions via the storedSupportrole. Schema-validated in tests with@pegma/authorization-policyso drift fails CI.createRoleStore(store, 'pegma.dev')bound at the worker composition root, over the same D1-backedStorethe other components share.@pegma/authorization-storage@0.2.0,@pegma/authorization-policy@0.2.0.Admindeliberately NOT mapped — it arrives with the Phase 5 management surface; a role nothing checks is a loaded gun.Phase 2 — staff gate reads roles
staffAccessContextFromRolesresolves stored active assignments per request, uncached — honors the library's 60-second staff-check bound; a revocation is effective on the next request.support.staff_role_check_failedand falls through to the allowlist (legacy stays authoritative until Phase 4 deletes it whole).Phase 3 — first-operator seed
PEGMA_SUPPORT_BOOTSTRAP_PRINCIPALS: a listed principal's next authenticated support touch writes a REAL auditedSupportassignment (actorsystem:bootstrap), once per principal, ever.bootstrap-support-<principalId>: the record — active OR revoked — is the durable "already seeded" marker, so a deliberate revocation stays revoked even while the env var lingers.support.bootstrap_support_failed).Tests
tsc --noEmitclean.Operational follow-through (after merge + deploy)
PEGMA_SUPPORT_BOOTSTRAP_PRINCIPALSto the operator's Identity principal id on the Worker.🤖 Generated with Claude Code