feat: persistent sessions and OIDC sign-in (auth M2 + M3)

Sessions and users (M2)
- users and sessions tables in SQLite; only a digest of the session ID is stored
- idle 30 min / absolute 8 h deadlines, UPDATE-only touch, per-user revoke by generation
- emergency operator is a users row (issuer local:emergency); its sessions are
  bound to the operator hash fingerprint, so unsetting or rotating it ends them
- CSRF derived from the session ID; GET /api/v1/me

OIDC login (M3)
- openidconnect 4.1: authorization code + PKCE S256, static redirect URI, no redirects
- one-time login transactions bound to the browser by a Lax correlation cookie
- identity is (issuer, subject); admin only from configured subjects/groups;
  a signed-in user without a grant gets 403 on management APIs
- OIDC sessions are bound to the OIDC configuration fingerprint
- SSO button, no-access page and fixed error codes in the web UI
- tests against a mock IdP with signed and malformed tokens; rehearsed against
  Keycloak 26.1 in a real browser
- rsa 0.9 advisory (RUSTSEC-2023-0071) excepted with a written reason: runtime
  code only verifies signatures with public keys

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-14 13:43:09 +07:00
parent a9ebded5ba
commit 618681fa7f
23 changed files with 3695 additions and 139 deletions

View File

@@ -173,3 +173,43 @@ tessera legacy-import --bucket legacy-bucket --prefix billing/ --orbit-id ORBIT_
Repeat without `--inventory-only` to import. The JSON report includes the source key, ETag, size, last-modified timestamp, and Tessera snapshot ID. Conditional reads reject changed objects between listing and download. A persistent receipt prevents reimport after local retention and GC. [AWS S3 CLI inventory](https://docs.aws.amazon.com/cli/latest/reference/s3api/list-objects-v2.html), [AWS S3 conditional download](https://docs.aws.amazon.com/cli/latest/reference/s3api/get-object.html).
Add `--history /path/to/consistent-history.sqlite` to archive a consistent SQLite export of the old job history. Save the reported history ID and retrieve it with `tessera legacy-history HISTORY_UUID history.sqlite` on the vault host. Inspect the retrieved copy read-only. Legacy SQL archives retain their original bytes and can be applied to a temporary database with the matching engine client.
## OIDC sign-in (single issuer)
Set `TESSERA_OIDC_ISSUER` to enable browser SSO (authorization code + PKCE S256,
Tessera is a confidential client). When it is set, these are also required:
| Variable | Meaning |
| --- | --- |
| `TESSERA_OIDC_CLIENT_ID`, `TESSERA_OIDC_CLIENT_SECRET` | Client registered at the IdP. The secret is only read from the environment and never logged. |
| `TESSERA_OIDC_REDIRECT_URL` | Public, static callback, exactly `https://<hub>/api/v1/auth/oidc/callback`. It is never derived from `Host` or `X-Forwarded-*`. |
| `TESSERA_OIDC_ADMIN_SUBJECTS` | Comma-separated `sub` values that may administer the hub. |
| `TESSERA_OIDC_ADMIN_GROUPS` | Comma-separated group names that may administer the hub. |
| `TESSERA_OIDC_GROUPS_CLAIM` | ID-token claim that carries groups (default `groups`; string or array of strings). |
| `TESSERA_OIDC_CA_FILE` | Optional PEM bundle for an IdP behind a private CA. |
At least one admin subject or group is mandatory, otherwise startup fails: with
no mapping nobody could administer the hub. Issuer and redirect URL must be
`https://`; plain http is accepted only for a loopback host together with
`TESSERA_LOCAL_DEVELOPMENT=true`.
Behaviour to know about:
- Users are identified by `(issuer, subject)`, never by email or display name.
There is no auto-link by email and no first-user-becomes-admin.
- A user who signs in but matches no admin mapping gets a "No access yet" page and
`403` on every management API. They can still call `GET /api/v1/me` and sign out.
- Group membership is read at sign-in. A change at the IdP applies at the next
sign-in, at most 8 hours later (absolute session limit); there is no back-channel
logout or SCIM yet.
- Changing the issuer, client ID, admin subjects/groups or groups claim ends every
existing OIDC session. Rotating the client secret does not.
- Sign-out ends the Tessera session only. The IdP session stays, so the next
"Sign in with SSO" may not ask for a password. RP-initiated logout is not implemented.
- ID tokens must be signed with RS256 (the library default). An IdP that signs
with another algorithm is rejected until that is made configurable.
- The emergency operator password keeps working beside SSO and is shown under
"Emergency operator sign-in" when SSO is on.
- No IdP token is stored or sent to the browser; the browser only receives the
Tessera session cookie.