Stage 1: /api/auth/exchange/k8s for service-principal JWTs #32
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
queue
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
romaine-life/auth!32
Loading…
Reference in a new issue
No description provided.
Delete branch "service-token-exchange"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Stage 1 of nelsong6/tank-operator#486 — auth-side only.
Adds
POST /api/auth/exchange/k8s: session pods (today: tank-operator) POST their projected SA token and receive a normal auth.romaine.life JWT withrole=service. The JWT is shape-compatible with human JWTs (same JWKS,iss,aud) so any app that already verifies auth.romaine.life tokens can accept service callers by extending its role gate to includeservice— no JWKS/verifier surgery needed.This PR is independently coherent: the endpoint is live and verified by tests, but no in-cluster caller exists yet. Stage 2 (tank-operator role-gate widening + new session-creation handlers) and Stage 4 (atomic cutover of
requireInternalCallerSA-TokenReview path) will land cross-repo against this contract.What's in here
POST /api/auth/exchange/k8s— reuses the existingverifyK8sSAToken(refactored to accept env-driven{audience, allowlist}so the admin and service paths share one verifier). Audience pinned tohttps://auth.romaine.lifeperK8S_SERVICE_AUDIENCE;(namespace, serviceAccount)pinned perK8S_SERVICE_SA_ALLOWLIST.pod-<session-id>@service.tank.romaine.life. DNS-owned, never MX-served.RESERVED_SERVICE_EMAIL_DOMAINSinsrc/synthetic-email.tsis the registry — new consumers add one entry here and one row inNAMESPACE_TO_CONSUMER(both required by construction;buildServiceEmailrefuses unregistered consumers).databaseHooks.user.create.beforeinsrc/auth.tsrefuses any IdP-sourced user-create whose email is in a reserved domain. Defense-in-depth against a Microsoft/Google IdP returning an email that collides with our synthetic namespace. Admin consolePOST /admin/usersgets the same check.userId = svc:<consumer>:<session-id>(deterministic, prefix-namespaced so it cannot collide with a human UUID). Inserted directly via Drizzle to intentionally bypass the reserved-domain hook above — that hook exists to block humans, not the exchange that owns the namespace.auth.api.signJWT. Better Auth's/sign-jwtendpoint is exposed only programmatically (no HTTP path). Uses the same JWKS-stored keypair, sameiss, sameaud, samekidrotation behavior as the human path. Default TTL 15 min (Better Auth'sexpirationTimedefault). Extraactor_emailclaim carries the human owner.src/k8s-pod.tsdoes a single GET againstkubernetes.default.svcusing the in-cluster SA token. Trusts the cluster CA viaNODE_EXTRA_CA_CERTSso native fetch works without pulling inundici/@kubernetes/client-node.k8s/templates/rbac-service-consumers.yamlscaffolds a Role + RoleBinding grantingpods/getto (auth/auth) in each namespace listed underk8sOidc.serviceConsumerNamespaces. Scoped strictly topods get— minimum surface for the lookup, no list/watch.What's NOT in here (deferred to later stages)
nelsong6/authdoesn't currently expose Prometheus; adding a metrics surface is its own scoped lift. Until then, exchange failures surface viaconsole.errorand the structuredreasonin the response body (denied_token | denied_allowlist | denied_unbound_pod | denied_unknown_namespace | denied_annotation_missing | denied_pod_lookup_failed | error_jwt_mint | error_internal).suband per-actor_emailceilings oncreate_session); auth doesn't gate that.Test plan
npm run typecheck— cleannpm run build— cleannpm test— 42/42 passing (existing 28 + 14 new across synthetic-email, k8s-pod, service-exchange helpers)npm run check:static-slot-origins— cleanhelm template auth k8s/— renders; new env vars and cross-namespace RBAC present/api/auth/jwksand carriesrole=service+actor_email(post-merge, paired with the Stage 3 session-pod bootstrap)Migration policy
No legacy auth shape is being retired in this PR — the new endpoint is additive. The retirement of
requireInternalCaller's raw SA-TokenReview path on tank-operator's/api/internal/sessions/*is Stage 4 and lands atomically with the mcp-tank-operator switchover per #486.