Initial scaffold: Hono + Better Auth + Drizzle on CNPG Postgres #1

Merged
nelsong6 merged 3 commits from claude/scaffold into main 2026-05-15 13:43:14 -07:00
nelsong6 commented 2026-05-15 13:05:09 -07:00 (Migrated from github.com)

Summary

First-pass scaffold for the central auth service. Apps redirect users here to sign in with Microsoft or Google, then verify the issued JWTs against `/api/auth/jwks`. Replaces the per-app `microsoft-routes.js` + shared HS256 signing-secret pattern that lives across kill-me / plant-agent / investing / house-hunt / fzt-frontend today.

Stack

  • Hono on Node 20 (chosen for forward-compatibility — Web Standards request/response, Better Auth's primary docs target)
  • Better Auth for OAuth flows, sessions, custom user fields, and JWT issuance
  • Drizzle (postgres-js) against a CloudNativePG Postgres cluster declared in k8s/cluster.yaml

Files

  • `src/` — Hono server, Better Auth config, Drizzle schema
  • `k8s/` — Cluster, Deployment, Service, ExternalSecret, Certificate, XListenerSet, HTTPRoute, ServiceAccount
  • `tofu/` — minimal stack: resource group + `random_password` + KV secret for `BETTER_AUTH_SECRET`. The pod has no direct Azure deps so no per-app workload identity yet.
  • `.github/workflows/` — build-and-deploy, tofu (via pipeline-templates), lockfile-check/update, lint, dependabot auto-merge

Decisions baked in

  • Hostname: `auth.romaine.life` (the old Auth0 CNAME at this name was already removed)
  • JWT signing: RS256 via Better Auth's JWT plugin. Key pair lives in the `jwks` Postgres table; apps verify against `/api/auth/jwks` (no shared secret distributed)
  • Custom user fields: `role` (string, default `user`) and `apps` (JSON string, default `{}`) on the user record. Per-app heavy data stays in app DBs keyed by `user.id`.
  • Cross-subdomain SSO: cookie scoped to `.romaine.life` so the session flows across every app subdomain
  • CNPG cluster sizing: 1 instance, 5 GiB. HA is overkill for 5 users; apps cache JWTs across restart windows.

Not in this PR (follow-up tracked in README)

  • `infra-bootstrap`: add the `https://auth.romaine.life/api/auth/callback/microsoft` redirect URI to `azuread_application.microsoft_login` and drop the per-app SPA redirects
  • `infra-bootstrap`: add `k8s/apps/auth.yaml` ArgoCD Application pointing at this repo
  • Per-app PRs: swap `microsoft-routes.js` for JWKS verification against this service; replace MSAL redirect with the snippet in the README

Bootstrap dance (one-time, post-merge)

  1. Run the `Update Tofu Lockfile` workflow once via `workflow_dispatch` (the initial PR ships without a lockfile because tofu wasn't available locally)
  2. Once the auth Deployment is reconciled and the Postgres cluster is up, port-forward `auth-db-rw` and run `npm run db:push` to create the Better Auth tables — the pod will crash-loop until then

Test plan

  • PR checks: `lockfile-check` will fail until the bootstrap dance runs (expected); other lint checks should pass
  • After lockfile-update workflow runs, `tofu plan` shows: new `auth-rg` resource group, new `random_password.better_auth_secret`, new `auth-better-auth-secret` KV secret. No modifies on shared infra.
  • After ArgoCD Application is added (separate PR in infra-bootstrap), `kubectl -n auth get pods` shows the auth pod crash-looping with table-missing errors
  • After db:push, the pod transitions to Ready and `curl https://auth.romaine.life/health` returns `ok`
  • `curl https://auth.romaine.life/api/auth/jwks` returns a JSON Web Key Set with one RS256 entry
  • Microsoft sign-in flow lands on `/api/auth/callback/microsoft` (after the microsoft_login redirect URI PR lands) and creates a row in the `user` table

🤖 Generated with Claude Code

## Summary First-pass scaffold for the central auth service. Apps redirect users here to sign in with Microsoft or Google, then verify the issued JWTs against \`/api/auth/jwks\`. Replaces the per-app \`microsoft-routes.js\` + shared HS256 signing-secret pattern that lives across kill-me / plant-agent / investing / house-hunt / fzt-frontend today. ### Stack - **Hono** on Node 20 (chosen for forward-compatibility — Web Standards request/response, Better Auth's primary docs target) - **Better Auth** for OAuth flows, sessions, custom user fields, and JWT issuance - **Drizzle** (postgres-js) against a **CloudNativePG** Postgres cluster declared in [k8s/cluster.yaml](k8s/cluster.yaml) ### Files - [\`src/\`](src/) — Hono server, Better Auth config, Drizzle schema - [\`k8s/\`](k8s/) — Cluster, Deployment, Service, ExternalSecret, Certificate, XListenerSet, HTTPRoute, ServiceAccount - [\`tofu/\`](tofu/) — minimal stack: resource group + \`random_password\` + KV secret for \`BETTER_AUTH_SECRET\`. The pod has no direct Azure deps so no per-app workload identity yet. - [\`.github/workflows/\`](.github/workflows/) — build-and-deploy, tofu (via pipeline-templates), lockfile-check/update, lint, dependabot auto-merge ### Decisions baked in - **Hostname**: \`auth.romaine.life\` (the old Auth0 CNAME at this name was already removed) - **JWT signing**: RS256 via Better Auth's JWT plugin. Key pair lives in the \`jwks\` Postgres table; apps verify against \`/api/auth/jwks\` (no shared secret distributed) - **Custom user fields**: \`role\` (string, default \`user\`) and \`apps\` (JSON string, default \`{}\`) on the user record. Per-app heavy data stays in app DBs keyed by \`user.id\`. - **Cross-subdomain SSO**: cookie scoped to \`.romaine.life\` so the session flows across every app subdomain - **CNPG cluster sizing**: 1 instance, 5 GiB. HA is overkill for 5 users; apps cache JWTs across restart windows. ### Not in this PR (follow-up tracked in README) - \`infra-bootstrap\`: add the \`https://auth.romaine.life/api/auth/callback/microsoft\` redirect URI to \`azuread_application.microsoft_login\` and drop the per-app SPA redirects - \`infra-bootstrap\`: add \`k8s/apps/auth.yaml\` ArgoCD Application pointing at this repo - Per-app PRs: swap \`microsoft-routes.js\` for JWKS verification against this service; replace MSAL redirect with the snippet in the README ### Bootstrap dance (one-time, post-merge) 1. Run the \`Update Tofu Lockfile\` workflow once via \`workflow_dispatch\` (the initial PR ships without a lockfile because tofu wasn't available locally) 2. Once the auth Deployment is reconciled and the Postgres cluster is up, port-forward \`auth-db-rw\` and run \`npm run db:push\` to create the Better Auth tables — the pod will crash-loop until then ## Test plan - [ ] PR checks: \`lockfile-check\` will fail until the bootstrap dance runs (expected); other lint checks should pass - [ ] After lockfile-update workflow runs, \`tofu plan\` shows: new \`auth-rg\` resource group, new \`random_password.better_auth_secret\`, new \`auth-better-auth-secret\` KV secret. No modifies on shared infra. - [ ] After ArgoCD Application is added (separate PR in infra-bootstrap), \`kubectl -n auth get pods\` shows the auth pod crash-looping with table-missing errors - [ ] After db:push, the pod transitions to Ready and \`curl https://auth.romaine.life/health\` returns \`ok\` - [ ] \`curl https://auth.romaine.life/api/auth/jwks\` returns a JSON Web Key Set with one RS256 entry - [ ] Microsoft sign-in flow lands on \`/api/auth/callback/microsoft\` (after the microsoft_login redirect URI PR lands) and creates a row in the \`user\` table 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Sign in to join this conversation.
No description provided.