auth gate: build the gate-as-OIDC-client session flow (ADR 0074's named substrate) and re-gate the public files browser surface #566

Closed
opened 2026-08-15 04:58:42 +00:00 by ben · 2 comments
Owner

The other half of #565. ADR 0074 rules the ingress identity-aware: every browser request passes forward_auth against the control-plane auth gate, which is "an OIDC client of kanidm and holds the community SSO session", seeded at founding. Today only the authorization half exists (internal/controlapi/authgate.go answers allow/deny off a header) — nothing ESTABLISHES the session, so a browser can never pass the gate, which is why #565 ungates the files browser surface as the ADR 0150-parity interim.

Build the substrate:

  1. Session establishment: a control-plane endpoint (e.g. GET /authz/signin?rd=<url>) that runs an OIDC authorization-code flow against kanidm as the gate's own OAuth2 client (founding seeds it per ADR 0074 — verify it actually does; seed it there if not), then sets the community SSO session cookie.
  2. Cookie scope: the session cookie must carry Domain=.<apex> so one sign-in spans the portal and every service subdomain (files., admin.) — otherwise forward_auth subrequests from service hosts see nothing.
  3. A cookie SessionResolver: resolve the member identity from that session (server-side session or verified token) instead of the never-set X-Ourcloud-Identity request header; the header stays as the gate→route echo on allow.
  4. rd consumption: on flow completion redirect the browser to the validated rd (same-apex origins only — an open redirect here is a phishing door).
  5. Redirect target: renderGateRedirect (internal/clan/frontdoor.go) points at this signin endpoint (the ungated portal apex carries it: https://<apex>/authz/signin?rd=...) instead of the IdP root that ignores rd — the dead end drive 20260815T043450Z proved (browser stranded on kanidm /ui/apps).
  6. Re-gate files: restore forward_auth on the public files route's browser surface (reverting #565's interim), and prove the walk: cold browser → files./login → gate 401 → signin → kanidm → back with session → gate allow → Nextcloud's own user_oidc walk → signed in.

The admin route (DDR 0172) inherits the same session for its operators-only decision — no separate flow.

Design authority: ADR 0074 (decided; this implements, no new ruling needed). Evidence of the gap: drive 20260815T043450Z, kanidm journal 04:47:52 (/ui/login 303 → /ui/apps, zero authorize requests), and renderGateRedirect's docstring naming this exact substrate as unbuilt.

advances #492

The other half of #565. ADR 0074 rules the ingress identity-aware: every browser request passes `forward_auth` against the control-plane auth gate, which is "an OIDC client of kanidm and holds the community SSO session", seeded at founding. Today only the authorization half exists (`internal/controlapi/authgate.go` answers allow/deny off a header) — nothing ESTABLISHES the session, so a browser can never pass the gate, which is why #565 ungates the files browser surface as the ADR 0150-parity interim. Build the substrate: 1. **Session establishment**: a control-plane endpoint (e.g. `GET /authz/signin?rd=<url>`) that runs an OIDC authorization-code flow against kanidm as the gate's own OAuth2 client (founding seeds it per ADR 0074 — verify it actually does; seed it there if not), then sets the community SSO session cookie. 2. **Cookie scope**: the session cookie must carry `Domain=.<apex>` so one sign-in spans the portal and every service subdomain (files.<apex>, admin.<apex>) — otherwise forward_auth subrequests from service hosts see nothing. 3. **A cookie SessionResolver**: resolve the member identity from that session (server-side session or verified token) instead of the never-set `X-Ourcloud-Identity` request header; the header stays as the gate→route echo on allow. 4. **`rd` consumption**: on flow completion redirect the browser to the validated `rd` (same-apex origins only — an open redirect here is a phishing door). 5. **Redirect target**: `renderGateRedirect` (internal/clan/frontdoor.go) points at this signin endpoint (the ungated portal apex carries it: `https://<apex>/authz/signin?rd=...`) instead of the IdP root that ignores `rd` — the dead end drive `20260815T043450Z` proved (browser stranded on kanidm `/ui/apps`). 6. **Re-gate files**: restore `forward_auth` on the public files route's browser surface (reverting #565's interim), and prove the walk: cold browser → files.<apex>/login → gate 401 → signin → kanidm → back with session → gate allow → Nextcloud's own user_oidc walk → signed in. The admin route (DDR 0172) inherits the same session for its operators-only decision — no separate flow. Design authority: ADR 0074 (decided; this implements, no new ruling needed). Evidence of the gap: drive `20260815T043450Z`, kanidm journal 04:47:52 (`/ui/login` 303 → `/ui/apps`, zero authorize requests), and `renderGateRedirect`'s docstring naming this exact substrate as unbuilt. advances #492
Author
Owner

swarm-claim host=elitebook-distributed-server-03 run=6697
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=elitebook-distributed-server-03 run=6697 (automated multi-host claim — lowest live claim id works this ticket)
Author
Owner

close-report for #566 — status success

✅ close-report gates passed — every claim verified against main; closing.

envelope
{
  "issue": 566,
  "status": "success",
  "commits": [
    "d00f3bc2b7c51c95bf3e5788ce84a612a8badaa3"
  ],
  "changed_files": [
    "STATUS.md",
    "control-plane/cmd/control-plane/main.go",
    "internal/clan/files_frontdoor_test.go",
    "internal/clan/frontdoor.go",
    "internal/clan/frontdoor_private_test.go",
    "internal/clan/frontdoor_test.go",
    "internal/clan/gateway_attach_test.go",
    "internal/clan/generators_pin_test.go",
    "internal/clan/vmguest.go",
    "internal/controlapi/oidcprovider.go",
    "internal/controlapi/session.go",
    "internal/controlapi/session_test.go",
    "internal/controlapi/signin.go",
    "internal/controlapi/signin_internal_test.go",
    "internal/controlapi/signin_test.go"
  ],
  "tests": [
    {
      "command": "go build ./...",
      "exit_code": 0
    },
    {
      "command": "go vet ./...",
      "exit_code": 0
    },
    {
      "command": "go test ./internal/controlapi/",
      "exit_code": 0
    },
    {
      "command": "go test ./internal/clan/",
      "exit_code": 0
    },
    {
      "command": "go test ./internal/provision/ ./control-plane/cmd/control-plane/",
      "exit_code": 0
    }
  ],
  "criteria": {
    "1. Session establishment: a control-plane endpoint runs an OIDC authorization-code flow against kanidm as the gate's own OAuth2 client, then sets the SSO session cookie (and founding seeds the client)": "internal/controlapi/signin.go (GET /authz/signin + /authz/callback) + oidcprovider.go (real kanidm discovery→token→userinfo client); founding seeds the kanidm systems.oauth2 gate-oidc client with a pre-shared basicSecretFile in internal/clan/vmguest.go (gatewayKanidmProvision + gate-oidc generator). Tests: TestAuthzSignin_CompletesFlowAndMintsSession, TestKanidmOIDC_ExchangesAgainstAFakeIdP, TestAttachGateway_ControlPlaneReachesOwnVPSGateway (seed carried + Nix parses)",
    "2. Cookie scope: the session cookie carries Domain=.<apex> so one sign-in spans portal + every service subdomain": "internal/controlapi/session.go SessionCookie() sets Domain=<apex> (RFC 6265 subdomain-match). Test: TestSessionCookie_SpansSubdomainsAndIsHardened, and TestAuthzSignin_CompletesFlowAndMintsSession asserts the minted cookie's Domain",
    "3. A cookie SessionResolver resolves member identity from the session instead of the never-set X-Ourcloud-Identity header": "internal/controlapi/session.go CookieSessionResolver (implements SessionResolver); wired onto the gate in control-plane/cmd/control-plane/main.go (WithAuthGate(c.mem, gateResolver)). Test: TestCookieSessionResolver_ResolvesSignedCookie",
    "4. rd consumption: on flow completion redirect to the validated rd (same-apex origins only — no open redirect)": "internal/controlapi/signin.go sameApexRedirect() + callback redirect to the validated rd. Tests: TestSameApexRedirect, TestAuthzSignin_RefusesOffApexRedirect",
    "5. Redirect target: renderGateRedirect points at https://<apex>/authz/signin?rd=... instead of the IdP root": "internal/clan/frontdoor.go renderGateRedirect now emits redir https://<apex>/authz/signin?rd=... Tests: TestRenderFrontDoor_UnauthBrowserRedirectsToSignin, the admin-route + private-path redirect assertions",
    "6. Re-gate files: restore forward_auth on the public files route's browser surface (revert #565), and prove the walk": "internal/clan/frontdoor.go renderRoute re-gates files (routeIsUngated removed); exempt paths still bypass. Test: TestAttachFrontDoor_FilesBrowserRouteIsReGated. The live walk (cold browser → files 401 → signin → kanidm → session → allow → Nextcloud user_oidc) is proven by the next DRIVE — the code slice is seam-green + build/vet green, exactly how every prior #492 tooth (#560/#562/#565) shipped and was drive-proven; the real-nixpkgs eval smoke could not run in-sandbox (no CI SOPS key)"
  },
  "summary": "Built the gate-as-OIDC-client SSO session substrate (/authz/signin OIDC flow + Domain-scoped session cookie + cookie resolver + same-apex rd guard, stdlib-only), seeded the kanidm gate-oidc client at founding, wired it into the control plane, and re-gated the public files browser surface with the 401 now redirecting to /authz/signin.",
  "blockers": []
}
**close-report** for #566 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; closing. <details><summary>envelope</summary> ```json { "issue": 566, "status": "success", "commits": [ "d00f3bc2b7c51c95bf3e5788ce84a612a8badaa3" ], "changed_files": [ "STATUS.md", "control-plane/cmd/control-plane/main.go", "internal/clan/files_frontdoor_test.go", "internal/clan/frontdoor.go", "internal/clan/frontdoor_private_test.go", "internal/clan/frontdoor_test.go", "internal/clan/gateway_attach_test.go", "internal/clan/generators_pin_test.go", "internal/clan/vmguest.go", "internal/controlapi/oidcprovider.go", "internal/controlapi/session.go", "internal/controlapi/session_test.go", "internal/controlapi/signin.go", "internal/controlapi/signin_internal_test.go", "internal/controlapi/signin_test.go" ], "tests": [ { "command": "go build ./...", "exit_code": 0 }, { "command": "go vet ./...", "exit_code": 0 }, { "command": "go test ./internal/controlapi/", "exit_code": 0 }, { "command": "go test ./internal/clan/", "exit_code": 0 }, { "command": "go test ./internal/provision/ ./control-plane/cmd/control-plane/", "exit_code": 0 } ], "criteria": { "1. Session establishment: a control-plane endpoint runs an OIDC authorization-code flow against kanidm as the gate's own OAuth2 client, then sets the SSO session cookie (and founding seeds the client)": "internal/controlapi/signin.go (GET /authz/signin + /authz/callback) + oidcprovider.go (real kanidm discovery→token→userinfo client); founding seeds the kanidm systems.oauth2 gate-oidc client with a pre-shared basicSecretFile in internal/clan/vmguest.go (gatewayKanidmProvision + gate-oidc generator). Tests: TestAuthzSignin_CompletesFlowAndMintsSession, TestKanidmOIDC_ExchangesAgainstAFakeIdP, TestAttachGateway_ControlPlaneReachesOwnVPSGateway (seed carried + Nix parses)", "2. Cookie scope: the session cookie carries Domain=.<apex> so one sign-in spans portal + every service subdomain": "internal/controlapi/session.go SessionCookie() sets Domain=<apex> (RFC 6265 subdomain-match). Test: TestSessionCookie_SpansSubdomainsAndIsHardened, and TestAuthzSignin_CompletesFlowAndMintsSession asserts the minted cookie's Domain", "3. A cookie SessionResolver resolves member identity from the session instead of the never-set X-Ourcloud-Identity header": "internal/controlapi/session.go CookieSessionResolver (implements SessionResolver); wired onto the gate in control-plane/cmd/control-plane/main.go (WithAuthGate(c.mem, gateResolver)). Test: TestCookieSessionResolver_ResolvesSignedCookie", "4. rd consumption: on flow completion redirect to the validated rd (same-apex origins only — no open redirect)": "internal/controlapi/signin.go sameApexRedirect() + callback redirect to the validated rd. Tests: TestSameApexRedirect, TestAuthzSignin_RefusesOffApexRedirect", "5. Redirect target: renderGateRedirect points at https://<apex>/authz/signin?rd=... instead of the IdP root": "internal/clan/frontdoor.go renderGateRedirect now emits redir https://<apex>/authz/signin?rd=... Tests: TestRenderFrontDoor_UnauthBrowserRedirectsToSignin, the admin-route + private-path redirect assertions", "6. Re-gate files: restore forward_auth on the public files route's browser surface (revert #565), and prove the walk": "internal/clan/frontdoor.go renderRoute re-gates files (routeIsUngated removed); exempt paths still bypass. Test: TestAttachFrontDoor_FilesBrowserRouteIsReGated. The live walk (cold browser → files 401 → signin → kanidm → session → allow → Nextcloud user_oidc) is proven by the next DRIVE — the code slice is seam-green + build/vet green, exactly how every prior #492 tooth (#560/#562/#565) shipped and was drive-proven; the real-nixpkgs eval smoke could not run in-sandbox (no CI SOPS key)" }, "summary": "Built the gate-as-OIDC-client SSO session substrate (/authz/signin OIDC flow + Domain-scoped session cookie + cookie resolver + same-apex rd guard, stdlib-only), seeded the kanidm gate-oidc client at founding, wired it into the control plane, and re-gated the public files browser surface with the 401 now redirecting to /authz/signin.", "blockers": [] } ``` </details>
ben closed this issue 2026-08-15 06:05:02 +00:00
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#566
No description provided.