From 7e199f1fac2b9ab9f92f40ae2ae5d9ec74413b89 Mon Sep 17 00:00:00 2001 From: 13768039+zomby1 <13768039+zomby1@users.noreply.github.com> Date: Wed, 25 Nov 2026 09:32:11 +0100 Subject: [PATCH] docs(auth): trusted-proxy review points: claim trust, SameSite, hook replies The walkthrough now says the app registration is single-tenant, that email and preferred_username are mutable, and that a logon name with a dot needs the map. oauth2-proxy gets cookie_samesite = lax, and its identity headers are removed on the way to Codeman. The API reference lists the hook's plain-text replies for a proxy sign-in and the 404 for an unknown HTML-view capability. --- docs/api-reference.md | 28 +++++++++++++++++++++++++--- docs/multi-user-plan.md | 2 +- docs/wiki/Multi-User-Mode.md | 30 +++++++++++++++++++++++++++--- 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/docs/api-reference.md b/docs/api-reference.md index 98740959..ded48797 100644 --- a/docs/api-reference.md +++ b/docs/api-reference.md @@ -59,10 +59,13 @@ payload return `{ "success": true, "data": {} }`. > to 600 s. Proxy operators and HTTP clients with a global read timeout need to know > that before pointing them at Codeman. -⚠️ **A `401` is the one status that is not an envelope.** Authentication is rejected +⚠️ **A `401` is not an envelope.** Authentication is rejected in a request hook, before any handler runs, and it replies with the bare string `Unauthorized` (`Unauthorized: hook secret required` on the hook path) plus -`WWW-Authenticate: Basic realm="Codeman"`. There is no `success`, no `error`, and no +`WWW-Authenticate: Basic realm="Codeman"`. With trusted-proxy sign-in on (experimental, +see [Authentication](#authentication)) the same hook has more plain-text replies: a `401` +without `WWW-Authenticate`, a `403` and a `503` for a refused proxy identity, and a `403` +or `404` for a `/webview/` or `/html-view/` path without a live capability. There is no `success`, no `error`, and no `errorCode`, because the wrapping hook only wraps object payloads. So a client that pipes every response straight into a JSON parser dies with a parse error rather than reporting an auth failure, which is a confusing way to discover that a password is @@ -976,7 +979,8 @@ by the owner's decision the page may load from and send requests to any host), ` `Referrer-Policy: no-referrer` and `Access-Control-Allow-Origin: *`. A `Range` request is answered with `206` + `Content-Range` (`416` past the end), like `file-raw`. Every refusal is a plain-text `404 Not found`; with a password set, an -unknown or revoked capability is the auth hook's `401` instead. +unknown or revoked capability is the auth hook's `401` instead. With trusted-proxy sign-in +on it is the hook's plain-text `404`, with no challenge. ## Session lineage (`parentSessionId`) @@ -1894,6 +1898,24 @@ Optional HTTP Basic (`CODEMAN_USERNAME`/`CODEMAN_PASSWORD`) → opaque `401 UNAUTHORIZED`; rate-limited requests get `429 RATE_LIMITED`. See [`security-architecture.md`](security-architecture.md). +**Trusted-proxy sign-in (experimental, multi-user mode, off unless a secret is +configured).** An authenticating reverse proxy on the same host sends +`X-Codeman-Proxy-Secret` and `X-Codeman-User` over loopback, and the request runs as that +existing, enabled account. No cookie is issued, and `GET /api/me` reports +`viaTrustedProxy: true`. The hook's refusals on this path are plain text, not envelopes: + +| Status | When | +|---|---| +| `401`, no `WWW-Authenticate` | the secret is wrong, or the request did not arrive over loopback | +| `403` | the secret is right, but there is no username or no enabled account with that name | +| `503` | the user store cannot be read | +| `429` | too many wrong secrets from one address | + +With the feature on, a path under `/webview/` or `/html-view/` without a live capability is +answered by the hook before any credential is looked at: plain-text `403` for a web tab, +`404` for an HTML view, no challenge. See +[`security-architecture.md` §10a](security-architecture.md). + ## SSE event channel `GET /api/events` is a Server-Sent Events stream (`text/event-stream`); each diff --git a/docs/multi-user-plan.md b/docs/multi-user-plan.md index a2f71a12..73e2b9f5 100644 --- a/docs/multi-user-plan.md +++ b/docs/multi-user-plan.md @@ -188,7 +188,7 @@ All handlers: multi-user mode only (404 otherwise), `requireAdmin`, Zod schemas | `POST /api/admin/users/:username/logout` | Revoke all cookie sessions for that user. Honest limit under Basic auth: the browser silently re-sends cached credentials and gets a fresh cookie on the next request, so logout only truly ends QR-issued sessions; to actually lock someone out, disable the account or reset the password. For a person who signs in through a trusted reverse proxy, neither logout nor a reset ends access (no cookie, no password): disable or delete the account. Say so in the panel tooltip until Phase 6 | | `DELETE /api/admin/users/:username` | `{ deleteSpace?: boolean }` (default false). Refuses last admin. Kills the user's live sessions first (normal kill flow, incl. docker/remote teardown per case), revokes cookies, removes from store. With `deleteSpace`: guarded recursive delete of `~/codeman-users/` (realpath must be inside `USER_SPACES_DIR`, top-level dir must not be a symlink), plus their registry entries and push subscriptions | | `POST /api/admin/cases/assign` | Move a legacy `~/codeman-cases/` into a user's space (`fs.rename`) | -| Self-service `GET /api/me` | `{ username, role, mustChangePassword }` (works in single-user mode too: synthetic admin; the frontend uses it to decide whether to render admin UI) | +| Self-service `GET /api/me` | `{ username, role, mustChangePassword, multiUser, viaTrustedProxy }` (works in single-user mode too: synthetic admin without `viaTrustedProxy`; the frontend uses it to decide whether to render admin UI). For a trusted-proxy sign-in `viaTrustedProxy` is `true` and `mustChangePassword` is reported as `false` | | Self-service `POST /api/me/password` | `{ currentPassword, newPassword }`, verifies current, min length 8, revokes other sessions, clears `mustChangePassword` | **Audit log**: append-only `~/.codeman/admin-audit.jsonl` (same idiom as `session-lifecycle.jsonl`): timestamp, acting admin, action, target, request IP. User management without an audit trail is not acceptable even for a homelab tool. diff --git a/docs/wiki/Multi-User-Mode.md b/docs/wiki/Multi-User-Mode.md index df4be852..66989130 100644 --- a/docs/wiki/Multi-User-Mode.md +++ b/docs/wiki/Multi-User-Mode.md @@ -213,6 +213,7 @@ set_xauthrequest = true # return the identity as X-Auth-Request-* heade skip_provider_button = true upstreams = ["static://202"] # forward_auth only, nothing to proxy cookie_secure = true +cookie_samesite = "lax" # never sent from a sandboxed web-tab frame cookie_expire = "12h" # sign in again after this (default 168h) cookie_refresh = "1h" # re-check with the provider this often scope = "openid email profile offline_access" # offline_access: a refresh token (Entra ID) @@ -226,6 +227,19 @@ needs a refresh token: without one (for Entra ID, without `offline_access` in th oauth2-proxy can't refresh, and people are sent back through sign-in whenever the ID token expires, about hourly. +Set `cookie_samesite`. oauth2-proxy puts no `SameSite` attribute on its cookie unless it is +configured, and browsers disagree about a cookie without one. With `lax`, a sandboxed +web-tab frame does not send the proxy's cookie in any browser. + +The username Codeman gets is only as trustworthy as the claim it comes from: + +- **Register the app as single-tenant.** The proxy trusts values that the administrators + of the signing-in person's tenant control, so only your own tenant may sign in. +- **`email` and `preferred_username` are mutable.** An administrator can change them, and + an address can be given to another person later. That person then gets the Codeman + account the address maps to, until you remove its row from the `map` below. Go through + the table when people leave or are renamed. + ### Caddy Give Caddy the same secret through its environment, not in the Caddyfile (which is often @@ -302,6 +316,8 @@ codeman.example.com { reverse_proxy 127.0.0.1:3000 { header_up X-Codeman-Proxy-Secret {env.CODEMAN_TRUSTED_PROXY_SECRET} header_up X-Codeman-User {codeman_user} + # Codeman needs only the two headers above. + header_up -X-Auth-Request-Email } } } @@ -320,6 +336,9 @@ Codeman cannot see a mistake here: - **The proxy's own cookie stops at the proxy.** The `request_header Cookie …` lines remove it on both routes. With a different `cookie_name` in oauth2-proxy, change the name in the pattern. +- **oauth2-proxy's identity headers stop at the proxy too.** `header_up -X-Auth-Request-Email` + removes the address on the way to Codeman, because the web-tab relay passes headers it + does not know on to dashboards. Check the order Caddy will actually use with `caddy adapt --config Caddyfile --adapter caddyfile` before going live. With @@ -337,7 +356,8 @@ fetch('/api/me', { headers: { 'X-Codeman-User': 'someone-else' } }).then((r) => The `map` is a list you maintain. If your provider can put the Codeman username into the ID token (for example the AD logon name: Entra ID can add it with a claims mapping policy that emits `user.onpremisessamaccountname` as a custom claim; the app then needs -`acceptMappedClaims` enabled), let oauth2-proxy return that claim as a header. That needs +`acceptMappedClaims` enabled, which belongs only on a single-tenant app registration), let +oauth2-proxy return that claim as a header. That needs oauth2-proxy 7.15.5 or later with its alpha config (`--alpha-config`), and the claim must be listed in the provider's `additionalClaims`, otherwise the header stays empty: @@ -381,13 +401,16 @@ route { reverse_proxy 127.0.0.1:3000 { header_up X-Codeman-Proxy-Secret {env.CODEMAN_TRUSTED_PROXY_SECRET} header_up X-Codeman-User {http.request.header.X-Auth-Request-Codeman-User} + header_up -X-Auth-Request-Email + header_up -X-Auth-Request-Codeman-User } } ``` Adding a person is then: allow them at the identity provider, and `codeman users add `. Codeman usernames allow letters, digits, `_` and `-` only, so -the claim must fit that. A browser that signed in before the claim existed needs to sign +the claim must fit that. A logon name with a dot (`jane.doe`) does not: for such accounts +keep the `map`. A browser that signed in before the claim existed needs to sign out (`/oauth2/sign_out`) and in again. ### Things to know @@ -407,7 +430,8 @@ out (`/oauth2/sign_out`) and in again. prompt or failure count, so anonymous requests can't probe passwords or lock out the password sign-in. - **When the proxy session expires**, API calls and the live-update stream get a redirect - to the sign-in page instead of a `401`; reload the page. The `rd=` return address is not + to the sign-in page instead of a `401`. A page cannot follow it, so an open Codeman page + shows "Reconnecting" and does not recover by itself: reload it to sign in again. The `rd=` return address is not URL-encoded, so a query string with `&` loses everything after the first one. - **`mustChangePassword` is ignored** for proxy sign-ins, since no Codeman password was used, and `GET /api/me` reports it as `false` for them. A person's own "Revoke all" and logout end Codeman cookies, not the proxy's