#128 feat(auth): add OIDC single sign-on for the admin UI
Originally created by: bosd
Summary
Add human single sign-on to the Admin UI (issue [#121]), built on the shared OIDC
trust core from [#127]. An optional [oidc.login] block enables the OpenID
Connect authorization code flow with PKCE against a trusted issuer, so
operators can sign in with an existing identity provider.
Scope is login, claim-to-role mapping, and audit only. Accounts stay
administrator-provisioned: the first sign-in links a provider identity to an
existing account matched by verified email, later sign-ins use the stored
issuer and subject, and the configured group mapping sets the account role
(admin or member, never root). An unknown email, an unmapped group, and
an unverified email are refused. Local password login stays enabled, so
administrators can still reach the instance when the provider is unavailable.
dopbase run workload login (#31) will reuse the same core later.
The group-to-role mapping targets today's admin and member roles. When the
0.2.0 RBAC lands, [oidc.login.roles] can map groups to its roles instead; the
linking, verification, and audit parts do not depend on the role model.
A pending sign-in is bound to the browser that started it: /auth/oidc/start
sets a short-lived dopbase_sso_state cookie that the callback must present
alongside the provider's state, so a completed callback URL replayed into
another browser is refused (state_unbound in the audit log). The check runs
before any database work, so an unbound callback can neither consume the flow
nor probe state values, and every callback response clears the cookie. A flow
is consumed with a single DELETE ... RETURNING statement, so two racing
callbacks cannot both use the same state.
Stacked on [#127] (feat/oidc-trust): this branch is based on that one, so the
diff also contains its commit until [#127] merges. Review [#127] first.
Compatibility
No breaking changes. [oidc].issuers keeps its shape and [oidc.login] is a
new, optional table; startup validates it and rejects an issuer that is not
trusted, an empty role map, a role other than admin/member, and a missing
secret for client-secret auth. Migration 20261017133051_oidc_login adds the
oidc_identities and oidc_login_flows tables, and factory reset clears both.
A sign-in only changes the stored role of an account
whose provider group maps to a different one, and it never changes the
protected root account.
Verification
cargo fmt --checkand
cargo clippy --locked --all-targets --all-features -- -D warningsare clean.cargo test --locked --all-features --no-fail-fast: everything passes except
the three pre-existingtests/cli/commands/export.rscases that need the
util-linuxscripttool. They are unrelated and fail identically onmain.- New
app/tests/oidc_sso.rs(16 tests) drives the real router against a mock
provider (discovery, JWKS, and token endpoint) and covers first-sign-in
linking, role mapping, repeat sign-in by stored subject, unknown email,
unmapped group, unverified email, unknown and replayed state, a callback
replayed into another browser without or with a wrong binding cookie,
provider error, exchange failure, wrong nonce, an ignored external redirect,
and that no provider tokens are persisted. bun run test:ui: 216 tests in 31 files pass, including the new SSO button
controller tests.bun run test:docspasses, and prettier is clean on every
changed Markdown, TypeScript, and Vue file.- Not run here:
bun run lint:ui/eslint fails in this environment before
linting anything (typescript-eslintcrashes on every file, including ones
this PR does not touch).
Demo
Not needed: yet. I am deploying this branch against a Rauthy instance and will
replace this with a recording of the sign-in flow once that test is done.
Checklist
- [x] I kept this pull request focused on one problem.
- [x] I added or updated tests for behavior changes, or explained why tests are not needed.
- [x] I updated the documentation and
CHANGELOG.mdwhen public behavior changed, or explained why they are not needed. - [x] I added a screenshot or video demo for a feature or improvement, or explained why one is not needed.
- [x] I updated relevant documentation inside
/docs
Originally posted by: bosd
Reviewed and improved in
f40b297. What changed:1. Migration number collision (would break at merge). The branch added
0014_oidc_login, but version0014is already taken by the secret rotationPR [#122], and
0015-0017by the audit-log PRs [#123]-#126. Two migrations withthe same version fail to apply, so whichever PR merged second would break. The
migration is renumbered to
0018_oidc_login(next free version, so this PRmerges after that stack) and
app/migrations/README.mdnow lists it.2. The pending sign-in is now bound to its browser. The
statewassingle-use but not browser-bound, so a completed callback URL replayed into a
different browser would mint a session for the attacker's account there (login
CSRF).
/auth/oidc/startnow sets a short-liveddopbase_sso_statecookie(
SameSite=Lax— deliberate, since the provider callback is a cross-sitetop-level navigation) and the callback refuses a
statethat does not matchit, audited as
state_unbound. The check runs before any database work, so anunbound callback can neither consume the flow nor probe which states exist, and
every callback response clears the cookie. New test
the_pending_sign_in_is_bound_to_its_browsercovers missing, wrong, andcorrect binding values.
3. Race in the single-use state.
consume_login_flowdid SELECT thenDELETE in a deferred transaction; in WAL mode two concurrent callbacks could
both read the flow before either deleted it, minting two sessions from one
state. It is now a singleDELETE ... RETURNINGstatement.4. Small cleanups. The browser session cookie's
Max-Ageis derived fromBROWSER_SESSION_ABSOLUTE_HOURSinstead of a duplicated86400literal, andthe
clippy::redundant_closurewarning inoidc.rsis fixed, socargo clippy -- -D warningsis clean again.5. Verification filled in. The environment does have bun, so the UI tests
were run:
bun run test:uipasses 216/216 (including the new SSO buttoncontroller tests),
bun run test:docspasses, prettier is clean, and the fullcargo suite passes except the three pre-existing
commands::export::*casesthat need util-linux
script(they fail identically onmain). eslint isbroken in this environment (
typescript-eslintcrashes before lintinganything, including untouched files), so
lint:uicould not be run anywhere,not just on this PR. The PR body's verification section now reflects all of
this.
Related
Tickets:
#122Tickets:
#123Ticket changed by: dopbase