#141 [Feature]: OIDC single sign-on and browser-approved CLI login
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
GET /api/v1/auth/sso/startcreates a single-use flow (PKCE S256,state,nonce), sets adopbase_ssocookie that binds the flow to this browser, and redirects to the provider.GET /api/v1/auth/sso/callbackchecks the binding cookie, consumes the flow withDELETE ... RETURNING, exchanges the code, and validates the ID token (issuer, audience, expiry, nonce, asymmetric algorithms only).- 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 toPOST /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 --browserprints a link and an 8-character code (for exampleWDJB-MJHT) and waits.--browser-openalso opens the link in this machine's browser, and--passwordforces the old prompt. On an SSO server, plaindopbase loginuses the browser flow./cli/approveis 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/sessionreturns 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.tomland 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
openidconnectcrate 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
emailclaim is unverified, so Entra accounts link by email only with thexms_edovclaim. - 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.approvedandcli_login.denied. Logins recordmethod: ssoormethod: browser.
Implementation checklist
- [x] Shared session issuing,
GET /api/v1/auth/methods, device flow endpoints,/cli/approvepage,dopbase login --browserand--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.
Ticket changed by: dopbase