ProxyAuth / Security

/auth, end to end: everything that touches ProxyAuth's own login

ProxyAuthSecurity / AuthenticationUpdated on 2026-09-18

Every vhost that does not delegate identity through oidc: authenticates the same way: POST /auth. From outside it is one endpoint. Inside, a surprising number of independent settings converge on that one request. This post follows it from the login form to the logout.

One setting decides the shape: session_cookie

A browser and a script want incompatible things from a login, and session_cookie — global, or per vhost — is how you say which one a vhost serves.

session_cookie: truesession_cookie: false
typical callera browser submitting a formcurl, CI, a mobile app
/auth answers303 to login_redirect_url + session_token cookie200 with {"token", "expires_at"}
carried afterwardsthe browser resends the cookieAuthorization: Bearer <token>
CSRFappliesdoes not apply — set csrf_token: false
lifetimemax_age_session_cookie, capped at token_expiry_secondstoken_expiry_seconds, returned as expires_at

Only a browser can be sent a redirect and be trusted to follow it. A fetch or curl call would either ignore the 303 or follow it and lose what mattered, which is why the API form returns data instead.

The cookie always carries Secure, HttpOnly and SameSite=Strict, and it can never outlive the token inside it.

The login page is yours

A browser login is a static HTML file you write, served by a normal route, posting to /auth:

routes:
  - prefix: "/"
    static: "/var/www/login/"
    static_index: "login.html"
    tag_proxyauth: true
    cache: false
<form method="POST" action="/auth">
  <input type="hidden" name="csrf_token" value="{{ csrf_token }}">
  <input type="text" name="username" autocomplete="username">
  <input type="password" name="password" autocomplete="current-password">
  <button type="submit">Sign in</button>
</form>

tag_proxyauth: true is what fills {{ csrf_token }}. Without it the tag stays literal, and every submission is rejected. cache: false sends no-store, because the token is generated per visitor. When login_via_otp is on for the vhost, the same form also carries the TOTP code — the whole login is still one POST.

What a login must satisfy

A request to /auth has to clear every one of these before a session exists:

  1. Rate limit. ratelimit_auth applies to /auth independently of proxied traffic. Off by default (requests_per_second: 0). Over the burst, the client is held for block_delay ms and receives a 429 — and the correct password is refused too while the limiter is engaged, so guessing right does not bypass it.
  2. CSRF, when session cookies and CSRF are both on for the vhost.
  3. Credentials. Passwords are Argon2id hashes, verified in constant time.
  4. Per-account IP allow-list. An account with allow set is refused from any other address, even with the right password.
  5. Vhost login authorization. allow_users, allow_groups, allow_roles combined as an OR, with exclude_users overriding all of them. All three empty means no login succeeds on this vhost.
  6. TOTP, when login_via_otp is on for the vhost.
  7. must_change_password. A flagged account gets the reset page instead of a session: a redirect in cookie mode, {"must_change_password", "reset_link"} in JSON mode.

Only then is a token signed and returned.

Per vhost, everything above can differ

vhosts:
  - vhost: ["internal.example.com"]
    allow_groups: ["staff"]
    exclude_users: ["contractor-temp"]
    session_cookie: true
    tag_csrf_token: true
    login_via_otp: true
    max_age_session_cookie: 1800
    login_redirect_url: "/app"
    logout_redirect_url: "/"
    cors_origins: ["https://internal.example.com"]

login_redirect_url is where a fresh login lands and where an already-authenticated visitor is sent instead of the form. logout_redirect_url is where /logout goes, and also resolves which page gets the login error block filled in.

CORS on /auth

cors_origins lists the origins allowed to make credentialed cross-origin calls to /auth, /logout and /adm/auth/totp/get. null (the default) disables cross-origin access entirely. A same-origin request is never blocked by this list — including a POST where the browser adds an Origin header matching the page — because the comparison is against the scheme and host the request actually arrived on. /auth answers the OPTIONS preflight against this list.

What the backend gets

On a route with required_login, the backend receives X-User, X-User-Roles and X-User-Groups. It never sees the password and never sees the token. Client-supplied copies of those headers are stripped, so they cannot be forged by the caller.

Logout revokes, it does not only forget

GET /logout

Authenticated by the session_token cookie alone. A missing or expired cookie is not an error. ProxyAuth then:

  1. adds the token to the same revocation set /adm/revoke writes to;
  2. clears the cookie by resending it expired at the Unix epoch;
  3. redirects to the vhost’s logout_redirect_url, or the global one, or answers 200 if neither is set.

Step 1 is the important one. Clearing a cookie only asks the browser to forget. A copy taken earlier — through XSS, a shared machine, an exposed log — would otherwise keep working until natural expiry. Because every verification checks the revocation set, it stops immediately.

Bearer clients have no cookie to clear; to kill a token early, call POST /adm/revoke with its ID. And without redis, revocation is local to the node that performed it.

TOTP enrollment guards itself

POST /adm/auth/totp/get takes a username and password (not the admin token) and returns a TOTP secret — once. If the account already has a secret, it answers 409, even with the correct password. Re-disclosing an enrolled secret to anyone holding the password would collapse two factors into one.

allow_totp_reenroll: true on a vhost is the explicit, scoped opt-out: there, valid credentials are enough to replace the secret in one call. That makes the second factor a guard against a lost phone rather than against a stolen password — a trade-off to choose per vhost, never globally. Elsewhere, proxyauth reset-otp --username U or POST /adm/auth/totp/reset is the admin path.

A bug worth recording: this guard once read the account’s otpkey from the startup snapshot instead of through the overlay-aware resolver every other check uses. Any enrollment made after startup was invisible to it, so allow_totp_reenroll was never consulted and the call quietly handed back the existing secret with a 200. Routing the guard through the same resolver as login validation fixed it. It is the kind of bug that only shows up when a value is traced from where it is written to where it is read.

The API flow, for completeness

TOKEN=$(curl -s -X POST https://api.example.com/auth \
  -d 'username=ci-runner&password=...' | jq -r .token)

curl https://api.example.com/v1/builds -H "Authorization: Bearer $TOKEN"

No login page, no cookie, no CSRF. Refresh before expires_at.

On an OIDC vhost, none of this applies

Where oidc: is set, /auth and /logout proxy straight to the backend like any other path. Login happens at /oidc/authorize, logout at /oidc/end-session. The OIDC post covers that flow.

One endpoint, two shapes chosen by one setting, seven conditions before a token exists, and a logout that revokes rather than forgets. Most of it never needs touching; knowing it is there makes the exceptions easy to reason about.