ProxyAuth / Security

oidc: on a vhost, completely — the full mechanism, step by step

ProxyAuthSecurity / OIDCUpdated on 2026-09-18

Setting oidc: on a vhost changes who decides whether a visitor is allowed in: from ProxyAuth to the backend behind it, communicated through a signed, independently verifiable token rather than headers or a cookie only ProxyAuth understands. This is the mechanism, end to end.

Use it for applications that already have their own user model and native OIDC support — Grafana, Nextcloud, GitLab — where you want them to keep managing sessions and permissions.

What steps aside

On an OIDC vhost, ProxyAuth’s own enforcement stands down entirely:

  • required_login session enforcement;
  • CSRF validation and injection;
  • the decision to strip an incoming Authorization header;
  • route-level username, groups and roles.

The last one matters most. A route still carrying a groups: restriction from before it went OIDC would reject the very session the flow just established. Likewise, CSRF would reject the backend’s own state-changing calls, which never carried a ProxyAuth token.

The global /auth and /logout also proxy straight through. A relying party like Grafana has its own login and logout UI, and that is what visitors reach.

What still applies: vhost login authorization. allow_users, allow_groups, allow_roles and exclude_users are evaluated at login inside /oidc/authorize.

The six endpoints

Intercepted ahead of normal routing:

GET        /.well-known/openid-configuration   discovery
GET        /oidc/jwks.json                     public signing key
GET, POST  /oidc/authorize                     login step + its submission
POST       /oidc/token                         code → tokens (server to server)
GET        /oidc/userinfo                      claims
GET        /oidc/end-session                   RP-initiated logout

Everything lives under /oidc/ so it never collides with the backend’s own routes, except discovery, which RFC 8414 fixes at the root. Every other path proxies through untouched.

Configuration

vhosts:
  - vhost: ["grafana.example.com"]
    vhost_cert:
      cert: "/etc/proxyauth/cert/grafana.example.com/fullchain.pem"
      key: "/etc/proxyauth/cert/grafana.example.com/privkey.pem"
    certbot_renew: true
    allow_groups: ["staff"]
    oidc:
      client_id: "grafana"
      client_secret_hash: "$argon2id$v=19$m=19456,t=2,p=1$..."
      redirect_uris:
        - "https://grafana.example.com/login/generic_oauth"
      logout_redirect_uris:
        - "https://grafana.example.com/login"
      scopes: ["openid", "profile", "email"]
      login_page: "/etc/proxyauth/pages/login.html"
    routes:
      - prefix: "/"
        target: "http://127.0.0.1:3000"
        # no required_login: the backend decides

An OIDC issuer must be https, so tls must be on. One oidc: block registers exactly one relying party — the same one-vhost-one-backend model used everywhere else.

  • client_id — public; appears as aud in the id_token.
  • client_secret_hash — Argon2id, verified like a password, never stored or compared as plaintext.
  • redirect_uris — exact match only, byte for byte. No prefix, no wildcard. This is the defence against open redirects through authorization codes.
  • logout_redirect_uris — same discipline for logout; the first entry is also the fallback destination.
  • scopes — what the client may request. openid is always implicitly required. Default ["openid","profile","email"].
  • login_page — optional custom login HTML.

Generating client_secret_hash

Pick a long random secret — it is an API key, not something a human types — and hash it with Argon2id. There is no dedicated CLI command yet; a few lines with the argon2 crate do it:

use argon2::password_hash::{PasswordHasher, SaltString, rand_core::OsRng};
use argon2::Argon2;

let secret = "grafana-super-secret-value"; // goes into grafana.ini
let salt = SaltString::generate(&mut OsRng);
let hash = Argon2::default()
    .hash_password(secret.as_bytes(), &salt)
    .unwrap()
    .to_string();
println!("{hash}"); // goes into routes.yml

The signing key

Generated once, externally, before starting with oidc: anywhere:

openssl genrsa -traditional -out /etc/proxyauth/oidc/signing_key.pem 2048
chmod 600 /etc/proxyauth/oidc/signing_key.pem
chown proxyauth /etc/proxyauth/oidc/signing_key.pem

ProxyAuth only reads this file. Missing, or with permissions other than exactly 600, and it refuses to start with a message repeating these commands. -traditional matters: it expects PKCS#1 (BEGIN RSA PRIVATE KEY), not PKCS#8. The modulus and exponent for the JWKS are read by a small purpose-built DER reader, verified against real openssl keys, rather than a general-purpose RSA crate.

Every OIDC vhost on an instance currently shares this key. There is no per-vhost key or rotation with overlapping keys yet.

Step 1 — /oidc/authorize

The relying party sends the browser here with response_type=code, client_id, redirect_uri, scope, state, nonce, code_challenge and code_challenge_method=S256.

client_id and redirect_uri are validated first and independently. An invalid one produces an error page directly — never a redirect, because redirecting on the basis of an unvalidated URI is exactly what an open-redirect attack needs.

