Skip to content

Track A: harden OIDC SSO (PKCE, issuer-bound identity, source-scoped roles) - #511

Merged
athNdev merged 4 commits into
mainfrom
codex/auth-sso-track
Nov 18, 2026
Merged

athNdev merged 4 commits into
mainfrom
codex/auth-sso-track

Conversation

@athNdev

@athNdev athNdev commented Nov 18, 2026

Copy link
Copy Markdown
Owner

Summary

Tenant-independent Track A authentication/SSO hardening from the reviewed
plan gate (security-runtime-plans/auth-sso.md, G1–G11).
No live IdP tenant, credentials, deploy or release involved.

Protocol

  • Server-side Authorization Code + S256 PKCE, one-time nonce, and a bounded in-memory
    transaction holding state+nonce+verifier consumed with a single locked compare-and-delete
    before code exchange. Replay/concurrent callbacks are refused and never call the IdP
    token endpoint.
  • Pinned issuer (discovery + ID token), local signing-algorithm allowlist (RS256/ES256;
    HS256 only by explicit operator choice), and iss/aud/exp/signature/nonce validation.
  • Session token no longer appears in a URL. Callback issues a one-time, 60s, client-IP-bound
    exchange code redeemed via POST /api/v1/auth/oidc/exchange (Cache-Control: no-store).

Identity and entitlement

  • Sole identity key is (issuer, subject) with a new store lookup. A legacy issuer-less row
    yields link_required; no email/name auto-link, no implicit admin, no first-user admin from
    SSO. Local break-glass admin and recovery key remain the recoverable path.
  • New db.SetUserRolesBySource reconciles only source=oidc roles in one transaction and
    preserves local/admin grants. Absent groups default to revoke; no keep_previous; privileged
    raw claim names are refused without an explicit mapping; privileged provenance conflicts
    refuse sign-in and are audited. Reconciliation precedes session issue and role loss revokes
    all prior sessions.

Shared contracts and UI

  • Frozen Phase 0 hooks for Track B, owned by Track A (internal/auth/hooks.go):
    BootstrapAudit, SessionSnapshot, SessionValidator, plus the production validator.
    Exact signatures match Track B B-00; no import cycle.
  • Redacted security_audit events (issuer, subject hash, user ID, outcome, role-delta counts;
    never state/nonce/code/verifier/tokens/secrets).
  • Canonical Carbon login config/error/lockout states; the SPA consumes ?code= and maps
    ?error= codes to fixed operator-safe messages.

Verification (actual runs)

  • go test ./... -count=1 — all packages pass, including new auth/db fixtures.
  • go vet on affected packages — clean.
  • bun install --frozen-lockfile; bun run check (0 errors, 0 warnings);
    bun run test (279 pass, 0 fail).
  • Production frontend build via node ./node_modules/vite/bin/vite.js build — succeeded
    (✓ built, adapter-static wrote build). The scripts/web-build.sh bash wrapper could not
    run in this Windows harness (bash/WSL service unavailable), so its exact command was run
    directly with a 2048 MB heap cap.
  • go run ./cmd/knowledge-lint -root . -fix then without -fix — OK, 60 concepts,
    38/38 queries, indexes current. One pre-existing warning on invariants/data-safety
    (verification date older than its file change) is unrelated to this change.

Owned local OIDC discovery fixtures cover PKCE/nonce/state parameters, cookie flags,
issuer+subject identity, no auto-bind, no implicit admin, raw privileged-name denial,
source-aware role preservation, one-time exchange, and the session validator contract.
No exploit testing and no live provider calls were performed.

Evidence limits / limitations

  • Fixture evidence only. authentik and Okta interoperability with a real tenant is
    not verified; documentation-driven configuration support only.
  • Single controller process: the transaction and exchange stores are in memory (bounded TTL
    and caps). Multi-controller deployments need a shared store in a later slice.
  • IdP outage at startup still follows existing handler construction behaviour; visible
    degraded health (plan D10/P5) and best-effort IdP logout (ADR 0026) remain follow-up slices.
  • P4 session lifetime schema changes (idle/absolute fields) are not in this slice; existing
    auth.session_timeout absolute expiry remains.
  • Product PR merges are held due verified :edge/Pages auto-publication; this branch does not
    depend on them and will be rebased if needed.

Merge policy

Draft only. Independent review and CI are required. Do not merge from this lane.

- Add server-side Authorization Code + S256 PKCE, nonce, and one bounded
  transaction consumed atomically before code exchange; replay is refused.
- Pin issuer and signing algorithms; verify signature, iss, aud, exp, nonce.
- Return a one-time exchange code instead of a session token in the URL;
  add POST /api/v1/auth/oidc/exchange with IP binding and no-store.
- Resolve users by (issuer, subject); never auto-bind issuer-less legacy rows
  or grant implicit admin; keep local break-glass recovery.
- Reconcile only source=oidc roles transactionally before session issue via
  new db.SetUserRolesBySource; preserve local/admin grants, fail closed on
  privileged provenance conflicts, rotate sessions on sign-in.
- Add frozen Track B Phase 0 hooks (BootstrapAudit, SessionSnapshot,
  SessionValidator) and the production SessionValidator implementation.
- Add redacted OIDC audit events, canonical Carbon login error/lockout states,
  config defaults, ADRs 0023-0026, knowledge concept and owned fixtures.
…usal fixtures

- Make extra_claims_url enrichment fill-only with protected identity and
  role-claim keys, so it cannot overwrite verified claims or elevate roles;
  bound the response body and check Close errors.
- Fix new-code lint findings: checked deferred store.Close and QF1008 key.
- Add harmless fixtures for invalid issuer, wrong audience, wrong/missing
  nonce, expired token, signature failure, JWKS rollover and extra-claims
  injection, plus a bounded-response assertion.
- Document in ADR 0025 that ValidateSession's per-request DB role re-read is
  the security boundary after split reconciliation/session issue.
@athNdev
athNdev marked this pull request as ready for review November 18, 2026 03:31
@athNdev
athNdev merged commit 8e2c502 into main Nov 18, 2026
12 checks passed
@athNdev
athNdev deleted the codex/auth-sso-track branch November 18, 2026 03:31
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