feat(auth): sign in through a trusted reverse proxy in multi-user mode (experimental)

Multi-user mode only accepted Codeman passwords over HTTP Basic, so a team with an
identity provider (Entra ID, Google, Keycloak, ...) had to sign in twice, with no link
between the two identities.

With a shared secret configured (CODEMAN_TRUSTED_PROXY_SECRET_FILE, or
CODEMAN_TRUSTED_PROXY_SECRET; at least 32 printable ASCII characters), an authenticating
reverse proxy on the same host (oauth2-proxy behind Caddy or nginx, mod_auth_openidc,
Authelia) forwards X-Codeman-Proxy-Secret and X-Codeman-User, and the request signs in
as that existing, enabled account. CODEMAN_TRUSTED_PROXY_USER_HEADER renames the
username header. The feature is experimental (docs/versioning-policy.md): its settings,
headers and the viaTrustedProxy field may change until promoted.

- Accepted only from a loopback socket (isLoopbackIp, now shared with the hook-secret
  bypass) with a timing-safe secret match.
- The secret is read once at the start of WebServer.start(), before sessions are spawned
  or restored, and both variables are then removed from process.env, since every
  session inherits Codeman's environment. The secret file's resolved path stays in the
  module for the sensitive-path blocklist.
- A configured setup that cannot be used stops the start, like the first boot without
  users, with a message that says why and never contains the secret: both variables
  set; a secret file that is unreadable, empty, or readable by group or others (not
  checked on Windows); a short or non-ASCII secret; a secret with multi-user mode off;
  a rejected username header name. getTrustedProxyConfig() returns null for the same
  cases as a second layer.
- Both headers are read and deleted from every request by the first auth hook, in every
  auth mode, so no exemption or route (e.g. the web-tab relay) can forward the secret.
  The relay's drop list names them too, including a configured username header.
- Fails closed once the secret header is present, even empty: a wrong secret or a
  non-loopback source is 401; a missing username, or one with no enabled account, is a
  plain 403 with no challenge. None of these falls through to cookie or Basic. A
  username header without the secret is ignored.
- The username is matched exactly: normalizeUsername(), then the user store's username
  rule, no other transformation. A header sent twice arrives joined ("alice, bob") and
  is refused.
- The secret is compared before the failure bucket, so a correct secret always passes;
  only failures are throttled, in their own per-IP bucket.
- Checked before the session cookie; a cookie on the same request is neither used nor
  refreshed, and no cookie is minted: the proxy authorizes every new request and
  WebSocket upgrade.
- mustChangePassword does not gate a proxy sign-in, and GET /api/me reports
  mustChangePassword: false and viaTrustedProxy: true. Proxy sign-ins update the
  last-login time at most every 15 minutes.
- The username header is removed from every request, so its name is validated by shape
  (an X-... extension header or Remote-User; standard and reserved headers refused).
- With the feature configured, a /webview/ or /html-view/ request the capability
  exemptions don't let through is refused with the route's own 403/404 before the
  credential checks, by prefix on a path normalised the way a proxy's matcher sees it
  (case-insensitive, percent-decoded, dot segments resolved), whatever the token looks
  like: the proxy has to let these paths through without its sign-in, so they must not
  reach the Basic check, prompt or failure bucket. Without a proxy they keep the normal
  401.
- The configured secret file is on the isSensitivePath blocklist.
- The startup log says "Trusted-proxy sign-in enabled (experimental)".
- Single-user mode, the Host/Origin guard and the hook-secret bypass are otherwise
  unchanged.

Docs: security-architecture §10a, architecture-invariants, versioning-policy (new
experimental subsection), Settings-Reference, web-tabs and its wiki page, multi-user-plan,
the CLAUDE.md summary line, and a Caddy + oauth2-proxy walkthrough in the Multi-User Mode
wiki page (web tabs and HTML view bypass the sign-in and never get the secret; the proxy
removes its own session cookie; hook endpoints and their /api/v1 aliases are blocked;
optional username from an IdP claim; what the secret does not protect against).
Changeset included.
This commit is contained in:
13768039+zomby1 committed 2026-11-24 21:41:53 +01:00
1 parent 5548c17c4a
commit 8480bba908
19 files changed
+2024 -16

No files matched your search

+6
View File
@@ -50,6 +50,12 @@ export interface UsersFile {
export interface AuthUser {
username: string;
role: UserRole;
/**
* True when a trusted reverse proxy vouched for this request (see
* src/config/trusted-proxy.ts), so no Codeman password was involved. Absent for
* cookie, Basic and QR sign-ins.
*/
viaTrustedProxy?: boolean;
}
/** Admin-facing projection of a user: never carries the password hash. */