Repository navigation
feat(auth): add SSO-only mode that blocks password sign-in except for the default super admin - #730
Conversation
… the default super admin Adds an opt-in, backend-enforced SSO-only login policy (closes Paca-AI#676). While it is on, only the default super admin can sign in with a password, so a user removed at the identity provider can no longer fall back to a local password. Default super admin - Migration 000086 adds users.bootstrap_admin, kept to a single account by a partial unique index. seedAdmin marks the account seeded from ADMIN_USERNAME on every start (UserRepository.MarkBootstrapAdmin), so existing installs get the mark on upgrade and it follows ADMIN_USERNAME. Other SUPER_ADMIN or admin accounts are not exempt. Policy and enforcement - auth_security_settings.sso_only (off by default) is part of the existing login policy (mfadom.Policy.SSOOnly, PUT /admin/auth-security). It can only be turned on while an SSO provider is enabled (SSO_ONLY_NO_PROVIDER). - The login gate refuses password sign-in for every other account with 403 AUTH_PASSWORD_LOGIN_DISABLED. It does so after the password check, so a wrong password still reads as one, and again at the TOTP and passkey second-factor steps. - Password reset by an admin, set-password links (left unused) and password change are refused for those accounts, and so is password-only MFA enrollment. With linking by email, the linked account's password is refused in the same way. - SSO sign-in drops a pending must-change-password flag that SSO-only mode makes impossible to meet, so the session isn't stuck on a change the API refuses. - Break-glass password sign-ins by the default super admin are logged. - Public GET /auth/login-options tells the login page whether the instance is SSO-only. Web - The login page shows only the SSO providers when SSO-only is on, with a "Sign in as administrator" link (/?admin=1) to the password form. The route prefetches the policy so the form never flashes. - Login security settings get an SSO-only switch, disabled until a provider is enabled. The new errors are mapped on the login, MFA, set-password, change-password and reset-password screens, in all locales. Docs: the SSO guide covers SSO-only mode, the default super admin, the hidden admin sign-in and a recovery runbook. Tests cover the gate, policy validation, the password flows, password-only enrollment, the SSO flag drop, the seed mark (Postgres) and an API e2e run of the whole feature. The shared e2e environment now wires the login gate as bootstrap/app.go does.
There was a problem hiding this comment.
ℹ️ No critical issues — two minor hardening notes.
Reviewed changes
- SSO-only policy:
sso_onlyjoinsauth_security_settings(migration000086), is saved throughPUT /admin/auth-securitywith an enabled-provider check (SSO_ONLY_NO_PROVIDER), and is exposed to the login page by the new publicGET /auth/login-options. - Break-glass account:
users.bootstrap_adminmarks the account seeded fromADMIN_USERNAME;seedAdminmoves the mark on every start, and a partial unique index keeps it to one account. - Enforcement: password sign-in, MFA completion, passkey login, admin reset, set-password links, self-service change, and pre-login MFA enrollment all refuse non-exempt accounts with
403 AUTH_PASSWORD_LOGIN_DISABLED; the exempt account's sign-ins are logged. - SSO sign-in: a pending must-change-password flag is dropped when the policy keeps the account off passwords.
- Web: SSO-only login page with the
?admin=1administrator entry, the settings toggle, error mapping, and strings across all nine locales. - Docs/tests: SSO-only guide and permission tables, plus unit, Postgres seed, and e2e coverage.
ℹ️ Deleting the seeded admin can leave SSO-only with no break-glass account
The recovery story assumes a live bootstrap_admin account, but seedAdmin returns early when the ADMIN_USERNAME account is soft-deleted, and a soft delete only touches accounts, so the tombstone keeps bootstrap_admin = TRUE. After a DELETE /admin/users/{id} on that account, no live account can use a password, the stale flag occupies the partial unique index, and a restart does not reliably repair it; an install whose seeded admin was already deleted before upgrading gets no mark at all, yet SSO-only can still be turned on.
Technical details
# No live exempt account is guaranteed
## Affected sites
- `services/api/internal/bootstrap/seed_roles.go:100-114` — the soft-deleted branch returns without calling `MarkBootstrapAdmin`.
- `services/api/internal/repository/postgres/account_helpers.go:60-64` — soft delete updates only `accounts`; `users.bootstrap_admin` survives on the tombstone.
- `services/api/internal/repository/postgres/user_repository.go:343-373` — the clear-then-set only runs when the seed reaches it; the tombstone's flag otherwise blocks any other mark via `uni_users_bootstrap_admin`.
- `services/api/internal/service/mfa/mfa_service.go:420-424` — `SetPolicy` checks only that an enabled provider exists, not that a live marked account does.
- `services/api/internal/repository/postgres/user_repository.go:244-249` — `FindByUsernameIncludingDeleted` has no ordering, so once a same-named live account exists alongside the tombstone the row the seed acts on is nondeterministic.
## Required outcome
- After any API restart, either a live account holds `bootstrap_admin`, or turning SSO-only on is refused. A soft-deleted `ADMIN_USERNAME` account must not silently disable the break-glass path, and its stale mark must not prevent marking a live account.
- Decide whether deleting the marked account is allowed while the mode is on; if it is, the seed should recover from it.
## Open questions for the human
- Should `DELETE /admin/users/{id}` refuse the marked account while `sso_only` is on, or should the seed recreate or relocate the mark when the configured account is deleted?deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
…ils to load Signed-off-by: Asish Kumar <[email protected]>
There was a problem hiding this comment.
✅ No new issues found.
Reviewed changes
This run covers the single commit landed since the prior review (270e982 → c2979ad).
- Failed provider fetch on the SSO-only login page:
LoginFormPanelnow readsisErrorfrom the public SSO providers query and folds it into the existing empty-list condition, so a failed/auth/sso/providersrequest renders the "no single sign-on option is available" notice instead of a page with neither buttons nor explanation. The administrator sign-in link stays available. - Coverage: a vitest case makes the mocked provider request throw and asserts the notice appears.
The leftover non-blocking note from the previous review — a soft-deleted seeded admin can leave SSO-only without a live break-glass account, and SetPolicy does not check for one — is unchanged by these commits and still worth a decision before rollout.
deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏
pikann
left a comment
There was a problem hiding this comment.
LGTM! Thank you for the contribution! 🚀

Summary
Adds an opt-in, backend-enforced SSO-only login policy (closes #676). While it is on, only the default super admin can sign in with a password. Everyone else signs in through SSO, so a user removed at the IdP (or from the allowed IdP group, see #729) can no longer fall back to a local password.
Default super admin. Migration
000086addsusers.bootstrap_admin, and a partial unique index keeps it to one account.seedAdminmarks the account seeded fromADMIN_USERNAMEon every start. Existing installs therefore get the mark on upgrade, and it moves ifADMIN_USERNAMEchanges. The mark is never set through the API. OtherSUPER_ADMINor admin accounts are not exempt.Policy.
sso_onlyis part of the existing login policy:auth_security_settings,PUT /admin/auth-security, gated bysettings.security:write. It is off by default, and it can only be turned on while an SSO provider is enabled (SSO_ONLY_NO_PROVIDER).Enforcement (API). While the mode is on, any account other than the default super admin is refused with
403 AUTH_PASSWORD_LOGIN_DISABLEDat each of these points:/auth/login), checked after the password so a wrong password still reads as one. It is checked again when a TOTP code or passkey completes a login that was waiting on a second factor./admin/users/{id}/password), set-password links (/auth/password/set; the link is left unused), and password change (/users/me/password)./auth/mfa/setup…).LinkByEmailcan't bypass it, because a linked account's password is refused like any other.Web.
/?admin=1) opens the password form. The route prefetches a new publicGET /auth/login-options, so the form never flashes.Docs.
docs/guides/sso-oidc.mdgets an SSO-only section covering the default super admin, the hidden admin sign-in and a recovery runbook. The permission tables mention the new setting.Type of Change
Checklist
Testing
go test ./...(excluding e2e) andgolangci-lint runare clean.-racepasses on the touched packages.GET /auth/login-options, and the must-change-password drop on SSO sign-in.PACA_TEST_PG_DSN) covers the seed mark: idempotent, followsADMIN_USERNAME, and the unique index allows only one marked account.TestSSOOnlyModeruns on real Postgres and Redis. It covers no provider → 400, turning the mode on, password sign-in refused for anotherSUPER_ADMINand a user but allowed for the default super admin, reset and change refused, SSO sign-in by email link, and turning the mode off. The shared e2e env now wires the login gate asbootstrap/app.godoes. The full e2e suite passes with it, includingTestRealMigrations_ApplyCleanlyFromScratch.biome check,tsc, the full vitest suite (including newLoginFormPaneland updatedLoginSecuritySettingstests) andvite buildpass.