Menu ▾ ▴

#128 feat(auth): add OIDC single sign-on for the admin UI

closed
nobody
None
2026-10-26
2026-10-17
Anonymous
No

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 --check and
    cargo clippy --locked --all-targets --all-features -- -D warnings are clean.
  • cargo test --locked --all-features --no-fail-fast: everything passes except
    the three pre-existing tests/cli/commands/export.rs cases that need the
    util-linux script tool. They are unrelated and fail identically on main.
  • 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:docs passes, 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-eslint crashes 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.md when 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

Related

Tickets: #121
Tickets: #127

Discussion

  • Anonymous

    Anonymous - 2026-10-17

    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 version 0014 is already taken by the secret rotation
    PR [#122], and 0015-0017 by the audit-log PRs [#123]-#126. Two migrations with
    the 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 PR
    merges after that stack) and app/migrations/README.md now lists it.

    2. The pending sign-in is now bound to its browser. The state was
    single-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/start now sets a short-lived dopbase_sso_state cookie
    (SameSite=Lax — deliberate, since the provider callback is a cross-site
    top-level navigation) and the callback refuses a state that does not match
    it, audited as state_unbound. The check runs before any database work, so an
    unbound 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_browser covers missing, wrong, and
    correct binding values.

    3. Race in the single-use state. consume_login_flow did SELECT then
    DELETE 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 single DELETE ... RETURNING statement.

    4. Small cleanups. The browser session cookie's Max-Age is derived from
    BROWSER_SESSION_ABSOLUTE_HOURS instead of a duplicated 86400 literal, and
    the clippy::redundant_closure warning in oidc.rs is fixed, so
    cargo clippy -- -D warnings is clean again.

    5. Verification filled in. The environment does have bun, so the UI tests
    were run: bun run test:ui passes 216/216 (including the new SSO button
    controller tests), bun run test:docs passes, prettier is clean, and the full
    cargo suite passes except the three pre-existing commands::export::* cases
    that need util-linux script (they fail identically on main). eslint is
    broken in this environment (typescript-eslint crashes before linting
    anything, including untouched files), so lint:ui could not be run anywhere,
    not just on this PR. The PR body's verification section now reflects all of
    this.

     

    Related

    Tickets: #122
    Tickets: #123

  • Anonymous

    Anonymous - 2026-10-26

    Ticket changed by: dopbase

    • status: open --> closed
     

Log in to post a comment.