Menu ▾ ▴

#141 [Feature]: OIDC single sign-on and browser-approved CLI login

closed
nobody
2026-10-25
2026-10-25
Anonymous
No

Originally created by: thomijasir
Originally owned by: thomijasir

Feature Description

Let people sign in to the Admin UI through an external OpenID Connect provider, and let the CLI sign in by approving a code in the browser instead of typing a password in the terminal.

This issue covers [#121] (OIDC login for users) and [#30] (browser-based CLI login) as one design, because they depend on each other. Once an account can live without a password, the CLI needs a way to sign in that doesn't ask for one. [#31] (OIDC workload login for CI) is out of scope: runner tokens already cover machines.

Problem / Motivation

Dopbase only knows email and password today. Teams that already run an identity provider (Google Workspace, Entra ID, Okta, Keycloak, Authentik, Rauthy, Zitadel, Auth0, Cognito, Clerk, Supabase) want people to use it, and to stop managing a second set of passwords.

The CLI makes this harder. dopbase login asks for a password in the terminal, so an SSO-only account could never use the CLI, and confirming sensitive CLI actions such as --reveal also needs a password.

Proposed Solution

Two separate trust relationships

Browser --OIDC code + PKCE--> identity provider    (only the web UI talks to the provider)
Browser <-- Dopbase browser session --             (same session as a password login)
CLI --device flow--> Dopbase <--approve-- Browser session (password or SSO)

Dopbase is an OIDC client for the web UI only. It checks the ID token once and then issues its own session, exactly like a password login. It never stores the provider's access or refresh tokens.

For the CLI, Dopbase is its own authorization server, with a device flow modelled on RFC 8628. The CLI never talks to the provider. Any signed-in browser approves it, whether the session came from a password or from SSO. That's why browser login (#30) also works on servers without SSO.

Decisions

  • One provider in v1, configured by root in the Admin UI rather than in server.toml. Presets for Google, Microsoft Entra ID, Okta, Auth0, Amazon Cognito, Clerk, Supabase and Keycloak, plus a generic option. The schema leaves room for more providers later.
  • Admins still create accounts first. SSO signs in existing accounts only, and unknown emails are refused. There's no group-to-role mapping: roles stay in Dopbase.
  • The first sign-in links to an account only when the provider marks the email as verified. Later sign-ins match the provider's subject identifier, never the email again. Root is never linked by email; root links on purpose with a test sign-in.
  • Passwords become optional per account once SSO is on. Root can turn on "Require single sign-on", which refuses password sign-in for everyone except root, who keeps a break-glass password.
  • Root can hide the password form on the sign-in page. Passwords keep working in the CLI and the API.
  • SSO needs an HTTPS public URL (localhost excepted), because the provider sends sign-in codes back to it.

Web sign-in

  1. GET /api/v1/auth/sso/start creates a single-use flow (PKCE S256, state, nonce), sets a dopbase_sso cookie that binds the flow to this browser, and redirects to the provider.
  2. GET /api/v1/auth/sso/callback checks the binding cookie, consumes the flow with DELETE ... RETURNING, exchanges the code, and validates the ID token (issuer, audience, expiry, nonce, asymmetric algorithms only).
  3. The callback doesn't create the session. It redirects to /login/sso#code=... with a one-time handoff code in the URL fragment, which never reaches server logs. The page posts it to POST /api/v1/auth/sso/exchange, which issues the session through the same code path as password login. This blocks login CSRF and session fixation.

Confirming sensitive actions without a password

SSO users confirm in a popup with max_age=0 (plus prompt=login where the provider supports it). The server checks that auth_time is fresh and that the identity belongs to the current account. CLI users without a password confirm --reveal and similar actions through a device request with purpose=reauth, approved in the browser.

Browser CLI login (#30)

  • dopbase login --browser prints a link and an 8-character code (for example WDJB-MJHT) and waits. --browser-open also opens the link in this machine's browser, and --password forces the old prompt. On an SSO server, plain dopbase login uses the browser flow.
  • /cli/approve is a page of its own. It uses the browser's current session and shows which account it will sign in, with a button to switch accounts. With no session, it goes to the sign-in page and comes back to the code. Approving needs a recent confirmation (10 minutes) because it hands out a 90-day credential.
  • Codes expire after 10 minutes and work once. Polling honours slow_down, wrong codes are rate limited per session, and one client can have at most 20 requests waiting. Ctrl+C cancels the request.
  • A tab opened from the terminal has no CSRF token yet, so GET /api/v1/auth/session returns one for browser sessions. It's derived from the session's own token on the server, and both stay valid.

Data model (new timestamped migrations)

  • sso_providers: preset, display name, issuer, client ID, client secret encrypted with the master key, enabled, verified, require SSO, hide password form.
  • admin_identities: (issuer, subject) unique, one identity per account and provider, linked automatically or by hand.
  • sso_flows: pending sign-ins (state hash, nonce, PKCE verifier, binding hash, purpose, handoff hash, expiry).
  • cli_device_requests: hashed device and user codes, status, purpose, the target session for confirmations, client hostname and IP.

Accounts without a password store an empty hash that never verifies, instead of a nullable column. With sqlx 0.8, rebuilding the admins table would cascade-delete sessions.

Alternatives Considered

  • Configuring the provider in server.toml and mapping provider groups to roles, as proposed in [#121]. We keep roles in Dopbase and configure SSO in the UI with a test sign-in first, so a typo can't lock anyone out and group claims can't escalate access.
  • Hand-rolled JWT validation. We use the openidconnect crate for discovery, PKCE, nonce and ID token checks, with HTTP redirects disabled.
  • Letting the CLI talk to the provider directly. That would need a public client and provider-specific device flows. Approving through Dopbase works the same for every provider, and also without SSO.
  • OIDC workload login for CI (#31). Runner tokens already give each environment a scoped, revocable credential, so we're not doing it.

Additional Context

Security notes

  • The state is bound to the browser, the flow is single-use, and the handoff code lives 60 seconds and works once.
  • Provider metadata is cached for an hour, and JWKS is fetched again once on an unknown key.
  • Changing the issuer removes the old links and turns SSO off until the next test sign-in. People then link again by verified email.
  • The Entra email claim is unverified, so Entra accounts link by email only with the xms_edov claim.
  • The client secret is re-encrypted on master key rotation and covered by backups, restore and factory reset.
  • Rate limits cover SSO starts, callbacks, device requests and user-code guesses.
  • Password sign-in for a passwordless account runs a dummy password check so response timing doesn't reveal it.
  • New audit events: sso_provider.*, sso_identity.linked, sso_identity.unlinked, sso_login.failed, cli_login.approved and cli_login.denied. Logins record method: sso or method: browser.

Implementation checklist

  • [x] Shared session issuing, GET /api/v1/auth/methods, device flow endpoints, /cli/approve page, dopbase login --browser and --browser-open
  • [x] SSO provider settings page, test sign-in before enabling, start, callback and exchange, linking rules
  • [x] Optional passwords, Require SSO, hide password form, SSO confirmation, CLI confirmation through the browser
  • [x] Master key rotation, backup, restore and factory reset cover the client secret
  • [x] Server tests against an in-process mock provider, CLI tests, UI tests
  • [x] Docs (single sign-on guide, identity, CLI, API, audit events) and changelog

The pull request for this issue closes [#121] and [#30]. [#31] is closed as not planned.

Related

Tickets: #121
Tickets: #142
Tickets: #30
Tickets: #31

Discussion

  • Anonymous

    Anonymous - 2026-10-25
     
  • Anonymous

    Anonymous - 2026-10-25
     
  • Anonymous

    Anonymous - 2026-10-25

    Ticket changed by: dopbase

    • status: open --> closed
     

Log in to post a comment.