Skip to content

fix(k8s): use the env names the app actually reads - #46

Merged
MikkoNumminen merged 1 commit into
mainfrom
fix/k8s-env-names
Jul 24, 2026
Merged

fix(k8s): use the env names the app actually reads#46
MikkoNumminen merged 1 commit into
mainfrom
fix/k8s-env-names

Conversation

@MikkoNumminen

Copy link
Copy Markdown
Owner

The last thread from the #45 review: I kept NEXTAUTH_SECRET in the TOTP fallback chain "because the k8s templates still set it" — and then checked what else those templates set. They predate the NextAuth v5 migration entirely, and since both deployment paths inject env verbatim (envFrom), a fresh k8s deploy from them is broken in five distinct ways:

template provides app reads consequence
NEXTAUTH_SECRET AUTH_SECRET sign-in throws MissingSecret@auth/core/lib/utils/env.js reads only AUTH_SECRET, no legacy fallback
GOOGLE_CLIENT_*, GITHUB_CLIENT_* AUTH_GOOGLE_*, AUTH_GITHUB_* (v5 inference for bare provider imports, src/auth.ts:78) OAuth providers get no credentials
MONGODB_URI MONGODB_URL (src/mongoDb.ts:28) audit trail silently no-ops — the same failure mode just fixed on Vercel
AUDIT_HMAC_SECRET fails closed in production once Mongo is wired
TOTP_ENCRYPTION_KEY 2FA worked only via the legacy fallback #45 preserved

Plus AUTH_TRUST_HOST was never set — auth.ts doesn't set trustHost, so v5 behind the ingress rejects proxied Host headers with UntrustedHost (docker-compose already sets it; k8s didn't).

Changes

  • k8s/manifests/secret.yaml + Helm values.yaml secrets.data: renamed to the consumed names; added AUDIT_HMAC_SECRET, TOTP_ENCRYPTION_KEY; CRON_SECRET included as an optional commented entry (there's no CronJob manifest — whether to add one or use an external scheduler is a separate decision)
  • k8s/manifests/configmap.yaml + Helm values.yaml config: NEXTAUTH_URLAUTH_URL (the URL, unlike the secret, does have a legacy fallback — renamed for consistency), added AUTH_TRUST_HOST: "true", dropped MONGO_DB_NAME (read by nothing)
  • k8s/README.md: both documented example blocks updated to match

Verification

  • All three YAML files parse; the key sets in the raw manifests and the Helm values are identical
  • grep over k8s/ finds zero remaining stale names outside explanatory comments
  • Helm chart not rendered (helm CLI not on this machine) — the templates themselves are untouched; only values.yaml data changed, and the envFrom/stringData range loops are name-agnostic
  • Full suite through the pre-push hook: 2835 green (no app code touched; the suite run is the hook's blanket gate)

Note the deliberate asymmetry with #45: the app keeps honoring NEXTAUTH_SECRET for TOTP decryption so existing deployments don't lose 2FA secrets, while the templates stop recommending it for new deployments.

🤖 Generated with Claude Code

The manifests and Helm chart predate the NextAuth v5 migration and inject
env verbatim (envFrom), so a deploy from these templates got:

- broken sign-in: they set NEXTAUTH_SECRET, but @auth/core reads only
  AUTH_SECRET (verified in @auth/core/lib/utils/env.js — no legacy fallback);
  v5 in production throws MissingSecret
- dead OAuth credentials: GOOGLE_CLIENT_* / GITHUB_CLIENT_* instead of the
  AUTH_GOOGLE_* / AUTH_GITHUB_* names v5 infers for bare provider imports
- a silently disabled audit trail: MONGODB_URI, while the app reads
  MONGODB_URL (isMongoAvailable() false -> deferAudit no-ops)
- no AUDIT_HMAC_SECRET or TOTP_ENCRYPTION_KEY, both of which fail closed in
  production
- UntrustedHost behind the ingress: nothing set AUTH_TRUST_HOST and auth.ts
  does not set trustHost

Rename every key to what src/ actually consumes, add the two fail-closed
secrets, AUTH_TRUST_HOST, and an optional commented CRON_SECRET; drop the
unread MONGO_DB_NAME; NEXTAUTH_URL becomes AUTH_URL (the legacy name still
works for the URL, unlike the secret — kept consistent anyway). k8s/README
examples updated to match. YAML validated by parse; key sets in the raw
manifests and the Helm values are identical.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@vercel

vercel Bot commented Jul 24, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
hr-manager Ready Ready Preview, Comment Jul 24, 2026 5:32am

@MikkoNumminen
MikkoNumminen merged commit 15dfcb2 into main Jul 24, 2026
4 checks passed
MikkoNumminen added a commit that referenced this pull request Jul 24, 2026
Merging #46 — pure k8s manifests and Helm chart — triggered a full Vercel
production rebuild of identical app code, because k8s/ was in scope for the
ignore command. Kubernetes is a different deployment target entirely; nothing
under k8s/ can affect what Vercel builds.

Verified against real history: the #46 merge diff now skips, the #45 (app
code) diff still builds.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

Mutation Testing

Score: 70.73% (break threshold 60% — ✅ pass). 319 detected / 451 valid mutants (killed 194, timeout 125, survived 31, no-coverage 101). Full report.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant