Repository navigation
Conversation
…e (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.
|
Thanks for this, and for working through the whole #846 list. The PR lets multi-user mode sign people in through an authenticating reverse proxy on the same host, off by default and experimental. I ran your Caddy example with Caddy 2.11.9 against a real server, with a stub in place of oauth2-proxy. I tried a forged Needed before merge:
Please include these in the same push:
Nits:
One question from #846 is still open, and this review does not settle it: whether a dead capability under Items 1 and 2 have to be in before this can merge. |
Under CODEMAN_BASE_URL the server strips the mount prefix only in its literal spelling, so /CODEMAN/webview/x, /%63odeman/webview/x, //codeman/webview/x or /x/../codeman/webview/x reached the credential checks with the prefix still in front. A proxy's path matcher lets those through without its sign-in, so they got a Basic challenge and filled the per-IP failure bucket. capabilityPrefixOf() now takes the base path and, after its normalisation, removes the lower-cased base path once when the path starts with it. The exemptions are unchanged. The secret file's real path is now resolved once, when the secret is read, instead of on every sensitive-path check. Tests for behaviour that had none: the last-login throttle for proxy sign-ins, the 503 for an unreadable user store with a valid cookie or Basic credentials, removal of X-Codeman-User when another username header is configured, the normal challenge on capability paths with the feature off, the secret file reached through a symlink, and the reserved username header names.
…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.
The server strips the literal mount prefix before the auth hook runs, so under a base path named /webview, /html-view or starting with one of them, /webview/webview/x arrives as /webview/x. Removing the base path again in capabilityPrefixOf() then took the capability prefix itself, and such paths reached the Basic check and its failure count. The normalised path is now judged as it is first, and only when that is no capability path, once more with the base path removed once. Either match counts, so this can only add refusals, never an exemption.
Background requests from an open page followed the redirect to the sign-in start, and each one replaced oauth2-proxy's CSRF cookie, so a real sign-in could end on its CSRF error page. The example now answers them with 401 and uses one CSRF cookie per sign-in.
Under a dead web-tab capability, GET /webview/<cap> without the trailing slash and a WebSocket upgrade have no route status to copy (the route alone redirects, or accepts and closes with 4003). With trusted-proxy sign-in on, the hook answers both with 403, no challenge and no count. The refusal test sends each of them more often than the per-IP failure limit, before its final Basic sign-in, so a counted one turns that sign-in into a 429.
…copy A WebSocket upgrade and GET /webview/<cap> without the trailing slash get the hook's 403 under a dead web-tab capability. Say so in section 10a, next to the statuses.
The rule answers a request with a non-navigation Sec-Fetch-Mode with 401. A client that sends no such header is redirected as before, and a WebSocket handshake never followed the redirect.
|
Thanks for the review, and for running the example. All of it is in the new commits. 1. Base path. One case beyond your list: a mount that is itself named 2. Tests. One for each of your six. I checked each the way you did: reverted the behaviour, saw the test fail, restored it.
3. Claims. The walkthrough says the app registration is single-tenant and that 4. 5. Nits. The real path is resolved once in From your note on #846. The sentence for the two requests is in §10a, next to the statuses. The capability test asserts both: an upgrade request under a dead capability gets the 403, and
One more fix in the walkthrough, which I found while using it. The signed-in route of the Caddy example redirected every request without a proxy session to Not in this PR: once the session has ended, the open page ends up showing "No connection to the Codeman server" until the person reloads it. The walkthrough says so. I'd like to send a small frontend follow-up that detects the proxy's 401 and offers to sign in again, if you agree. |
|
Thanks for the second round, and for checking each new test by reverting its behaviour first. This PR lets multi-user mode sign people in through an authenticating reverse proxy on the same host. It is off by default and experimental. Both blocking items are in. Your five base-path spellings and the mount named There are two small things I will apply at merge time, so there is nothing for you to push:
You asked about a frontend follow-up that detects the proxy's 401 and offers to sign in again. That is a separate decision. It is still open, and this review does not answer it. Once the unit test job is green, the next step is to merge with those two changes. |
Closes #846
Problem
Multi-user mode only accepts Codeman passwords over HTTP Basic, so a team with an identity provider signs in twice and the two identities are not linked.
Change
With a shared secret configured (
CODEMAN_TRUSTED_PROXY_SECRET_FILEorCODEMAN_TRUSTED_PROXY_SECRET), an authenticating reverse proxy on the same host sendsX-Codeman-Proxy-SecretandX-Codeman-User, and the request signs in as that existing, enabled account. Off by default, multi-user mode only, and labelled experimental indocs/versioning-policy.md.src/config/trusted-proxy.ts(new): loads and validates the settings once, removes both secret variables fromprocess.env, reads and removes the two headers.src/web/middleware/auth.ts:checkTrustedProxyIdentityruns before the cookie check: loopback only,timingSafeEqualon equal lengths, fails closed, its own failure bucket, no cookie. The loopback test isisLoopbackIp(), now shared withcheckHookSecretBypass();normalizeUsername()andisValidUsername()and nothing else. A missing, invalid, unknown or disabled one gets a plain 403;serveRefusedCapabilityPath: with the feature on, a/webview/or/html-view/request without a live capability is answered by the hook before any credential is evaluated or counted.src/web/server.ts: a configured setup that cannot be used stops the start, like the first boot without users.src/web/routes/me-routes.ts:GET /api/meaddsviaTrustedProxyand reportsmustChangePassword: falsefor proxy sign-ins.src/web/webview-proxy.ts,src/web/sensitive-path.ts: both default header names and the configured one are on the relay's drop list; the secret file is refused by downloads and attachments.docs/security-architecture.md§10a,docs/versioning-policy.md,docs/architecture-invariants.md,docs/multi-user-plan.md,docs/web-tabs.md,CLAUDE.md, the wiki settings reference, and a Caddy + oauth2-proxy walkthrough in the multi-user wiki page.Your checklist from #846
CODEMAN_TRUSTED_PROXY_USER_HEADER. The message never contains the secret.alice, bob) is refused, also when both accounts exist. With a valid proxy identity thecodeman_sessioncookie is ignored and not refreshed.X-…header orRemote-User, with reserved names refused.X-Codeman-Useris removed whichever name is configured./proc/<pid>/environ, and any session running as Codeman's OS account can read the secret and sign in as anyone over loopback.lastLoginAt. An in-memory throttle (15 minutes per user) sits in front oftouchLastLogin().Behaviour with the feature off
proxy-secretin the data dir.Tests
test/trusted-proxy-auth.test.ts(92 tests) andtest/sensitive-path.test.ts: configuration and each start-up refusal, header stripping, sign-in and refusal paths, the username rule, source address, rate limiting, capability paths, the relay drop list, WebSocket upgrade and owner scoping.npm run typecheck,lint,format:check,check:frontend-syntax,check:frontend-dead,check:public-assets,check:browser-excludes,check:lockfile,check:plugin: pass.npm test: all 17,408 tests pass (764 files, 13 skipped).Manual test
Running on my own install behind Caddy + oauth2-proxy. The app, API, SSE, terminal and web tabs work for the signed-in account. Forged identity headers are ignored, unknown accounts are refused, no session inherits the secret, and a trusted web tab no longer receives the proxy's session cookie.
Follow-ups, not in this PR
buildUpstreamRequestHeaders()and the WebSocket leg'sfilterCookieHeader()call.