diff --git a/security/token-vault/README.md b/security/token-vault/README.md
index 3ed17d4..2a5f6b5 100644
--- a/security/token-vault/README.md
+++ b/security/token-vault/README.md
@@ -42,6 +42,8 @@ For an approved reveal grant:
- D1 database created from schema.sql.
- D1 binding named DB.
- Worker secrets: BOOTSTRAP_PASSWORD_HASH, SESSION_SIGNING_KEY, TOKEN_ENCRYPTION_KEY.
+- Worker variable: ACCESS_REQUIRED=true before staging/production exposure.
+- Cloudflare Access Self-hosted application for the Worker hostname, with Allow policies restricted to approved staff identity emails or groups. Do not add a public bypass policy.
Generate a new unique password locally with the hidden-input utility in scripts/hash-password.mjs. Store only its output as BOOTSTRAP_PASSWORD_HASH. Generate independent random 32-byte signing and encryption keys; store them as Worker secrets. The password previously supplied in chat is exposed and must never be used.
@@ -57,7 +59,7 @@ The encryption key is expected as Base64 or Base64URL encoding of exactly 32 ran
| ai_agent | Project-scoped | Project-granted reveal only | No |
| auditor | Yes | No | No |
-The bootstrap TOKEN identity is currently the only human login. Individual staff SSO/identity provisioning is not implemented in this milestone. AI Agent credentials are independent, project-scoped machine identities; do not share the bootstrap password with agents or staff.
+Staff use Cloudflare Access SSO. An owner provisions each staff email and assigns security_admin, developer, or auditor; the email from ctx.access.getIdentity() must match an active D1 identity. Set ACCESS_REQUIRED=true on the Worker before exposure. This also blocks direct workers.dev access for browser/human routes; the independent bearer-key agent API remains protected by its own project-scoped credentials. The TOKEN password remains the bootstrap owner login and is never shared with staff or agents.
## API
@@ -68,6 +70,9 @@ The bootstrap TOKEN identity is currently the only human login. Individual staff
- POST /api/tokens — encrypt and store a project-scoped credential.
- POST /api/tokens/:id/reveal — privileged human reveal with audit event.
- DELETE /api/tokens/:id — privileged deletion with audit event.
+- GET /api/members, POST /api/members — owner-only personnel inventory and Access email provisioning.
+- PATCH /api/members/:email — update staff role.
+- DELETE /api/members/:email — disable staff identity and revoke sessions.
- GET /api/agents, POST /api/agents — owner-only agent inventory and one-time key issuance.
- GET/POST /api/agents/:subject/grants — owner-only project grants.
- DELETE /api/agents/:subject — revoke an agent.
@@ -80,3 +85,7 @@ Run node security/token-vault/scripts/check-source.mjs for source validation and
Schema validation is executed against an in-memory SQLite database in CI before the Worker integration suite.
+
+Cloudflare Workers exposes authenticated Access identity through ctx.access; the Worker uses the verified email claim and then checks the matching active D1 identity before assigning application permissions. See the official Cloudflare Workers Access integration guide: https://developers.cloudflare.com/workers/configuration/cloudflare-access/.
+
+Staff Access identity is checked against the active D1 identity record on every authenticated request.
diff --git a/security/token-vault/scripts/check-source.mjs b/security/token-vault/scripts/check-source.mjs
index 468b5b8..54c4b1d 100644
--- a/security/token-vault/scripts/check-source.mjs
+++ b/security/token-vault/scripts/check-source.mjs
@@ -28,6 +28,9 @@ for (const marker of [
"agent_project_grants",
"agent.token.reveal",
"validProject(projectId)",
+ "ctx.access.getIdentity",
+ "ACCESS_REQUIRED",
+ "/api/members",
'"cache-control": "no-store, max-age=0"'
]) assert.ok(worker.includes(marker), "Missing security invariant: " + marker);
assert.ok(!worker.includes("!origin ||"), "Missing Origin must not be accepted");
diff --git a/security/token-vault/src/worker.js b/security/token-vault/src/worker.js
index 5d1a849..14053d2 100644
--- a/security/token-vault/src/worker.js
+++ b/security/token-vault/src/worker.js
@@ -76,13 +76,21 @@ async function audit(env, actor, action, resource, outcome = "success") {
await env.DB.prepare("INSERT INTO audit_events(id,actor,action,resource_id,outcome) VALUES(?,?,?,?,?)")
.bind(crypto.randomUUID(), actor, action, resource || null, outcome).run();
}
-async function currentUser(req, env) {
+async function currentUser(req, env, ctx) {
const id = await verify(cookieValue(req), env.SESSION_SIGNING_KEY);
- if (!id) return null;
- const row = await env.DB.prepare("SELECT s.subject,i.role,s.expires_at,i.active FROM sessions s JOIN identities i ON i.subject=s.subject WHERE s.id_hash=? AND s.revoked=0")
- .bind(await hash(id)).first();
- if (!row || !row.active || row.expires_at <= Math.floor(Date.now() / 1000)) return null;
- return { subject: row.subject, role: row.role };
+ if (id) {
+ const row = await env.DB.prepare("SELECT s.subject,i.role,s.expires_at,i.active FROM sessions s JOIN identities i ON i.subject=s.subject WHERE s.id_hash=? AND s.revoked=0")
+ .bind(await hash(id)).first();
+ if (row && row.active && row.expires_at > Math.floor(Date.now() / 1000)) return { subject: row.subject, role: row.role, auth: "session" };
+ }
+ if (ctx?.access && typeof ctx.access.getIdentity === "function") {
+ const identity = await ctx.access.getIdentity();
+ const email = typeof identity?.email === "string" ? identity.email.trim().toLowerCase() : "";
+ if (!email || email.length > 254) return null;
+ const member = await env.DB.prepare("SELECT subject,role,active FROM identities WHERE subject=?").bind(email).first();
+ if (member?.active) return { subject: member.subject, role: member.role, auth: "cloudflare-access" };
+ }
+ return null;
}
async function key(env) {
return crypto.subtle.importKey("raw", unb64(env.TOKEN_ENCRYPTION_KEY), "AES-GCM", false, ["encrypt", "decrypt"]);
@@ -121,7 +129,7 @@ function validProject(value) {
return typeof value === "string" && /^[a-z0-9][a-z0-9._-]{1,63}$/.test(value);
}
const LOGIN_HTML = '