oidc-admin red (sig 94a048d819e4): gate-oidc's enforced PKCE never satisfied by control-plane's OIDC client — files.<apex> re-gate (#566) breaks under it #643

Closed
opened 2026-08-22 01:29:19 +00:00 by matou-build-agent · 2 comments

Failure

Drive 20260822T010329Z, leg oidc-admin, red on page.waitForSelector('#header') timeout (60s), raced against a kanidm-login-field wait that also timed out (app/tests/e2e/fixtures/provision.ts:640-647) — neither Nextcloud's signed-in chrome nor kanidm's login form ever appeared after ceremony.goto(doorPath(door, '/login')) (app/tests/e2e/journey.droplet.spec.ts:576-579).

Root cause

kanidm's gate-oidc OAuth2 client — the community-SSO gate's own OIDC client (ADR 0074/#566), provisioned in internal/clan/vmguest.go:679-687 (gatewayKanidmProvision's gateOAuth2 block) — is never given allowInsecureClientDisablePkce = true, so the NixOS kanidm module enforces PKCE on it by default (nixos/modules/services/security/kanidm.nix:652-654,918-919, confirmed present in this repo's nix-store checkout). But the control-plane's own OIDC client, internal/controlapi/oidcprovider.go:71-88 (kanidmOIDC.AuthCodeURL), builds the authorize URL with only response_type, client_id, redirect_uri, scope, state — no code_challenge/code_challenge_method.

Evidence, live on this run — logs/droplet-journal.txt:1983-1992 (timestamps 01:16:53–54Z, inside the oidc-admin leg's window per artifacts/legs.json):

kanidmd ... GET /ui/oauth2?client_id=gate-oidc&redirect_uri=https%3A%2F%2Frehearsal-b.idss.nz%2Fauthz%2Fcallback...
kanidmd ... ERROR 🚨 Invalid identity: NotAuthenticated
kanidmd ... ERROR 🚨 No PKCE code challenge was provided with client in enforced PKCE mode | o2rs.name: "gate-oidc"
kanidmd ... ERROR 🚨 Unable to authorise - Error ID: ... error: invalid_request

(repeats twice, ~1s apart — two independent forward_auth 401 round-trips).

Why this leg, not the earlier ones

On the own-VPS public path every SERVICE route (files included) sits behind the gate's forward_auth template again since #566 (internal/clan/frontdoor.go:405-439 renderRoute, comment at 405-411). /login is not in files.go's FilesExemptPaths (internal/clan/files.go:74-79, only DAV + /status.php are exempt) — files.go:63-64 says as much: "direct browser entry to files. stays behind forward_auth". So any browser hitting files.<apex>/login without a community SSO cookie 401s, gets redirected to /authz/signin?rd=... (internal/controlapi/signin.go:124-144), which 302s to kanidm's gate-oidc authorize endpoint — and dies on the PKCE check above.

The bare apex root (portalAddress, what sign-in/co-host/deploy-files/files-healthy/door all exercise) is explicitly ungated (internal/clan/frontdoor.go:487-498 renderPortalRoute, "Ungated this arc (#512, parity with the private path)") — those legs never touch the broken gate at all, which is why they stayed green.

branded-login (the leg immediately before oidc-admin) also hits files.<apex>/login, from a fresh cookie-less browser, and also PASSED (866ms) — almost certainly a false green: its assertion (provision.ts assertBrandedLogin, waits on h3, input[type=text]:visible, input[name*="user" i]:visible) is loose enough that kanidm's own community-branded "Unable to authorise" error shell likely satisfies it, since kanidm renders the community heading on its error pages too. oidc-admin's stricter race (real Nextcloud chrome vs. a real username field) is what actually caught the break.

Suspected layer

Go (internal/controlapi OIDC client) + Nix render (internal/clan/vmguest.go kanidm client provision) — security-sensitive auth-flow code, not a rendering/selector/constant slip.

What plugging it needs

A ruling on approach, then implementation:

  1. Implement PKCE properly (architecturally consistent with #566's design): generate a code_verifier per flow in signinStart, add it to the sealed flowState (internal/controlapi/signin.go:211-215), send code_challenge/code_challenge_method=S256 in AuthCodeURL (oidcprovider.go), and the stored code_verifier in Exchange's token POST. Touches the OIDCProvider interface (both methods' signatures) and its seam-test fakes (internal/controlapi/signin_test.go, likely an oidcprovider_test.go) — genuine feature work, not mechanical.
  2. Or set allowInsecureClientDisablePkce = true on the gate-oidc client in vmguest.go:679-687 — a one-block Nix change, but a conscious security-posture call (the nixpkgs option name says as much: "You should request the client to enable PKCE!") that needs a human/ADR ruling, not a silent self-fix, and isn't verifiable against a real kanidm from this checkout anyway.

Either way, assertBrandedLogin's selector (provision.ts) is worth tightening afterward so this failure mode can't false-green again.

Run dir: /home/dev/swarm/Matou/idss/test-results/drive-droplet/20260822T010329Z

drive 20260822T010329Z red at oidc-admin: page.waitForSelector: Timeout 60000ms exceeded. Call log: - waiting for locator('#header') to be visible
evidence: test-results/…/20260822T010329Z/ on matou-workstation (legs.json, droplet-journal.txt, trace) — a representative screenshot is attached here if one was captured (#596)

## Failure Drive `20260822T010329Z`, leg `oidc-admin`, red on `page.waitForSelector('#header')` timeout (60s), raced against a kanidm-login-field wait that also timed out (`app/tests/e2e/fixtures/provision.ts:640-647`) — neither Nextcloud's signed-in chrome nor kanidm's login form ever appeared after `ceremony.goto(doorPath(door, '/login'))` (`app/tests/e2e/journey.droplet.spec.ts:576-579`). ## Root cause kanidm's `gate-oidc` OAuth2 client — the community-SSO gate's own OIDC client (ADR 0074/#566), provisioned in `internal/clan/vmguest.go:679-687` (`gatewayKanidmProvision`'s `gateOAuth2` block) — is never given `allowInsecureClientDisablePkce = true`, so the NixOS kanidm module enforces PKCE on it by default (`nixos/modules/services/security/kanidm.nix:652-654,918-919`, confirmed present in this repo's nix-store checkout). But the control-plane's own OIDC client, `internal/controlapi/oidcprovider.go:71-88` (`kanidmOIDC.AuthCodeURL`), builds the authorize URL with only `response_type`, `client_id`, `redirect_uri`, `scope`, `state` — **no `code_challenge`/`code_challenge_method`**. Evidence, live on this run — `logs/droplet-journal.txt:1983-1992` (timestamps 01:16:53–54Z, inside the oidc-admin leg's window per `artifacts/legs.json`): ``` kanidmd ... GET /ui/oauth2?client_id=gate-oidc&redirect_uri=https%3A%2F%2Frehearsal-b.idss.nz%2Fauthz%2Fcallback... kanidmd ... ERROR 🚨 Invalid identity: NotAuthenticated kanidmd ... ERROR 🚨 No PKCE code challenge was provided with client in enforced PKCE mode | o2rs.name: "gate-oidc" kanidmd ... ERROR 🚨 Unable to authorise - Error ID: ... error: invalid_request ``` (repeats twice, ~1s apart — two independent forward_auth 401 round-trips). ## Why this leg, not the earlier ones On the own-VPS public path every SERVICE route (files included) sits behind the gate's `forward_auth` template again since #566 (`internal/clan/frontdoor.go:405-439` `renderRoute`, comment at 405-411). `/login` is not in `files.go`'s `FilesExemptPaths` (`internal/clan/files.go:74-79`, only DAV + `/status.php` are exempt) — files.go:63-64 says as much: "direct browser entry to files.<apex> stays behind forward_auth". So any browser hitting `files.<apex>/login` without a community SSO cookie 401s, gets redirected to `/authz/signin?rd=...` (`internal/controlapi/signin.go:124-144`), which 302s to kanidm's `gate-oidc` authorize endpoint — and dies on the PKCE check above. The bare apex root (`portalAddress`, what `sign-in`/`co-host`/`deploy-files`/`files-healthy`/`door` all exercise) is explicitly **ungated** (`internal/clan/frontdoor.go:487-498` `renderPortalRoute`, "Ungated this arc (#512, parity with the private path)") — those legs never touch the broken gate at all, which is why they stayed green. `branded-login` (the leg immediately before oidc-admin) also hits `files.<apex>/login`, from a fresh cookie-less browser, and also PASSED (866ms) — almost certainly a **false green**: its assertion (`provision.ts` `assertBrandedLogin`, waits on `h3, input[type=text]:visible, input[name*="user" i]:visible`) is loose enough that kanidm's own community-branded "Unable to authorise" error shell likely satisfies it, since kanidm renders the community heading on its error pages too. `oidc-admin`'s stricter race (real Nextcloud chrome vs. a real username field) is what actually caught the break. ## Suspected layer Go (`internal/controlapi` OIDC client) + Nix render (`internal/clan/vmguest.go` kanidm client provision) — security-sensitive auth-flow code, not a rendering/selector/constant slip. ## What plugging it needs A ruling on approach, then implementation: 1. **Implement PKCE properly** (architecturally consistent with #566's design): generate a `code_verifier` per flow in `signinStart`, add it to the sealed `flowState` (`internal/controlapi/signin.go:211-215`), send `code_challenge`/`code_challenge_method=S256` in `AuthCodeURL` (`oidcprovider.go`), and the stored `code_verifier` in `Exchange`'s token POST. Touches the `OIDCProvider` interface (both methods' signatures) and its seam-test fakes (`internal/controlapi/signin_test.go`, likely an `oidcprovider_test.go`) — genuine feature work, not mechanical. 2. **Or** set `allowInsecureClientDisablePkce = true` on the `gate-oidc` client in `vmguest.go:679-687` — a one-block Nix change, but a conscious security-posture call (the nixpkgs option name says as much: "You should request the client to enable PKCE!") that needs a human/ADR ruling, not a silent self-fix, and isn't verifiable against a real kanidm from this checkout anyway. Either way, `assertBrandedLogin`'s selector (`provision.ts`) is worth tightening afterward so this failure mode can't false-green again. Run dir: `/home/dev/swarm/Matou/idss/test-results/drive-droplet/20260822T010329Z` drive `20260822T010329Z` red at `oidc-admin`: `page.waitForSelector: Timeout 60000ms exceeded. Call log: - waiting for locator('#header') to be visible` evidence: `test-results/…/20260822T010329Z/` on matou-workstation (legs.json, droplet-journal.txt, trace) — a representative screenshot is attached here if one was captured (#596) <!-- rehearsal-sig: 94a048d819e4 -->
Author
Member

Ruled by agent under ADR 0174 — veto anytime.

Ruling: implement PKCE properly (option 1), not the Nix allowInsecureClientDisablePkce escape hatch (option 2).

Why this is the two-way door: option 1 is a code change to internal/controlapi/{signin,oidcprovider}.go, revertible with a commit, and provable by the existing OIDCProvider seam tests (signin_test.go) plus a new PKCE-specific assertion in TestKanidmOIDC_ExchangesAgainstAFakeIdP and TestAuthzSignin_CompletesFlowAndMintsSession — no live kanidm needed to prove the client now sends a matching code_challenge/code_verifier pair, per ADR 0174 rule 1.

Option 2 is explicitly out of scope for this session: it is a security-posture widening (disabling PKCE enforcement on a real OAuth2 client) — ADR 0174 rule 3's one-way-door list names this exact class ("loosening an auth requirement, the #329-class ruling"). It also isn't verifiable from this checkout (no live kanidm). Not taking it.

Proceeding with option 1.

Ruled by agent under ADR 0174 — veto anytime. **Ruling: implement PKCE properly (option 1)**, not the Nix `allowInsecureClientDisablePkce` escape hatch (option 2). Why this is the two-way door: option 1 is a code change to `internal/controlapi/{signin,oidcprovider}.go`, revertible with a commit, and provable by the existing OIDCProvider seam tests (`signin_test.go`) plus a new PKCE-specific assertion in `TestKanidmOIDC_ExchangesAgainstAFakeIdP` and `TestAuthzSignin_CompletesFlowAndMintsSession` — no live kanidm needed to prove the client now sends a matching `code_challenge`/`code_verifier` pair, per ADR 0174 rule 1. Option 2 is explicitly out of scope for this session: it is a security-posture *widening* (disabling PKCE enforcement on a real OAuth2 client) — ADR 0174 rule 3's one-way-door list names this exact class ("loosening an auth requirement, the #329-class ruling"). It also isn't verifiable from this checkout (no live kanidm). Not taking it. Proceeding with option 1.
Author
Member

Close report

Landed: acc5a7aa — control-plane's OIDC client now runs PKCE (RFC 7636 S256), matching kanidm's enforced gate-oidc client (option 1 from the ticket; ruling above).

What changed:

  • internal/controlapi/signin.go: signinStart mints an S256 code_verifier/code_challenge pair per flow (newPKCE), seals the verifier in the existing signed, HttpOnly flow cookie (never the browser-visible authorize URL), and signinCallback hands it to Exchange at token-exchange time. flowState gained a CodeVerifier field.
  • internal/controlapi/oidcprovider.go: kanidmOIDC.AuthCodeURL now sends code_challenge/code_challenge_method=S256; Exchange now sends code_verifier in the token POST. OIDCProvider's two interface methods each gained a PKCE parameter (no other callers in the tree — grepped clean).
  • internal/controlapi/signin_test.go (TDD, red confirmed first via go vet failing on the old signatures): the full-flow seam test now asserts kanidm receives a code_challenge at authorize and that the exchange-time verifier's S256 hash matches it; TestKanidmOIDC_ExchangesAgainstAFakeIdP runs against a fake IdP that itself enforces PKCE (400s a mismatched/missing verifier, modelling kanidm's real behaviour), asserting both the successful pair and a mismatched-verifier failure.
  • app/tests/e2e/fixtures/provision.ts's assertBrandedLogin: dropped the bare h3 alternative from its wait selector — kanidm renders the same community-branded heading on its own authorise-ERROR shell, so the old selector could false-green (this is very likely what happened to branded-login on the failing drive, per the ticket's own analysis). Now requires the actual username field.

Nix side: confirmed internal/clan/vmguest.go's gateOAuth2 block needed NO change — the fix is entirely the Go client now speaking PKCE. Did not touch allowInsecureClientDisablePkce (option 2) — that stays unruled, per the ADR 0174 comment above (one-way-door security-posture widening).

Proof:

  • go build ./..., go vet ./..., gofmt -l . — clean.
  • go test ./... — all green (internal/controlapi 0.2s, full tree ~unchanged elsewhere).
  • vue-tsc -p app/tsconfig.json (covers app/tests) — clean, confirms the provision.ts edit type-checks.
  • Live proof is necessarily the next own-VPS rehearsal drive's oidc-admin leg against a real kanidm — this session's checkout has no live kanidm to exchange a real PKCE-enforced authorize/token round-trip against, same constraint the ticket itself named. Closing on the strength of the seam tests proving the client now sends and round-trips a genuine matching PKCE pair (ADR 0174 rule 1: revertible + provable by existing test), consistent with the #641/#642 precedent this same drive lineage set.

advances #643

## Close report **Landed:** `acc5a7aa` — control-plane's OIDC client now runs PKCE (RFC 7636 S256), matching kanidm's enforced `gate-oidc` client (option 1 from the ticket; ruling above). **What changed:** - `internal/controlapi/signin.go`: `signinStart` mints an S256 `code_verifier`/`code_challenge` pair per flow (`newPKCE`), seals the verifier in the existing signed, HttpOnly flow cookie (never the browser-visible authorize URL), and `signinCallback` hands it to `Exchange` at token-exchange time. `flowState` gained a `CodeVerifier` field. - `internal/controlapi/oidcprovider.go`: `kanidmOIDC.AuthCodeURL` now sends `code_challenge`/`code_challenge_method=S256`; `Exchange` now sends `code_verifier` in the token POST. `OIDCProvider`'s two interface methods each gained a PKCE parameter (no other callers in the tree — grepped clean). - `internal/controlapi/signin_test.go` (TDD, red confirmed first via `go vet` failing on the old signatures): the full-flow seam test now asserts kanidm receives a `code_challenge` at authorize and that the exchange-time verifier's S256 hash matches it; `TestKanidmOIDC_ExchangesAgainstAFakeIdP` runs against a fake IdP that itself enforces PKCE (400s a mismatched/missing verifier, modelling kanidm's real behaviour), asserting both the successful pair and a mismatched-verifier failure. - `app/tests/e2e/fixtures/provision.ts`'s `assertBrandedLogin`: dropped the bare `h3` alternative from its wait selector — kanidm renders the same community-branded heading on its own authorise-ERROR shell, so the old selector could false-green (this is very likely what happened to `branded-login` on the failing drive, per the ticket's own analysis). Now requires the actual username field. **Nix side:** confirmed `internal/clan/vmguest.go`'s `gateOAuth2` block needed NO change — the fix is entirely the Go client now speaking PKCE. Did not touch `allowInsecureClientDisablePkce` (option 2) — that stays unruled, per the ADR 0174 comment above (one-way-door security-posture widening). **Proof:** - `go build ./...`, `go vet ./...`, `gofmt -l .` — clean. - `go test ./...` — all green (`internal/controlapi` 0.2s, full tree ~unchanged elsewhere). - `vue-tsc -p app/tsconfig.json` (covers `app/tests`) — clean, confirms the `provision.ts` edit type-checks. - Live proof is necessarily the **next own-VPS rehearsal drive's `oidc-admin` leg** against a real kanidm — this session's checkout has no live kanidm to exchange a real PKCE-enforced authorize/token round-trip against, same constraint the ticket itself named. Closing on the strength of the seam tests proving the client now sends and round-trips a genuine matching PKCE pair (ADR 0174 rule 1: revertible + provable by existing test), consistent with the #641/#642 precedent this same drive lineage set. advances #643
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.

Reference
Matou/idss#643
No description provided.