You do not have staff access
- This surface is only available to allowlisted operators. If you expected
- access, contact an administrator.
+ This surface is only available to operators holding the Support role. If
+ you expected access, contact an administrator.
Account
diff --git a/src/pages/staff/support/ticket.astro b/src/pages/staff/support/ticket.astro
index 1bd2b87..2393311 100644
--- a/src/pages/staff/support/ticket.astro
+++ b/src/pages/staff/support/ticket.astro
@@ -4,7 +4,7 @@ import Base from '../../../layouts/Base.astro';
Staff · Ticket
@@ -30,7 +30,7 @@ import Base from '../../../layouts/Base.astro';
You do not have staff access
- This surface is only available to allowlisted operators.
+ This surface is only available to operators holding the Support role.
Account
diff --git a/worker/src/index.ts b/worker/src/index.ts
index 2d8b6a0..da75924 100644
--- a/worker/src/index.ts
+++ b/worker/src/index.ts
@@ -25,7 +25,6 @@ import {
import { handleGetReleases, readReleasesConfig } from './releases-api';
import { parseBootstrapPrincipals } from './role-bootstrap';
import { createSupportApi } from './support-api';
-import { parseStaffAllowlist } from './support-access';
import {
createProductionSupportRuntime,
probeSupportStore,
@@ -59,12 +58,10 @@ function createSupportHandler(env: AppEnv, logger: ReturnType;
-/** Parsed host allowlists for Support Desk staff operators. */
-export interface StaffAllowlist {
- /** Lowercased verified emails. */
- readonly emails: ReadonlySet;
- /** Identity principal / subject ids. */
- readonly principals: ReadonlySet;
-}
-
-const EMPTY_STAFF_ALLOWLIST: StaffAllowlist = Object.freeze({
- emails: Object.freeze(new Set()),
- principals: Object.freeze(new Set()),
-});
-
-function parseCommaList(value: string | undefined): string[] {
- if (value === undefined || value.trim() === '') {
- return [];
- }
- return value
- .split(',')
- .map((part) => part.trim())
- .filter((part) => part.length > 0);
-}
-
-/**
- * Parse `SUPPORT_STAFF_EMAILS` and `SUPPORT_STAFF_PRINCIPALS` from host env.
- *
- * Emails are lowercased for case-insensitive comparison. Principal ids are
- * kept as-is (trimmed). Empty or missing env → empty allowlist (no staff).
- */
-export function parseStaffAllowlist(env: {
- readonly SUPPORT_STAFF_EMAILS?: string;
- readonly SUPPORT_STAFF_PRINCIPALS?: string;
-}): StaffAllowlist {
- const emails = new Set(
- parseCommaList(env.SUPPORT_STAFF_EMAILS).map((email) =>
- email.toLowerCase(),
- ),
- );
- const principals = new Set(parseCommaList(env.SUPPORT_STAFF_PRINCIPALS));
- return Object.freeze({
- emails: Object.freeze(emails),
- principals: Object.freeze(principals),
- });
-}
-
-/** Empty allowlist for hosts/tests that inject staff later. */
-export function emptyStaffAllowlist(): StaffAllowlist {
- return EMPTY_STAFF_ALLOWLIST;
-}
-
/**
* Resolve an AccessContext for an authenticated Identity principal.
*
@@ -160,36 +110,3 @@ export async function staffAccessContextFromRoles(
: null;
}
-/**
- * LEGACY staff AccessContext from the host env allowlist — honored beside
- * the role path during the lockout-safe retirement order
- * (docs/ROLE_ADOPTION_PLAN.md Phases 2–4), then deleted whole.
- *
- * A principal is staff only when authenticated **and** (principal id is in
- * `SUPPORT_STAFF_PRINCIPALS` **or** verified user email is in
- * `SUPPORT_STAFF_EMAILS`). Returns `null` when not staff — callers map that
- * to HTTP 403 `forbidden` (not 404).
- */
-export function staffAccessContext(
- principalId: PrincipalId,
- allowlist: StaffAllowlist,
- userEmail?: string,
-): AccessContext | null {
- const principalAllowed = allowlist.principals.has(principalId);
- const emailAllowed =
- userEmail !== undefined &&
- userEmail.trim() !== '' &&
- allowlist.emails.has(userEmail.trim().toLowerCase());
- if (!principalAllowed && !emailAllowed) {
- return null;
- }
- const context = resolveAccess(
- { principalId, roles: [SUPPORT_ROLE] },
- PEGMA_ACCESS_POLICY,
- );
- // Same permission proof as the role path: allowlisting alone never
- // outranks what the policy actually grants.
- return hasPermission(context, supportPermissions.queueRead)
- ? context
- : null;
-}
diff --git a/worker/src/support-api.test.ts b/worker/src/support-api.test.ts
index 864191e..05aff33 100644
--- a/worker/src/support-api.test.ts
+++ b/worker/src/support-api.test.ts
@@ -21,9 +21,7 @@ import { validatePolicy } from '@pegma/authorization-policy';
import {
APPLICATION_SCOPE,
customerAccessContext,
- parseStaffAllowlist,
PEGMA_ACCESS_POLICY,
- staffAccessContext,
staffAccessContextFromRoles,
SUPPORT_ROLE,
SUPPORT_STAFF_PERMISSIONS,
@@ -153,9 +151,9 @@ function patch(
}
function fixture(options: {
- readonly staffPrincipals?: readonly PrincipalId[];
- readonly staffEmails?: readonly string[];
readonly bootstrapPrincipals?: readonly PrincipalId[];
+ /** Wire the API without any role store (fail-closed 503 posture). */
+ readonly omitRoleStore?: boolean;
/** Override the role store the API sees (e.g. a failing one). */
readonly roleStoreOverride?: Parameters[0]['roleStore'];
} = {}) {
@@ -175,10 +173,6 @@ function fixture(options: {
logger,
clock,
});
- const staffAllowlist = parseStaffAllowlist({
- SUPPORT_STAFF_PRINCIPALS: (options.staffPrincipals ?? []).join(','),
- SUPPORT_STAFF_EMAILS: (options.staffEmails ?? []).join(','),
- });
const api = createSupportApi({
application: runtime.application,
sessions,
@@ -187,10 +181,11 @@ function fixture(options: {
createLimiter: runtime.createLimiter,
replyLimiter: runtime.replyLimiter,
logger,
- roleStore: options.roleStoreOverride ?? runtime.roleStore,
+ roleStore: options.omitRoleStore
+ ? undefined
+ : (options.roleStoreOverride ?? runtime.roleStore),
bootstrapMarkers: runtime.bootstrapMarkers,
bootstrapPrincipals: new Set(options.bootstrapPrincipals ?? []),
- staffAllowlist,
});
return {
store,
@@ -203,6 +198,27 @@ function fixture(options: {
};
}
+/** Grant the stored Support role the way an operator surface would. */
+async function grantSupport(
+ roleStore: ReturnType['roleStore'],
+ principalId: PrincipalId,
+ id = `assign-${principalId}`,
+) {
+ const granted = await roleStore.grantRoleAssignmentWithAudit({
+ assignment: {
+ id,
+ principalId,
+ role: SUPPORT_ROLE,
+ scope: APPLICATION_SCOPE,
+ grantedBy: { kind: 'principal', principalId: 'principal-admin' },
+ grantedAtEpochMs: Date.parse('2026-07-30T00:00:00.000Z'),
+ status: 'active',
+ },
+ auditEventId: `evt-${id}`,
+ });
+ expect(granted.status).toBe('granted');
+}
+
async function createCustomerTicket(
api: ReturnType,
sessions: ReturnType,
@@ -538,55 +554,9 @@ describe('application ownership boundary', () => {
});
});
-describe('staff allowlist and access', () => {
- it('parses env allowlists case-insensitively for emails', () => {
- const allowlist = parseStaffAllowlist({
- SUPPORT_STAFF_EMAILS: ' Ops@Example.TEST , other@example.test ',
- SUPPORT_STAFF_PRINCIPALS: ' principal-staff , principal-x ',
- });
- expect(allowlist.emails.has('ops@example.test')).toBe(true);
- expect(allowlist.emails.has('other@example.test')).toBe(true);
- expect(allowlist.principals.has('principal-staff')).toBe(true);
- expect(allowlist.principals.has('principal-x')).toBe(true);
- });
-
- it('grants staff permissions only for allowlisted principals or emails', () => {
- const byPrincipal = parseStaffAllowlist({
- SUPPORT_STAFF_PRINCIPALS: principalStaff,
- });
- const byEmail = parseStaffAllowlist({
- SUPPORT_STAFF_EMAILS: 'staff@example.test',
- });
- const empty = parseStaffAllowlist({});
-
- const staffByPrincipal = staffAccessContext(
- principalStaff,
- byPrincipal,
- 'staff@example.test',
- );
- expect(staffByPrincipal).not.toBeNull();
- expect(staffByPrincipal?.policyVersion).toBe(PEGMA_ACCESS_POLICY.version);
- expect(staffByPrincipal?.permissions).toEqual(
- expect.arrayContaining([...SUPPORT_STAFF_PERMISSIONS]),
- );
-
- const staffByEmail = staffAccessContext(
- principalA,
- byEmail,
- 'STAFF@example.test',
- );
- expect(staffByEmail).not.toBeNull();
-
- expect(staffAccessContext(principalA, empty, 'a@example.test')).toBeNull();
- expect(
- staffAccessContext(principalA, byPrincipal, 'a@example.test'),
- ).toBeNull();
- });
-});
-
describe('staff support API', () => {
it('returns 401 for unauthenticated staff routes', async () => {
- const { api } = fixture({ staffPrincipals: [principalStaff] });
+ const { api } = fixture();
const queue = await api(get('/api/support/admin/queue'));
expect(queue.status).toBe(401);
expect(await queue.json()).toEqual({ error: 'authentication_required' });
@@ -596,7 +566,8 @@ describe('staff support API', () => {
});
it('returns 403 for authenticated non-staff on queue, read, reply, and note', async () => {
- const { api, sessions } = fixture({ staffPrincipals: [principalStaff] });
+ const { api, sessions, roleStore } = fixture();
+ await grantSupport(roleStore, principalStaff);
const customer = await createCustomerTicket(api, sessions, principalA, 'a');
const nonStaff = await sessionCookie(sessions, principalB, 'b'.repeat(43));
@@ -640,8 +611,9 @@ describe('staff support API', () => {
expect(await note.json()).toEqual({ error: 'forbidden' });
});
- it('lists the queue for allowlisted staff after customer create', async () => {
- const { api, sessions } = fixture({ staffPrincipals: [principalStaff] });
+ it('lists the queue for Support role holders after customer create', async () => {
+ const { api, sessions, roleStore } = fixture();
+ await grantSupport(roleStore, principalStaff);
const customer = await createCustomerTicket(api, sessions, principalA, 'a');
const staff = await sessionCookie(
sessions,
@@ -662,7 +634,8 @@ describe('staff support API', () => {
});
it('reads staff ticket including messages and requester email', async () => {
- const { api, sessions } = fixture({ staffPrincipals: [principalStaff] });
+ const { api, sessions, roleStore } = fixture();
+ await grantSupport(roleStore, principalStaff);
const customer = await createCustomerTicket(api, sessions, principalA, 'a');
const staff = await sessionCookie(
sessions,
@@ -695,7 +668,8 @@ describe('staff support API', () => {
});
it('public staff reply is customer-visible and advances status', async () => {
- const { api, sessions } = fixture({ staffPrincipals: [principalStaff] });
+ const { api, sessions, roleStore } = fixture();
+ await grantSupport(roleStore, principalStaff);
const customer = await createCustomerTicket(api, sessions, principalA, 'a');
const staff = await sessionCookie(
sessions,
@@ -745,7 +719,8 @@ describe('staff support API', () => {
});
it('internal notes are staff-only and never on customer read', async () => {
- const { api, sessions } = fixture({ staffPrincipals: [principalStaff] });
+ const { api, sessions, roleStore } = fixture();
+ await grantSupport(roleStore, principalStaff);
const customer = await createCustomerTicket(api, sessions, principalA, 'a');
const staff = await sessionCookie(
sessions,
@@ -793,7 +768,8 @@ describe('staff support API', () => {
});
it('keeps public reply and internal note on separate endpoints', async () => {
- const { api, sessions } = fixture({ staffPrincipals: [principalStaff] });
+ const { api, sessions, roleStore } = fixture();
+ await grantSupport(roleStore, principalStaff);
const customer = await createCustomerTicket(api, sessions, principalA, 'a');
const staff = await sessionCookie(
sessions,
@@ -857,7 +833,8 @@ describe('staff support API', () => {
});
it('supports assign, priority change, and resolve for staff', async () => {
- const { api, sessions } = fixture({ staffPrincipals: [principalStaff] });
+ const { api, sessions, roleStore } = fixture();
+ await grantSupport(roleStore, principalStaff);
const customer = await createCustomerTicket(api, sessions, principalA, 'a');
const staff = await sessionCookie(
sessions,
@@ -908,42 +885,9 @@ describe('staff support API', () => {
};
expect(resolvedBody.ticket.status).toBe('resolved');
});
-
- it('allows staff by verified email allowlist', async () => {
- const { api, sessions } = fixture({
- staffEmails: ['staff@example.test'],
- });
- await createCustomerTicket(api, sessions, principalA, 'a');
- const staff = await sessionCookie(
- sessions,
- principalStaff,
- 's'.repeat(43),
- );
- const queue = await api(get('/api/support/admin/queue', staff.cookie));
- expect(queue.status).toBe(200);
- });
});
describe('Support role store adoption (docs/ROLE_ADOPTION_PLAN.md phases 1–3)', () => {
- async function grantSupport(
- roleStore: ReturnType['roleStore'],
- principalId: PrincipalId,
- id = `assign-${principalId}`,
- ) {
- const granted = await roleStore.grantRoleAssignmentWithAudit({
- assignment: {
- id,
- principalId,
- role: SUPPORT_ROLE,
- scope: APPLICATION_SCOPE,
- grantedBy: { kind: 'principal', principalId: 'principal-admin' },
- grantedAtEpochMs: Date.parse('2026-07-30T00:00:00.000Z'),
- status: 'active',
- },
- auditEventId: `evt-${id}`,
- });
- expect(granted.status).toBe('granted');
- }
it('the host policy validates as a PolicyDocumentV1 (schema drift fails CI)', () => {
const serialized = JSON.parse(JSON.stringify(PEGMA_ACCESS_POLICY));
@@ -990,7 +934,21 @@ describe('Support role store adoption (docs/ROLE_ADOPTION_PLAN.md phases 1–3)'
expect(queue.status).toBe(200);
});
- it('denies without role or allowlist; a role-store failure falls back to the legacy allowlist', async () => {
+ it('fails CLOSED: no role store is a 503, and a role-store failure is a 503 even for a role holder', async () => {
+ const unconfigured = fixture({ omitRoleStore: true });
+ const nobody = await sessionCookie(
+ unconfigured.sessions,
+ principalA,
+ 'n'.repeat(43),
+ );
+ const unconfiguredQueue = await unconfigured.api(
+ get('/api/support/admin/queue', nobody.cookie),
+ );
+ expect(unconfiguredQueue.status).toBe(503);
+ expect(await unconfiguredQueue.json()).toEqual({
+ error: 'support_not_configured',
+ });
+
const failing = {
listActiveRoleAssignments: async () => {
throw new Error('role store down');
@@ -1000,21 +958,22 @@ describe('Support role store adoption (docs/ROLE_ADOPTION_PLAN.md phases 1–3)'
throw new Error('role store down');
},
} as unknown as Parameters[0]['roleStore'];
-
- const denied = fixture({ roleStoreOverride: failing });
- const nobody = await sessionCookie(denied.sessions, principalA, 'n'.repeat(43));
- expect(
- (await denied.api(get('/api/support/admin/queue', nobody.cookie))).status,
- ).toBe(403);
-
- const legacy = fixture({
- roleStoreOverride: failing,
- staffPrincipals: [principalStaff],
+ const degraded = fixture({ roleStoreOverride: failing });
+ // The durable store holds a real Support grant, but the API reads
+ // through the failing store — outage must never quietly deny or allow.
+ await grantSupport(degraded.roleStore, principalStaff);
+ const staff = await sessionCookie(
+ degraded.sessions,
+ principalStaff,
+ 'l'.repeat(43),
+ );
+ const degradedQueue = await degraded.api(
+ get('/api/support/admin/queue', staff.cookie),
+ );
+ expect(degradedQueue.status).toBe(503);
+ expect(await degradedQueue.json()).toEqual({
+ error: 'service_unavailable',
});
- const staff = await sessionCookie(legacy.sessions, principalStaff, 'l'.repeat(43));
- expect(
- (await legacy.api(get('/api/support/admin/queue', staff.cookie))).status,
- ).toBe(200);
});
it('bootstrap seeds a listed principal on an authenticated touch, once, revocation-durable', async () => {
diff --git a/worker/src/support-api.ts b/worker/src/support-api.ts
index b49b6c8..56cd184 100644
--- a/worker/src/support-api.ts
+++ b/worker/src/support-api.ts
@@ -33,11 +33,8 @@ import {
} from './role-bootstrap';
import {
customerAccessContext,
- emptyStaffAllowlist,
- staffAccessContext,
staffAccessContextFromRoles,
type SupportRoleReader,
- type StaffAllowlist,
} from './support-access';
import {
mapSupportError,
@@ -103,15 +100,8 @@ interface SupportApiOptions {
readonly replyLimiter: DurableRateLimiter;
readonly logger: Logger;
/**
- * LEGACY host staff allowlist, honored beside the role path during the
- * lockout-safe retirement order (docs/ROLE_ADOPTION_PLAN.md) — deleted
- * whole in Phase 4. Prefer injecting from env via `parseStaffAllowlist`
- * so tests can supply a fixed list without process env.
- */
- readonly staffAllowlist?: StaffAllowlist;
- /**
- * Audited role store — the REAL staff gate (Phase 2). Absent ⇒ only the
- * legacy allowlist can grant staff access.
+ * Audited role store — the ONLY staff gate (docs/ROLE_ADOPTION_PLAN.md
+ * Phase 4). Absent ⇒ staff routes are a controlled 503, fail closed.
*/
readonly roleStore?: SupportRoleReader & BootstrapRoleStore;
/** One-time Support bootstrap principals (Phase 3). */
@@ -697,37 +687,31 @@ function parseStaffQueueQuery(url: URL): StaffQueueQuery {
async function requireStaffAccess(
authenticated: Authenticated,
- allowlist: StaffAllowlist,
options: SupportApiOptions,
) {
- // The Support ROLE is the real gate (docs/ROLE_ADOPTION_PLAN.md Phase 2);
- // the env allowlist stays honored as the legacy path until Phase 4
- // deletes it whole. A role-store failure falls through to the allowlist
- // rather than 503ing — the legacy path is authoritative until deleted.
- if (options.roleStore !== undefined) {
- try {
- const roleAccess = await staffAccessContextFromRoles(
- authenticated.link.subject,
- options.roleStore,
- );
- if (roleAccess !== null) {
- return roleAccess;
- }
- } catch (error) {
- options.logger.log('warn', 'support.staff_role_check_failed', {
- error: error instanceof Error ? error.name : 'unknown',
- });
- }
+ // The stored Support ROLE is the only gate (docs/ROLE_ADOPTION_PLAN.md
+ // Phase 4) and it FAILS CLOSED: a host wired without a role store or a
+ // role-store failure is a controlled 503, never a quiet allow or a
+ // misleading 403.
+ if (options.roleStore === undefined) {
+ throw new ApiError(503, 'support_not_configured');
}
- const access = staffAccessContext(
- authenticated.link.subject,
- allowlist,
- authenticated.user.email,
- );
- if (access === null) {
+ let roleAccess: Awaited>;
+ try {
+ roleAccess = await staffAccessContextFromRoles(
+ authenticated.link.subject,
+ options.roleStore,
+ );
+ } catch (error) {
+ options.logger.log('error', 'support.staff_role_check_failed', {
+ error: error instanceof Error ? error.name : 'unknown',
+ });
+ throw new ApiError(503, 'service_unavailable');
+ }
+ if (roleAccess === null) {
throw new ApiError(403, 'forbidden');
}
- return access;
+ return roleAccess;
}
/**
@@ -737,14 +721,12 @@ async function requireStaffAccess(
* Fetch Metadata for mutations. Principal is the Identity subject from the
* session — never taken from the request body.
*
- * Staff routes live under `/api/support/admin/…` and require host allowlist
- * membership (`SUPPORT_STAFF_EMAILS` / `SUPPORT_STAFF_PRINCIPALS`).
+ * Staff routes live under `/api/support/admin/…` and require the stored,
+ * audited `Support` role.
*/
export function createSupportApi(
options: SupportApiOptions,
): (request: Request) => Promise {
- const staffAllowlist = options.staffAllowlist ?? emptyStaffAllowlist();
-
return async (request) => {
const url = new URL(request.url);
const path = url.pathname;
@@ -792,7 +774,7 @@ export function createSupportApi(
if (request.method === 'GET' && path === '/api/support/admin/queue') {
const authenticated = await requireAuthentication(request, options);
- const access = await requireStaffAccess(authenticated, staffAllowlist, options);
+ const access = await requireStaffAccess(authenticated, options);
const queueQuery = parseStaffQueueQuery(url);
const result = await options.application.listStaffQueue(
access,
@@ -812,7 +794,7 @@ export function createSupportApi(
) {
const ticketId = adminMatch[1]!;
const authenticated = await requireAuthentication(request, options);
- const access = await requireStaffAccess(authenticated, staffAllowlist, options);
+ const access = await requireStaffAccess(authenticated, options);
const view = await options.application.readStaffTicket(
access,
ticketId,
@@ -832,7 +814,7 @@ export function createSupportApi(
const ticketId = adminMatch[1]!;
const authenticated = await requireAuthentication(request, options);
await requireCsrf(request, authenticated);
- const access = await requireStaffAccess(authenticated, staffAllowlist, options);
+ const access = await requireStaffAccess(authenticated, options);
const body = optionalKeysObject(
await readJson(request),
@@ -924,7 +906,7 @@ export function createSupportApi(
await requireCsrf(request, authenticated);
// Authorize before debiting the shared customer/staff reply limiter so
// non-staff sessions fail closed without mutating quota state.
- const access = await requireStaffAccess(authenticated, staffAllowlist, options);
+ const access = await requireStaffAccess(authenticated, options);
await enforceRateLimit(
options.replyLimiter,
authenticated.link.subject,
@@ -960,7 +942,7 @@ export function createSupportApi(
const authenticated = await requireAuthentication(request, options);
await requireCsrf(request, authenticated);
// Same order as messages: staff check before shared limiter debit.
- const access = await requireStaffAccess(authenticated, staffAllowlist, options);
+ const access = await requireStaffAccess(authenticated, options);
await enforceRateLimit(
options.replyLimiter,
authenticated.link.subject,
diff --git a/worker/src/support-desk.ts b/worker/src/support-desk.ts
index 114e72b..b1235e7 100644
--- a/worker/src/support-desk.ts
+++ b/worker/src/support-desk.ts
@@ -161,16 +161,6 @@ export interface SupportRuntimeEnv {
readonly IDENTITY_DB: D1Database;
/** When `"true"`, health includes a lightweight Support Desk store probe. */
readonly SUPPORT_HEALTH_PROBE?: string;
- /**
- * Comma-separated verified emails of Support Desk staff operators
- * (case-insensitive). Combined with {@link SUPPORT_STAFF_PRINCIPALS}.
- */
- readonly SUPPORT_STAFF_EMAILS?: string;
- /**
- * Comma-separated Identity principal / subject ids of Support Desk staff
- * operators. Combined with {@link SUPPORT_STAFF_EMAILS}.
- */
- readonly SUPPORT_STAFF_PRINCIPALS?: string;
/**
* One-time Support-role bootstrap principals
* (docs/ROLE_ADOPTION_PLAN.md Phase 3). Delete after the first operator