From 4cf40644c9e647d98f2a0557f0aed93386dd73a7 Mon Sep 17 00:00:00 2001 From: Ilker Manap Date: Sun, 4 Oct 2026 16:36:15 +0200 Subject: [PATCH] Single sign-on through OpenID Connect: accounts, staff roles and memberships from the provider Co-Authored-By: Claude Opus 5.5 (1M context) --- CHANGELOG.md | 7 + docs/install.md | 38 +++ docs/reference.md | 99 ++++++++ go.mod | 5 +- go.sum | 6 + internal/config/config.go | 6 + internal/config/engines_test.go | 18 ++ internal/config/oidc.go | 88 +++++++ internal/docgen/reference_gen.go | 14 ++ internal/docgen/render.go | 1 + internal/router/handlers.go | 5 + internal/router/router.go | 3 + internal/web/account.go | 29 ++- internal/web/oidc.go | 366 ++++++++++++++++++++++++++++ internal/web/oidc_test.go | 171 +++++++++++++ internal/web/templates/account.html | 1 + 16 files changed, 853 insertions(+), 4 deletions(-) create mode 100644 internal/config/oidc.go create mode 100644 internal/web/oidc.go create mode 100644 internal/web/oidc_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index f7df86d..8246872 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,13 @@ APIs change between minors without a deprecation period. administration page and changes nothing, `operator` also runs the cluster from them, `billing` sees usage and quotas. Set with `llmgw users role` or the console's **Staff role…**. +- **Single sign-on through OpenID Connect** (`auth.oidc`). A "Sign in + with …" button sends people to the identity provider and back, with PKCE, + state and nonce. The ID token is verified, and the account is found by + the verified email address, or made when `create_accounts` is on. Groups + give staff roles (`roles`, set at every sign-in) and places in the tree + (`memberships`). `no_passwords` leaves the provider as the only way in, + except for administrators. ### Guardrails diff --git a/docs/install.md b/docs/install.md index 64aa014..93190ec 100644 --- a/docs/install.md +++ b/docs/install.md @@ -1080,6 +1080,44 @@ thing to get right is the health check: point it at `/ready`, not `/health`. so a load balancer using it would send half the traffic to something that refuses every request. +## Single sign-on + +People can sign in through your identity provider — Keycloak, Entra ID, +Google, Okta, Authentik, anything that speaks OpenID Connect. + +1. Register a client there with the redirect address + `https:///login/oidc/callback`. +2. Put its secret in a file only root reads. +3. Add to `server.yaml`: + +```yaml +auth: + oidc: + issuer: https://login.example.com/realms/acme + client_id: llmgw + client_secret_file: /etc/llmgw/secrets/oidc-client-secret + label: Acme SSO # the button says "Sign in with Acme SSO" + create_accounts: true # make an active account for someone new + roles: # staff roles from groups, set at each sign-in + admin: [llmgw-admins] + operator: [llmgw-ops] + memberships: # groups to places in the tree, joined at sign-in + ml-engineers: "team:Acme/ml" + no_passwords: true # the provider only; administrators keep a password way in +``` + +How the sign-in works: + +- **Request:** it uses PKCE, a state and a nonce. +- **Identity:** the ID token is verified against the provider's keys, and + the account is found by the verified email address. +- **Unknown addresses:** without `create_accounts`, only people who already + have an account can sign in. +- **Roles:** a person taken out of a group loses the role the next time + they sign in. +- **Memberships:** they are added, never taken away. +- **Audit:** each sign-in is recorded in the audit log. + ## The firewall `server init`, `node add`, `server add` and `mirror init` each keep that diff --git a/docs/reference.md b/docs/reference.md index 337a519..4eb3ba3 100644 --- a/docs/reference.md +++ b/docs/reference.md @@ -33,6 +33,7 @@ rather than repeated. | `default_rpm` | `int` | [Auth](#auth) | | `default_tpm` | `int` | [Auth](#auth) | | `signup_open` | `bool` | [Auth](#auth) | +| `oidc` | `OIDC` | [Auth](#auth) | | `personal` | `Personal` | [Auth](#auth) | | `pricing` | `map[string]Price` | [Auth](#auth) | | `default_price` | `Price` | [Auth](#auth) | @@ -106,6 +107,17 @@ rather than repeated. | `prometheus` | `string` | [Monitoring](#monitoring) | | `window` | `time.Duration` | [Monitoring](#monitoring) | | `timeout` | `time.Duration` | [Monitoring](#monitoring) | +| `issuer` | `string` | [OIDC](#oidc) | +| `client_id` | `string` | [OIDC](#oidc) | +| `client_secret_file` | `string` | [OIDC](#oidc) | +| `redirect_url` | `string` | [OIDC](#oidc) | +| `label` | `string` | [OIDC](#oidc) | +| `scopes` | `[]string` | [OIDC](#oidc) | +| `groups_claim` | `string` | [OIDC](#oidc) | +| `create_accounts` | `bool` | [OIDC](#oidc) | +| `roles` | `map[string][]string` | [OIDC](#oidc) | +| `memberships` | `map[string]string` | [OIDC](#oidc) | +| `no_passwords` | `bool` | [OIDC](#oidc) | | `nvidia_smi` | `string` | [Options](#options) | | `ib_root` | `string` | [Options](#options) | | `prefer_nvml` | `bool` | [Options](#options) | @@ -413,6 +425,14 @@ SignupOpen serves the signup form. Accounts it creates are pending until an operator approves them, so this is not a way in — but turning it off means accounts are made with `llmgw users create` instead. +### `oidc` + +`OIDC` + +OIDC is sign-in through an identity provider. + +Takes a [OIDC](#oidc) block. + ### `personal` `Personal` @@ -959,6 +979,85 @@ Window is how far back the charts look. Zero takes an hour. Timeout bounds one query. It runs while somebody waits for a page, so a monitoring system that is slow today is skipped rather than waited for. +## OIDC + +### `issuer` + +`string` + +Issuer is the provider's address; its /.well-known/openid-configuration +says the rest. + +### `client_id` + +`string` + +ClientID and the file holding its secret, as registered with the +provider. + +### `client_secret_file` + +`string` + +### `redirect_url` + +`string` + +RedirectURL is where the provider sends people back: +https:///login/oidc/callback. Empty works it out from the +request, which is right unless a proxy changes the address. + +### `label` + +`string` + +Label is what the sign-in button says: "Sign in with