Then:

  • a valid ProxyAuth session exists → a code is issued immediately;
  • otherwise → the login form is rendered right here, and its POST comes back to /oidc/authorize with the original query preserved.

Credentials are verified against the same account store as everywhere else, with the same TOTP rules. The login step happens once per session; a returning visitor goes straight to the redirect with a code.

PKCE, mandatory

S256 only, plain never accepted, no confidential-client exemption:

fn verify_pkce(code_verifier: &str, code_challenge: &str) -> bool {
    let hash = Sha256::digest(code_verifier.as_bytes());
    let computed = base64url_encode(&hash);
    computed.as_bytes().ct_eq(code_challenge.as_bytes()).into()
}

It proves that whoever redeems the code started the flow. An intercepted code — from history, a referrer, a compromised hop — is useless without the verifier that was never sent anywhere.

Codes: single-use, atomic, 120 seconds

Codes live in LMDB and are validated and consumed in one read-write transaction, so two concurrent redemptions cannot both succeed — the same fix applied to password-reset tokens after a real race was found there. They live 120 seconds: enough for the redirect and the exchange, nothing else.

The code is consumed before PKCE is checked. A wrong verifier burns it. That is deliberate: a code that could be retried after a failed PKCE check would not really be single-use.

Step 2 — /oidc/token, five checks in order

Called server to server with client_secret_basic or client_secret_post:

  1. Client authentication — before the code is even looked at, so a wrong secret never reveals whether the code was valid.
  2. Code — atomic, single-use.
  3. client_id match with the code’s stored client.
  4. redirect_uri match, byte for byte with what /oidc/authorize received (RFC 6749 §4.1.3).
  5. PKCE — SHA-256 of code_verifier, constant-time comparison.

Only then is anything signed:

{ "access_token": "...", "token_type": "Bearer", "expires_in": 3600, "id_token": "..." }

Two tokens, two shapes

id_token:      iss, sub, aud, exp, iat, nonce
access_token:  iss, sub, scope, exp, iat

Both are RS256 JWTs valid for one hour. The id_token is verified by the relying party’s own library against /oidc/jwks.json, checking aud against its client_id. The access_token omits aud because it is only ever verified by ProxyAuth’s /oidc/userinfo — which also checks iss against the vhost the request arrived on, since all OIDC vhosts share a signing key.

/oidc/userinfo

Bearer only, no cookie fallback. sub always; email and email_verified only with the email scope; name only with profile. Requesting profile alone never leaks an email address.

Discovery and JWKS are public

Both always answer Access-Control-Allow-Origin: *, including on OPTIONS, and cors_origins never applies to them: any client library from any origin needs them to configure itself. Discovery advertises RS256 only and code_challenge_methods_supported: ["S256"].

Logout

GET /oidc/end-session?post_logout_redirect_uri=https://grafana.example.com/login&state=abc123

The ProxyAuth session cookie is cleared unconditionally. Then:

  • URI present and on the exact-match list → redirect, state echoed;
  • URI absent → redirect to the first logout_redirect_uris entry;
  • URI present but unknown → a plain confirmation page, no guessing.

id_token_hint is deliberately not accepted: it is the relying party’s token, with no reliable mapping back to a ProxyAuth session. The cookie is cleared either way.

Custom login page

<!DOCTYPE html>
<html><body>
  <img src="/logo.svg" alt="">
  {{ form }}
</body></html>

{{ form }} is a complete form: submit target, CSRF field if enabled, username, password, TOTP if required, button. For a hand-built form, {{ auth_action }} gives the submit target and {{ form_totp }} the TOTP input alone (empty when TOTP is off). The general tags ({{ csrf_token }}, …) are available too. If the file cannot be read, the built-in form is used and the error logged.

Grafana, complete

[auth.generic_oauth]
enabled = true
name = ProxyAuth
client_id = grafana
client_secret = grafana-super-secret-value
scopes = openid profile email
auth_url = https://grafana.example.com/oidc/authorize
token_url = https://grafana.example.com/oidc/token
api_url = https://grafana.example.com/oidc/userinfo
redirect_uri = https://grafana.example.com/login/generic_oauth
allow_sign_up = true
signout_redirect_url = https://grafana.example.com/oidc/end-session

allow_sign_up = true matters on the first login of each account; without it Grafana refuses to create a local user it has never seen, even after a successful handshake.

Verify before clicking anything:

curl https://grafana.example.com/.well-known/openid-configuration
curl https://grafana.example.com/oidc/jwks.json

Known limits

  • One signing key shared by all OIDC vhosts, no rotation yet.
  • No dedicated CLI to hash a client secret.
  • The OIDC key is not covered by sync group boundaries.

Validate before redirecting, require PKCE, burn the code on first touch, sign only after five checks agree — and let the backend own everything after that. The standard flow, in the order that makes each step mean something.