Files
ZitPlane/notes/P05-OIDC-07.md
T

27 KiB

P05-OIDC-07 — Production HTTPS, Issuer/Ingress & Secrets/Recovery Deployment Contract Forensic Design

Date: 2026-11-23 (Asia/Dhaka) Approved Gitea main baseline: 620b165e9d3f2c26ad967db54e540387a076292b, independently verified before this note. Existing accepted CI: Gitea Run #99 / Job #214, completed/success on immutable tested source 7d6b6d0704b9e39bcb6e74257dadf0b64a19fc0f; source-built imported Login V2 image, actual running image identity, four healthy disposable services, real Chromium PKCE/state/nonce/Auth.js callback/session/Account negatives/logout and BOTH run-owned cleanup systems PASS. Phase: Documentation-only read-only production deployment security/operational contract audit; absolutely no new runtime acceptance.

Exact pre-document-change Scope Lock

This scope note must be committed before any other P05-OIDC-07 documentation modifications.

WRITE ONLY: notes/**, relevant project/**, relevant docs/** and their associated README/MINIFEST entries (root README only if needed for accurate navigation). No other changed paths; no first-party product features, CI tooling or deployment code modifications.

STRICT READ-ONLY: auth/** including imported upstream Login source/Dockerfile, users/** including Auth.js and UI, core/**, deployment/** including both Compose files, tests/**, .gitea/workflows/**, every package manifest/lock, runner configuration and access, live VPS/DNS/Coolify/Cloudflare/TLS and other production infrastructure, production secrets/tokens/keys, unrelated files; preserve untracked root AI_INSTRUCTIONS.md unchanged. No source/config edit, CI dispatch/rerun, local build/test/dev server, actual real-user login, DNS/TLS/infrastructure edit, production deploy, registry push, tags or releases. No production state may be inferred from public DNS/docs or current CI.

Design goals, read-only evidence approach

  1. Audit Gitea HEAD/tree, accepted Run #99 and relevant existing immutable source (not mutate). Distinguish IMPLEMENTED, VERIFIED, UNVERIFIED, BLOCKED, PROPOSED per supported artifact.
  2. Treat auth.vib.tools and account.vib.tools as proposed domains only; do not verify or access live DNS, external endpoints or infrastructure under this phase. Define canonical external HTTPS issuer, ZITADEL API, Login V2 and Console routes, Account OIDC client/callback/logout registration, trust boundaries, secure cookies, OAuth safety.
  3. Define supported TLS termination/certificate renewal, safe forwarding and Host header validation, HTTP/2/h2c upstream, no public DB/Go/plaintext admin ports and ingress rate limits/monitoring/HA contracts. Record the development-only HTTP localhost configuration and limitations without deploying it.
  4. Audit imported image source-vs-release gap, Auth.js host trust/session protection, token rotation/federated logout, Console/IAM_OWNER break-glass and Login V2 safe cutover requirements.
  5. Define minimum secure ZITADEL master key, Login Client PAT and OIDC confidential client secrets/bootstrap ownership/rotations, SMTP and recovery, production IAM least privilege, encrypted Postgres backups including key identity escrow and restore acceptance, upgrades/rollback and monitoring/incident response.
  6. Audit CI image/provenance/reproducibility vs immutable digest/SBOM/signature/advisory refresh supply-chain contract, and separate internal disposable integration from actual production security acceptance.
  7. Produce a prioritized, smallest CI-only production-config dry-run implementation Scope Lock for separately approved P05-OIDC-08 (or other evidence-based narrow next phase), including exact proposed write/read-only file list, repeatable checks, failure/cleanup/secret-redaction rules and one authorized CI gate. No such implementation in P05-OIDC-07.
  8. Synchronize evidence in notes/**, project/**, docs/**, README/MINIFEST/source inventory as relevant. Perform one focused final Markdown/manifest/exact diff/security audit, documentation-only commit/push and remote Gitea main SHA verification. Never claim tests were run or production was verified.

Initial evidence and deliberate exclusions

  • Verified main baseline 620b165e9d3f2c26ad967db54e540387a076292b had 771 Git-tracked blobs; accepted Run #99 job #214 recorded 5/5 SUCCESS and mandatory cleanup PASS. CI tested source 7d6b6d0704b9e39bcb6e74257dadf0b64a19fc0f is distinct from this phase's later documentation SHAs.
  • Prior P05-OIDC-05 and P05-OIDC-06-A01 notes document dev-only localhost HTTP/backend Compose, imported image actual disposable OIDC acceptance and outstanding production/TLS/secret/MFA/multi-app gates.
  • This phase cannot show that real production DNS, certificates, auth/account subdomains, Coolify/VPS, SMTP, issuer tenants or secrets exist; do not make such claims. Do not read live production credentials or touch any connected hosting service in this scope.

Completed source & contract forensic audit — read-only evidence

Audit date: 2026-11-23. Pre-other-docs Scope Lock commit: d5561fa37c6dd5acbda0cbbe74f357fbc490d08d. Accepted source-tested CI: Run #99 / Job #214 completed/success, 7d6b6d0704b9e39bcb6e74257dadf0b64a19fc0f; all five steps success, disposable imported custom Login V2 real OIDC/negative/logout and both owned cleanup PASS. This phase did not dispatch/rerun CI, test a host, or access external production infrastructure. Repository baseline has 771 tracked files; the two new first-party docs (this note + operator guide) will increase this to 773.

Evidence classification — no category substitution

Capability / trust boundary Status Immutable evidence / missing gate
Custom imported Login V2 source and temporary image runtime VERIFIED CI Run #99 actual image ID matched running Login container; Chromium password, PKCE/state/nonce/Auth.js callback, protected Account pages/API, negative/logout and both cleanup PASS
Original official prebuilt Login V2 path VERIFIED CI Distinct original prebuilt Run #96 successful; Run #98 was a historical custom image entrypoint failure subsequently resolved by A01; do not overwrite either history
ZITADEL/Traefik/Postgres dev network, h2c and isolated issuer IMPLEMENTED + VERIFIED in CI only deployment/docker/compose.backend.dev.yaml, tests/ci/compose.portless.override.yaml, Run #99, HTTP localhost:8080, four services healthy
Public DNS for auth.vib.tools and account.vib.tools PROPOSED / UNVERIFIED Target names only; no live DNS query, network TLS inspection, Coolify/VPS/Cloudflare read or deployment
Canonical production HTTPS issuer, valid certificates and proxy BLOCKED No production ingress/certificate/issuer config tracked; dev Compose ZITADEL_EXTERNALDOMAIN=localhost, EXTERNALSECURE=false, TLS_ENABLED=false, Host:localhost, published host loopback 8080:80
Account Auth.js OIDC protocol/session IMPLEMENTED + VERIFIED in disposable CI users/ui/src/{auth.ts,lib/env.ts,lib/identity.ts}, next.config.ts and Run #99; PKCE/state/nonce, 1h JWT, subject+expiry rejection, HTTPS-origin rule in production
Actual production callback allowlist, cookies, trusted proxy UNVERIFIED / BLOCKED AUTH_URL, ZITADEL_ISSUER source validators exist; no public HTTPS callback registration, Secure/SameSite/Domain response or spoofed forwarded-Host negative acceptance
Console/admin human auth and Login V2 cutover/rollback UNVERIFIED / BLOCKED Dev Compose enables instance-wide Login V2; only Account login was browser-tested. No Console login, emergency access, per-app staged rollout, production rollback tested
Login/Account credentials and identity recovery IMPLEMENTED dev-only; production BLOCKED core/backend/zitadel/dev.py generates ignored local .env; dev first-admin, Login PAT/bootstrap volume, DB password. No protected production KMS/secret manager/rotation audit
MFA/passkey, recovery, global logout, multi-app SSO UNVERIFIED Imported upstream pages exist; no real factor enroll/recover/WebAuthn RP-domain/Console human, second OIDC client or federated logout CI
Production database durability, encrypted offsite backup/restore BLOCKED Dev named Postgres volume and disposable CI synthetic persistence prove no managed recovery. No production RPO/RTO/restore drill/master-key escrow verified
Production image release, signing/advisory refresh/observability BLOCKED Existing images are tags, imported custom CI image zitplane-login-ci:99 was local ephemeral and CLEANED. No release provenance/SBOM/signature/registry/rollback/TLS monitoring accepted

Proposed production-domain and routing contract — DESIGN ONLY

Canonical issuer: https://auth.vib.tools (origin, no nonstandard port or path). Discovery https://auth.vib.tools/.well-known/openid-configuration must advertise the same immutable issuer and HTTPS endpoints; the real ZITADEL instance and every relying party must agree on it. This is not a live verified URL.

Public route / audience Proposed ingress Private target / security contract
https://auth.vib.tools/ui/v2/login/** TLS 443, exactly one trusted public Host Imported source-built Login service on private 3000, preserve basePath and official Login V2 callback flows
https://auth.vib.tools/ui/console/** Same origin, not a second ID provider Official ZITADEL Go API/Console on internal 8080 h2c (HTTP/2) with gRPC-Web; verify actual Console login before cutover
https://auth.vib.tools/.well-known/**, /oauth/**, /oidc/**, /v2/**, /management/**, other official API/console paths One issuer, no split-brain public host ZITADEL Go on private h2c; default all paths except Login prefix to API, not a blind copy of the dev-only /api strip alias
https://account.vib.tools/** Independent TLS 443 vhost; not a second issuer Private Account Next.js/standalone server, Auth.js callback handled on Account host
https://account.vib.tools/api/auth/callback/zitadel Exact registered OIDC Web client redirect Confidential ZITADEL Web client, code+PKCE S256/state/nonce, reject wildcard/HTTP/arbitrary subdomain/redirect and untrusted forwarded origins
https://account.vib.tools/signin, /account/**, /api/account/me Account private app, authenticated page/API Same-origin HttpOnly cookies, fail-closed subject and token expiry, authenticated API private/no-store; verify actual Secure/SameSite settings and cross-subdomain redirects
Unencrypted port 80 Optional redirect-only HTTP→HTTPS, preferably no app/API response No bearer tokens, Login or callbacks over HTTP; HSTS staged after all relevant HTTPS subdomains actually confirmed
TCP 8080/3000/5432 and container/admin/metrics ports Not publicly published (including IPv6) Private network, DB firewall ACL; health/metrics least-privilege internal; route by name to stable containers only

TLS/transport: Terminate TLS at one fully controlled ingress with renewals/alerts, valid certificate chains, modern TLS minimum/ciphers and HTTPS-only redirect, or deliberately approved end-to-end TLS mode. The ZITADEL official deployment guide distinguishes external TLS mode (proxy TLS → internal plain h2c) from enabled end-to-end TLS; configure ZITADEL_EXTERNALSECURE/external domain/port and TLS-mode semantics consistently with the chosen ZITADEL v4 image, rather than reusing development false. Verify HTTP/2 to clients where required, h2c for ZITADEL gRPC, Console gRPC-Web, health/discovery/API. Do not infer that a generic HTTP/1.1 Cloudflare/Nginx/Traefik chain suffices. Reference: https://zitadel.com/docs/self-hosting/manage/reverseproxy/reverse_proxy .

Header/host/redirect trust boundary: At edge reject unknown SNI/Host, malformed/duplicate Host, untrusted Forwarded/X-Forwarded-Host/X-Forwarded-Proto/X-Forwarded-For; overwrite these from edge-verified authority, do not append user-supplied values. Restrict proxy trust to known ingress hops. Set canonical HTTPS Host and scheme consistently for Login V2 and ZITADEL. Account AUTH_TRUST_HOST=true only once ingress strips/overwrites upstream-spoofable headers, since Auth.js then trusts the forwarded origin. In auth/ui/v2/apps/login/src/lib/server/service-url.ts, constructUrl uses publicHost and request protocol; imported src/proxy.ts conditionally rewrites /.well-known/, /oauth/, /oidc/, /idps/callback/, /saml/, /assets/ and emits wildcard Access-Control-Allow-Origin: * on those proxy responses. This is SOURCE PRESENT, not a proven vulnerability; assess CORS/preflight and credentialed responses independently, avoid exposing a broad API proxy route or weakening CORS during ingress design. Dev CUSTOM_REQUEST_HEADERS=Host:localhost,X-Forwarded-Proto:http is not valid production host policy.

CSP/HSTS/cookie boundary: Imported Login next.config.mjs declares HSTS max-age=63072000; includeSubDomains; preload; do not opt into preload or broad subdomain enforcement until all relevant subdomains are confirmed HTTPS and renewal/recovery procedures exist. It also contains a server-action origin allowlist configurable through SERVER_ACTION_ALLOWED_ORIGINS; require exact known origins and test unexpected Origin and CSRF requests, no *. Account users/ui/next.config.ts sets nosniff, framing, Referrer/Permissions policies but not full production CSP/HSTS; the final edge policy must not conflict with Login's dynamic CSP and actual OAuth/Console assets. Prove response cookies (HttpOnly, Secure, bounded SameSite, Path and host-only scope); do not speculate that arbitrary cross-subdomain sharing is required. Use different secrets for different session issuers. Account AUTH_SECRET >=32 characters, stable across replicas; dedicated Login ZITADEL_SESSION_COOKIE_SECRET >=32 with supported phased rotation (new first, old temporarily accepted) and separate API credential. No leak of auth code, token, secret, cookie or redirect query to public logs.

OIDC client contract: One specific confidential Account client ID/secret bound to actual HTTPS issuer; register exact https://account.vib.tools/api/auth/callback/zitadel and only validated app-appropriate post-logout/redirect URI(s). No wildcard, HTTP, generic dynamic redirects or application cross-tenant audience mixing. Validate iss, aud, sub, PKCE, state, nonce and callback under true TLS; preserve existing Auth.js fail-closed expiration and Account API/no-store. Portal account-shell.tsx::portalLogout is local signOut only, not ZITADEL logout or global multi-app session revocation. Token refresh/server revocation and federated logout require a separate approved security implementation, not ingress rewrites.

Login V2, Admin Console, MFA and cutover safety

The current dev Compose uses instance-wide ZITADEL_DEFAULTINSTANCE_FEATURES_LOGINV2_REQUIRED=true, which applies to all applications including the Console. A production cutover to imported Login UI must first verify private container/issuer routing, public /ui/v2/login health, API login-client authentication and an explicit interactive Console sign-in with least-privileged admin; preserve alternate break-glass IAM_OWNER machine account+PAT stored securely outside normal Login containers. The ZITADEL guide recommends per-application gradual enablement for existing installations and explains that instance-wide enablement overrides app settings. Rollback must be pretested without destroying DB/session/keys, with feature-state and image reversions preserving the canonical issuer and non-compromised secrets. IdP/SAML callbacks, trusted domains, application login base paths and organization policy require independent acceptance. Official: https://zitadel.com/docs/self-hosting/manage/adopt-login-v2 .

MFA/OTP/passkey UI routes are present in imported source, NOT authenticated-factor enrollment/recovery accepted. Passkeys/WebAuthn RP ID and registered origin depend on final domain; test enrollment, challenge replay/rejection, factor policy, lost-device recovery and Console break-glass in isolated HTTPS context under separate scope. Account /account/security currently supplies informative links only; zitadelSelfServiceUrl() uses /ui/console/users/me and does not prove role/policy access. Multi-SaaS SSO must have another independently registered client and enforce issuer+subject+audience/tenant/authorization in each app before acceptance.

Production secret/bootstrap/backup/operations contract (proposed)

Secret or privileged surface Owner and minimum invariant Rotation / backup / failure gate
ZITADEL master key Exactly 32 bytes per ZITADEL specification, cryptographic identity independent of deployment; secret manager/HSM/offline encrypted escrow, tightly restricted access Restore with same key+matching database backup; never blindly regenerate or rotate—would make encrypted data unrecoverable; prove documented key ceremony before any change
PostgreSQL application/admin credentials Separate restricted DB accounts; private socket/network and TLS between hosts, not developer sslmode=disable used across insecure links DB credential rollover tested; separate migration/init ownership; recovery operator can restore without exposing plaintext backup
Login V2 API service identity Dedicated IAM_LOGIN_CLIENT service account (PAT via protected read-only file or supported signed system-user key), not IAM_OWNER Protected issuance, scope and expiry, rotation/revocation+session impact; never grant login service emergency owner access
Break-glass identity Separately protected IAM_OWNER machine account, out-of-band escrow+audit, limited emergency access Test emergency API recovery of misconfigured instance-wide Login V2 without interactive Console; rotate after use; do not put PAT in Login env or CI logs
Login V2 session signing Independent ZITADEL_SESSION_COOKIE_SECRET, >=32 characters, same across replicas Document safe old/new-list phased rotation and session expiration; keep distinct from service credential
Account relying-party secrets ZITADEL_CLIENT_SECRET, AUTH_SECRET >=32 chars, one confidential Web client; AUTH_TRUST_HOST only trusted sanitized proxy Versioned secret injection, controlled overlap/rollout for user sessions, least-privilege client rotation and revoked stale credentials
TLS/ACME/DNS/SMTP credentials Edge/proxy and mail service only; not injected into Account/Chromium/CI tests Restricted filesystem/KMS, expiry monitoring, emergency certificate renewal, validated SMTP sender/recovery links; no production email acceptance in current repo

Provisioning: A brand-new production instance must use a secure first-admin activation flow (verified email, required credential reset, least privilege) and approved bootstrap identity policies; never reuse zitadel-admin@zitadel.localhost, auto-verified local test email, 2028-01-01 dev Login PAT expiry, user: "0" defaults or ignored dev .env on production. Review root-running ZITADEL/Login containers and the Traefik Docker socket bind /var/run/docker.sock:ro: a read-only filesystem mount does not make the Docker Engine API read-only; prefer isolated Docker socket proxy with restricted endpoints or static/file provider and non-root service containers where supported. Nothing has been changed or validated on production.

Data contract: Pin PostgreSQL major/minor and upgrade policy; durable monitored storage; encrypted authenticated offsite backups, least-privilege restore access, tested PITR/consistent snapshots where applicable, separate key escrow, explicit operator-chosen RPO/RTO and retention, routine isolated restore drills that verify ZITADEL startup, issuer, keys, login and audit continuity. Never delete existing production DB or restore over a live instance in an unattended CI check. Backups lacking the matching master key, or key custody without DB, are not adequate recovery proof. Keep infrastructure config/secret identities and migrations versioned and access controlled; rehearse rollback including DB schema compatibility before rollout.

Operations/release contract: immutable image digests for Go ZITADEL, imported source-built Login and Account; secure build provenance, current dependency/advisory scan (Run #89's zero Moderate+ result is historical), SBOM and signed artifacts verified at deploy, no latest/mutable-only tags or ephemeral CI image mistaken for release. Current original imported Dockerfile uses FROM node:24-alpine tag and docker build --pull in the accepted test; Run #99 logged a resolved base digest at that time but did not pin/ship a production artifact. Store config changes as reviewed, roll out incrementally with automatic rollback gates, health for all paths, encrypted backup before migration, process isolation, SLO/alerts for upstream readiness, TLS certificate age, database disk/replication, API/login errors, abuse/rate limits, secret expiry and login/Console failure; protect log contents and audit admin/service-token actions. Include IPv4/IPv6 firewall and WAF/rate limits without breaking OAuth redirect or legitimate MFA.

Blocker priority and decision gates

Priority Blocker / proposal Minimum independent acceptance before live rollout
P0-1 Production canonical HTTPS issuer, DNS/cert, TLS/proxy h2c/Host/callback Fail-closed config validation, real HTTPS discovery issuer equality, exact redirect/CORS/forwarded-header negative tests, HTTP/2 Console/gRPC-Web; no public backend/DB ports
P0-2 Production key/DB/identity recovery and break-glass Secret-store and 32-byte master-key escrow, protected Login API identity and emergency IAM_OWNER, encrypted backup+isolated restore exercise/rollback documented
P0-3 Immutable release artifacts and safe deployment Source→image provenance/digest, current SCA/SBOM/signature, secretless dry-run, controlled change management; no runtime dev image
P1-1 Account HTTPS cookies/session and authorized callbacks Real Secure/HttpOnly/SameSite/Host-only cookie, Auth.js callback under TLS, policy-negative redirect/CSRF and expiry, refresh/federated logout separately scoped
P1-2 Admin Console and Login V2 cutover Interactive Console login and verified break-glass rollback with isolated database/tenant, no instance-wide feature switch before proof
P1-3 Factor/passkey/SMTP and second SaaS SSO Verified WebAuthn origin/RP ID/enroll/recover; SMTP deliverability; at least 2 independent OIDC app clients and tenant isolation
P2 HA/monitoring/scaling/response Operator-set RPO/RTO, metrics, HTTPS certificate and backup alerts, load/rollback and incident drill

Production verdict: BLOCKED / NOT VERIFIED. This is a repository evidence finding, not evidence that a particular external DNS/VPS/Coolify deployment exists or does not exist. The only new result in this phase is a documentation security contract (not a build, test, CI or rollout). External official documentation reviewed for design assumptions only: https://zitadel.com/docs/self-hosting/manage/productionchecklist , https://zitadel.com/docs/self-hosting/manage/reverseproxy/reverse_proxy , https://zitadel.com/docs/self-hosting/manage/adopt-login-v2 , https://zitadel.com/docs/self-hosting/manage/login-client , https://zitadel.com/docs/concepts/architecture/secrets , https://authjs.dev/getting-started/deployment .

Proposed separately approved P05-OIDC-08 — CI-Only Production Configuration Contract Dry-Run

Purpose: Encode the above design as synthetic / non-deployable CI-only configuration contracts, enforce fail-closed static validation, and prove that representative malformed TLS/issuer/routes/host/headers/secret references/public port configurations are rejected without talking to public DNS, production hosts or user services. This is NOT production deployment or actual external HTTPS acceptance.

Exact candidate SOURCE WRITE (only if newly approved):

  1. notes/P05-OIDC-08.md first, with Scope Lock and approved baseline.
  2. New deployment/production-contract/{README.md,MINIFEST.md,compose.ci.yaml,routing-policy.json}: CI-only structurally realistic Compose topology plus declarative strict edge routes/issuer/secret requirements; clearly mark NOT FOR DEPLOYMENT. No real secret values, live domains queried or public ports; use static proposed FQDN labels and synthetic secret references; no automatic external DNS/TLS.
  3. New tests/ci/production_contract/{README.md,MINIFEST.md,validate.py}: stdlib-only structural checks, synthetic positive and deliberately malformed negative fixtures generated in-memory; verify no published backend/DB ports, approved exact issuer/callback/Login path, ZITADEL h2c route, Host/forwarded sanitization contract, required env/secrets referenced-not-embedded, and fail on wildcard/HTTP/unknown hosts and privileged Docker socket.
  4. New .gitea/workflows/p05-production-contract-dry-run.yml: manual-only, one disposable runner job, read-only checkout, docker compose config --quiet / JSON structural validation (NO up, build, pull, login, deploy, DNS lookup), then positive+negative synthetic static tests, no real credentials; no registry upload. Approve dispatch exactly once after focused diff/security audit.
  5. Documentation only in notes/**, relevant project/**, docs/**, required associated deployment/README.md, .gitea/workflows/{README.md,MINIFEST.md}, tests/ci/{README.md,MINIFEST.md}, project/source inventory, root README if relevant. No other paths.

STRICT READ-ONLY candidate: Existing deployment/docker/** (both prior Compose files), auth/**, users/**, core/**, preexisting tests/** and .gitea/workflows/** outside the exact new files/associated documentation, all manifests/locks, runner settings, DNS/Coolify/VPS/live TLS, production secret managers, credentials and unrelated paths. Preserve untracked AI_INSTRUCTIONS.md.

Gate: One static/permission/security patch audit, source Git commit/push, one separately approved manual CI dispatch; log exact PASS/FAIL/NOT EXECUTED including reject-negative fixtures, cleanup verification (no created containers/resources), source SHA, documentation closure and remote HEAD. No production account/bootstrap, secret creation, actual TLS, public DNS, image build, Docker containers, registry push, local tests, human data, deployment, tag or release. Failure -> stop, report and request a new narrow phase; no scope creep/rerun.

Future phases after this dry-run, separately approved: production image provenance/release, secure secrets/backup/restore, external HTTPS ingress and genuine real-domain acceptance, Console/MFA/multi-app SSO. No deployment authorization is implied by P05-OIDC-08.