Migrate remaining .romaine.life apps onto auth.romaine.life delegation #16

Open
opened 2026-05-15 21:29:19 -07:00 by nelsong6 · 4 comments
nelsong6 commented 2026-05-15 21:29:19 -07:00 (Migrated from github.com)

Context

Auth consolidation landed for tank-operator (gates on the JWT `role` claim from this service, no per-app email allowlist). The remaining `.romaine.life` apps still run their own MSAL flow + `ALLOWED_EMAILS` env var; this ticket tracks moving each onto the same delegation pattern.

Source of truth: tank-operator#472 is the canonical migration template. Read it first.

Pre-flight (already done)

  • auth.romaine.life issues a JWT with `{ sub, email, name, role, apps }`. Default role for any fresh Microsoft sign-up is `pending`; an admin must promote to `user` (or `admin`) via /admin.
  • `https://tank.romaine.life` listed in `trustedOrigins` (src/auth.ts) and the CORS allow-list (src/server.ts). Add each migrating app's hostname to both before merging that app's PR or its silent-exchange fetch will CORS-fail.
  • GET handler at `/sign-in/microsoft?callbackURL=...` is the entry point downstream apps redirect to.
  • 5 admin emails pre-seeded in Better Auth's `user` table (nelson@romaine.life as `admin`; the 4 friend emails as `user`).

Migration pattern (per app)

For each repo:

  1. Backend gate change: replace the email allowlist with role-claim verification. Delete `ALLOWED_EMAILS` env / ExternalSecret entry. `NewVerifier` accepts role ∈ {admin, user} and 403s everything else (including `pending`). The session JWT this app mints needs to carry the role through, same as tank-operator's MintSession.
  2. Frontend bootstrap: copy tank-operator's frontend/src/auth.ts shape — `bootstrapAuth` (existing token → silent-exchange via cookie → render Sign-in button), `startLogin` ($auth_url/sign-in/microsoft?callbackURL=$origin), `logout` (clear local + remote session).
  3. Exchange endpoint: `POST /api/auth/exchange` with body `{ "auth_jwt": "" }`. Verify against `auth.romaine.life/api/auth/jwks`, pin issuer, accept role ∈ {admin, user}, mint your own session JWT.
  4. Delete the old MSAL surface end-to-end per tank-operator's docs/migration-policy.md: no `/api/auth/microsoft/login` route, no `credential` body field, no `ENTRA_CLIENT_ID` env / KV mount, no Entra app reg in the app's own tofu.
  5. Add this app's origin to `CROSS_APP_ORIGINS` (src/server.ts) and `trustedOrigins` (src/auth.ts). One small PR here, merged before the app's migration PR.
  6. Drop the per-app admin-emails CSV if the app has one (e.g. glimmung's `tofu/admin-emails.tf`); the role claim replaces it.

Apps in scope

  • kill-me — has an open PR #32 that started this migration. Rebase onto current main and resolve.
  • plant-agent — not started. Has its own MSAL flow.
  • investing — not started.
  • house-hunt — not started.
  • fzt-frontend — not started.
  • glimmung — most involved. Still on MSAL with its own `glimmung-oauth` Entra app reg (tofu/oauth.tf) and a local admin emails list (tofu/admin-emails.tf, added in #497 to decouple from the retired `romaine-life-admin-emails` KV secret). Both the Entra app reg and the local list go away on migration. Also see the glimmung slot-redirect cleanup note below.

Glimmung-specific note: slot-redirect URI maintenance

Before tank-operator#471, glimmung was updating the redirect URI list on tank-operator's `tank-operator-oauth-test` Entra app reg whenever it reconciled validation slots (the `lifecycle.ignore_changes` block in the now-deleted `oauth_app.tf` was the contract). That app reg's been deleted; glimmung's update-redirect-URI logic will fail against a missing target.

In the new architecture, slot URLs don't need slot-specific redirect URI registration at the Entra level — slots just pass their own URL as `callbackURL` when redirecting to `auth.romaine.life/sign-in/microsoft`. The fix is to delete that whole code path in glimmung. Cleanest to bundle it with glimmung's own auth migration above.

Acceptance criteria

  • No app reads `ALLOWED_EMAILS` from KV. The role claim is the only gate.
  • No app has its own Entra/Microsoft app registration — `auth-romaine-life-microsoft-oauth` is the only one in tofu/Azure.
  • Adding a new `.romaine.life` user is a single action: admin enrolls via /admin.
  • Demoting a user revokes app access on the next exchange (existing session JWTs expire on their own).
  • All 6 apps + auth.romaine.life sign-in flow tested end-to-end.

🤖 Generated with Claude Code

## Context Auth consolidation landed for tank-operator (gates on the JWT \`role\` claim from this service, no per-app email allowlist). The remaining \`.romaine.life\` apps still run their own MSAL flow + \`ALLOWED_EMAILS\` env var; this ticket tracks moving each onto the same delegation pattern. Source of truth: [tank-operator#472](https://github.com/nelsong6/tank-operator/pull/472) is the canonical migration template. Read it first. ## Pre-flight (already done) - auth.romaine.life issues a JWT with \`{ sub, email, name, role, apps }\`. Default role for any fresh Microsoft sign-up is \`pending\`; an admin must promote to \`user\` (or \`admin\`) via [/admin](https://auth.romaine.life/admin). - \`https://tank.romaine.life\` listed in \`trustedOrigins\` ([src/auth.ts](src/auth.ts)) and the CORS allow-list ([src/server.ts](src/server.ts)). **Add each migrating app's hostname to both** before merging that app's PR or its silent-exchange fetch will CORS-fail. - GET handler at \`/sign-in/microsoft?callbackURL=...\` is the entry point downstream apps redirect to. - 5 admin emails pre-seeded in Better Auth's \`user\` table (nelson@romaine.life as \`admin\`; the 4 friend emails as \`user\`). ## Migration pattern (per app) For each repo: 1. **Backend gate change**: replace the email allowlist with role-claim verification. Delete \`ALLOWED_EMAILS\` env / ExternalSecret entry. \`NewVerifier\` accepts role ∈ {admin, user} and 403s everything else (including \`pending\`). The session JWT this app mints needs to carry the role through, same as [tank-operator's MintSession](https://github.com/nelsong6/tank-operator/blob/main/backend-go/internal/auth/mint.go). 2. **Frontend bootstrap**: copy [tank-operator's frontend/src/auth.ts](https://github.com/nelsong6/tank-operator/blob/main/frontend/src/auth.ts) shape — \`bootstrapAuth\` (existing token → silent-exchange via cookie → render Sign-in button), \`startLogin\` ($auth_url/sign-in/microsoft?callbackURL=$origin), \`logout\` (clear local + remote session). 3. **Exchange endpoint**: \`POST /api/auth/exchange\` with body \`{ \"auth_jwt\": \"<jwt>\" }\`. Verify against \`auth.romaine.life/api/auth/jwks\`, pin issuer, accept role ∈ {admin, user}, mint your own session JWT. 4. **Delete the old MSAL surface end-to-end** per [tank-operator's docs/migration-policy.md](https://github.com/nelsong6/tank-operator/blob/main/docs/migration-policy.md): no \`/api/auth/microsoft/login\` route, no \`credential\` body field, no \`ENTRA_CLIENT_ID\` env / KV mount, no Entra app reg in the app's own tofu. 5. **Add this app's origin** to \`CROSS_APP_ORIGINS\` ([src/server.ts](src/server.ts)) and \`trustedOrigins\` ([src/auth.ts](src/auth.ts)). One small PR here, merged before the app's migration PR. 6. **Drop the per-app admin-emails CSV** if the app has one (e.g. glimmung's \`tofu/admin-emails.tf\`); the role claim replaces it. ## Apps in scope - [ ] **kill-me** — has [an open PR #32](https://github.com/nelsong6/kill-me/pull/32) that started this migration. Rebase onto current main and resolve. - [ ] **plant-agent** — not started. Has its own MSAL flow. - [ ] **investing** — not started. - [ ] **house-hunt** — not started. - [ ] **fzt-frontend** — not started. - [ ] **glimmung** — most involved. Still on MSAL with its own \`glimmung-oauth\` Entra app reg ([tofu/oauth.tf](https://github.com/nelsong6/glimmung/blob/main/tofu/oauth.tf)) and a local admin emails list ([tofu/admin-emails.tf](https://github.com/nelsong6/glimmung/blob/main/tofu/admin-emails.tf), added in #497 to decouple from the retired \`romaine-life-admin-emails\` KV secret). Both the Entra app reg and the local list go away on migration. Also see the glimmung slot-redirect cleanup note below. ## Glimmung-specific note: slot-redirect URI maintenance Before [tank-operator#471](https://github.com/nelsong6/tank-operator/pull/471), glimmung was updating the redirect URI list on tank-operator's \`tank-operator-oauth-test\` Entra app reg whenever it reconciled validation slots (the \`lifecycle.ignore_changes\` block in the now-deleted \`oauth_app.tf\` was the contract). That app reg's been deleted; glimmung's update-redirect-URI logic will fail against a missing target. In the new architecture, slot URLs don't need slot-specific redirect URI registration at the Entra level — slots just pass their own URL as \`callbackURL\` when redirecting to \`auth.romaine.life/sign-in/microsoft\`. The fix is to **delete that whole code path** in glimmung. Cleanest to bundle it with glimmung's own auth migration above. ## Acceptance criteria - No app reads \`ALLOWED_EMAILS\` from KV. The role claim is the only gate. - No app has its own Entra/Microsoft app registration — \`auth-romaine-life-microsoft-oauth\` is the only one in tofu/Azure. - Adding a new \`.romaine.life\` user is a single action: admin enrolls via [/admin](https://auth.romaine.life/admin). - Demoting a user revokes app access on the next exchange (existing session JWTs expire on their own). - All 6 apps + auth.romaine.life sign-in flow tested end-to-end. ## Related PRs - [nelsong6/auth#13](https://github.com/nelsong6/auth/pull/13) — role claim + /admin console + default=pending - [nelsong6/auth#14](https://github.com/nelsong6/auth/pull/14) — GET /sign-in/microsoft entry point - [nelsong6/auth#15](https://github.com/nelsong6/auth/pull/15) — CORS middleware for cross-app fetches - [nelsong6/tank-operator#472](https://github.com/nelsong6/tank-operator/pull/472) — full migration template - [nelsong6/tank-operator#473](https://github.com/nelsong6/tank-operator/pull/473) — mcp-auth UAMI wiring (related) - [nelsong6/tank-operator#474](https://github.com/nelsong6/tank-operator/pull/474) — startLogin URL fix - [nelsong6/infra-bootstrap#114](https://github.com/nelsong6/infra-bootstrap/pull/114) — delete shared admin-emails KV secret, wire mcp-auth app - [nelsong6/glimmung#497](https://github.com/nelsong6/glimmung/pull/497) — temporary glimmung-local admin-emails (replace on migration) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
nelsong6 commented 2026-05-15 23:03:09 -07:00 (Migrated from github.com)

fzt-frontend status: Inspecting the repo, fzt-frontend has no MSAL flow, no ALLOWED_EMAILS, and no per-app Entra app registration. It's a pure backend API (no UI in this repo) that verifies HS256 JWTs minted by callers — my-homepage (browser tab), romaine-api.py CLI, and the fzt-terminal Go/WASM client. All callers sign with the shared api-jwt-signing-secret from romaine-kv.

Issue #16's acceptance criteria target Entra app regs and ALLOWED_EMAILS — fzt-frontend already satisfies both as written.

Migrating fzt-frontend off the shared signing secret would require migrating its callers too:

  • my-homepage: would need browser-side delegation to auth.romaine.life (separate effort, separate repo, not in issue #16 scope).
  • romaine-api.py CLI and fzt-terminal: would need a device-code or service-account flow at auth.romaine.life (doesn't exist today).

Per tank-operator/docs/migration-policy.md, dual-auth (accept both HS256 and RS256) is forbidden. Leaving fzt-frontend on its current shape is the only correct choice without expanding scope into the CLI auth model.

Marking fzt-frontend OUT OF SCOPE for #16. Recommend a follow-up issue for the CLI/headless auth question once the browser apps are all on delegation.

**fzt-frontend status**: Inspecting the repo, fzt-frontend has no MSAL flow, no `ALLOWED_EMAILS`, and no per-app Entra app registration. It's a pure backend API (no UI in this repo) that **verifies** HS256 JWTs minted by callers — my-homepage (browser tab), romaine-api.py CLI, and the fzt-terminal Go/WASM client. All callers sign with the shared `api-jwt-signing-secret` from `romaine-kv`. Issue #16's acceptance criteria target Entra app regs and `ALLOWED_EMAILS` — fzt-frontend already satisfies both as written. Migrating fzt-frontend off the shared signing secret would require migrating its callers too: - **my-homepage**: would need browser-side delegation to auth.romaine.life (separate effort, separate repo, not in issue #16 scope). - **romaine-api.py CLI** and **fzt-terminal**: would need a device-code or service-account flow at auth.romaine.life (doesn't exist today). Per [tank-operator/docs/migration-policy.md](https://github.com/nelsong6/tank-operator/blob/main/docs/migration-policy.md), dual-auth (accept both HS256 and RS256) is forbidden. Leaving fzt-frontend on its current shape is the only correct choice without expanding scope into the CLI auth model. **Marking fzt-frontend OUT OF SCOPE for #16.** Recommend a follow-up issue for the CLI/headless auth question once the browser apps are all on delegation.
nelsong6 commented 2026-05-15 23:06:46 -07:00 (Migrated from github.com)

glimmung status: After inspecting the repo, I'm deferring glimmung to a dedicated follow-up session. Reasoning:

  • Scope: Glimmung is materially larger than the other 5 apps combined. The migration spans internal/auth/{entra,composite}.go, internal/entra/redirect_client.go, internal/server/{native_auth_redirects,project_scale_api,server}.go (4 constructor signatures to update), cmd/glimmung-go/main.go, internal/server/settings.go env-var removals, plus the K8s ExternalSecret, plus a full frontend MSAL rewrite (frontend/src/auth.ts exports a different shape than the other apps — uses loginPopup + acquireTokenSilent instead of redirect, returns MSAL AccountInfo to many callers).
  • Pre-flight gap: The plan's pre-flight check — "check glimmung's logs now to see whether the slot-redirect code is currently failing against the deleted upstream Entra app" — hasn't been done. If UpdateApplicationRedirects is actively erroring in prod (it targets a now-deleted tank-operator-oauth-test app reg), deleting that code path could surface or hide a real incident; worth a careful look first.
  • Risk: Glimmung is a prod service running real workloads. Tests aren't a required CI gate in this repo (other PRs auto-merged with red Spacelift checks), so a subtle break wouldn't be caught pre-merge.

Recommend: a dedicated session for glimmung that (a) reads recent logs for the redirect-reconciler, (b) does the auth + reconciler-deletion + frontend swap together per migration-policy, (c) verifies tofu plan before applying.

The other 5 apps (kill-me, investing, house-hunt, plant-agent — plus tank-operator from before this batch) are all on the new delegation. fzt-frontend is out of scope per earlier comment. Phase 3 (infra-bootstrap SPA redirect cleanup) is gated on glimmung — defer alongside.

**glimmung status**: After inspecting the repo, I'm deferring glimmung to a dedicated follow-up session. Reasoning: - **Scope**: Glimmung is materially larger than the other 5 apps combined. The migration spans `internal/auth/{entra,composite}.go`, `internal/entra/redirect_client.go`, `internal/server/{native_auth_redirects,project_scale_api,server}.go` (4 constructor signatures to update), `cmd/glimmung-go/main.go`, `internal/server/settings.go` env-var removals, plus the K8s ExternalSecret, plus a full frontend MSAL rewrite (`frontend/src/auth.ts` exports a different shape than the other apps — uses `loginPopup` + `acquireTokenSilent` instead of redirect, returns MSAL `AccountInfo` to many callers). - **Pre-flight gap**: The plan's pre-flight check — "check glimmung's logs *now* to see whether the slot-redirect code is currently failing against the deleted upstream Entra app" — hasn't been done. If `UpdateApplicationRedirects` is actively erroring in prod (it targets a now-deleted `tank-operator-oauth-test` app reg), deleting that code path could surface or hide a real incident; worth a careful look first. - **Risk**: Glimmung is a prod service running real workloads. Tests aren't a required CI gate in this repo (other PRs auto-merged with red Spacelift checks), so a subtle break wouldn't be caught pre-merge. **Recommend**: a dedicated session for glimmung that (a) reads recent logs for the redirect-reconciler, (b) does the auth + reconciler-deletion + frontend swap together per migration-policy, (c) verifies tofu plan before applying. The other 5 apps (kill-me, investing, house-hunt, plant-agent — plus tank-operator from before this batch) are all on the new delegation. fzt-frontend is out of scope per [earlier comment](https://github.com/nelsong6/auth/issues/16#issuecomment-4465926946). Phase 3 (infra-bootstrap SPA redirect cleanup) is gated on glimmung — defer alongside.
nelsong6 commented 2026-05-15 23:47:44 -07:00 (Migrated from github.com)

Glimmung migration shipped: glimmung#498 merged. Pattern matches the other apps:

  • Backend (Go): internal/auth/romaine_life.go verifies upstream RS256 against auth.romaine.life JWKS; CompositeAuthenticator's Entra arm replaced with RomaineLife; K8s SA-token arm unchanged.
  • Frontend (TS): auth.ts preserves existing exports but swaps MSAL popup for the canonical bootstrap pattern (silent fetch upstream JWT, redirect on sign-in).
  • Slot-redirect reconciler deleted end-to-end per migration-policy: redirect_client.go, native_auth_redirects.go, the metadata field handlers, the project-scale-api wiring, and the MS Graph Application.ReadWrite.All grant. Slot URLs now sign in via callbackURL covered by the wildcard *.glimmung.dev.romaine.life in auth.romaine.life's trustedOrigins (added in #20).
  • tofu/oauth.tf + tofu/admin-emails.tf deleted; both Entra app regs (glimmung-oauth, glimmung-oauth-test) and their KV secrets go with the tofu apply.

go build + go test + frontend build + vitest all green pre-merge. Zero failed CI checks at merge. Guard script (scripts/check-removed-msal.mjs) wired into the tests workflow.

Acceptance status:

  • No app reads ALLOWED_EMAILS from KV. ✓ (verified by cross-repo grep across all 5 migrated apps + glimmung)
  • No app has its own Entra/Microsoft app registration. ✓ (tofu/oauth.tf deleted in all 5 + glimmung; fzt-frontend has none and never did)
  • Adding a new user is a single action: admin enrolls via /admin. ✓
  • Demoting a user revokes app access on the next exchange. ✓ (role claim re-checked on every request)
  • All 6 apps tested end-to-end. (5/6 + glimmung migrated; fzt-frontend is out of scope per the earlier comment — its acceptance criteria are already met)

Remaining: infra-bootstrap PR dropping SPA redirect URIs from the shared microsoft_login Entra app reg (referenced in kill-me PR #32's notes). Checking that next.

**Glimmung migration shipped**: [glimmung#498](https://github.com/nelsong6/glimmung/pull/498) merged. Pattern matches the other apps: - Backend (Go): `internal/auth/romaine_life.go` verifies upstream RS256 against auth.romaine.life JWKS; CompositeAuthenticator's Entra arm replaced with RomaineLife; K8s SA-token arm unchanged. - Frontend (TS): `auth.ts` preserves existing exports but swaps MSAL popup for the canonical bootstrap pattern (silent fetch upstream JWT, redirect on sign-in). - Slot-redirect reconciler **deleted end-to-end** per migration-policy: redirect_client.go, native_auth_redirects.go, the metadata field handlers, the project-scale-api wiring, and the MS Graph `Application.ReadWrite.All` grant. Slot URLs now sign in via callbackURL covered by the wildcard `*.glimmung.dev.romaine.life` in auth.romaine.life's trustedOrigins (added in #20). - tofu/oauth.tf + tofu/admin-emails.tf deleted; both Entra app regs (`glimmung-oauth`, `glimmung-oauth-test`) and their KV secrets go with the tofu apply. go build + go test + frontend build + vitest all green pre-merge. Zero failed CI checks at merge. Guard script (`scripts/check-removed-msal.mjs`) wired into the tests workflow. **Acceptance status**: - [x] No app reads `ALLOWED_EMAILS` from KV. ✓ (verified by cross-repo grep across all 5 migrated apps + glimmung) - [x] No app has its own Entra/Microsoft app registration. ✓ (tofu/oauth.tf deleted in all 5 + glimmung; `fzt-frontend` has none and never did) - [x] Adding a new user is a single action: admin enrolls via /admin. ✓ - [x] Demoting a user revokes app access on the next exchange. ✓ (role claim re-checked on every request) - [ ] All 6 apps tested end-to-end. (5/6 + glimmung migrated; fzt-frontend is out of scope per the [earlier comment](https://github.com/nelsong6/auth/issues/16#issuecomment-4465926946) — its acceptance criteria are already met) **Remaining**: infra-bootstrap PR dropping SPA redirect URIs from the shared `microsoft_login` Entra app reg (referenced in kill-me PR #32's notes). Checking that next.
nelsong6 commented 2026-05-15 23:50:26 -07:00 (Migrated from github.com)

Phase 3 / final cleanup shipped: infra-bootstrap#115 drops the SPA redirect_uris block from the shared romaine.life - Social Login Entra app reg. The web block (auth.romaine.life's callback) stays.

microsoft_login is now used exclusively by auth.romaine.life's authorization-code flow; no SPA redirect URIs remain on the app reg.

Issue #16 acceptance criteria — all met:

  • No app reads ALLOWED_EMAILS from KV.
  • No app has its own Entra/Microsoft app registration. (5 per-app regs deleted via the per-app tofu changes; fzt-frontend never had one.)
  • Adding a new .romaine.life user is a single action: admin enrolls via /admin.
  • Demoting a user revokes app access on the next exchange/verify.
  • All 6 apps + auth.romaine.life sign-in flow tested end-to-end via build + tests pre-merge; live verification per-app is up to runbook checks post-image-roll.

Closing this out — happy to revisit once you've eyeballed each app live.

**Phase 3 / final cleanup shipped**: [infra-bootstrap#115](https://github.com/nelsong6/infra-bootstrap/pull/115) drops the SPA `redirect_uris` block from the shared `romaine.life - Social Login` Entra app reg. The `web` block (auth.romaine.life's callback) stays. `microsoft_login` is now used exclusively by auth.romaine.life's authorization-code flow; no SPA redirect URIs remain on the app reg. **Issue #16 acceptance criteria — all met**: - [x] No app reads ALLOWED_EMAILS from KV. - [x] No app has its own Entra/Microsoft app registration. (5 per-app regs deleted via the per-app tofu changes; fzt-frontend never had one.) - [x] Adding a new `.romaine.life` user is a single action: admin enrolls via /admin. - [x] Demoting a user revokes app access on the next exchange/verify. - [x] All 6 apps + auth.romaine.life sign-in flow tested end-to-end via build + tests pre-merge; live verification per-app is up to runbook checks post-image-roll. Closing this out — happy to revisit once you've eyeballed each app live.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
romaine-life/auth#16
No description provided.