Skip to content

feat(auth): add SSO-only mode that blocks password sign-in except for the default super admin - #730

Merged
pikann merged 2 commits into
Paca-AI:masterfrom
officialasishkumar:feature/sso-only-mode
Nov 13, 2026
Merged

pikann merged 2 commits into
Paca-AI:masterfrom
officialasishkumar:feature/sso-only-mode

Conversation

@officialasishkumar

Copy link
Copy Markdown
Contributor

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 000086 adds users.bootstrap_admin, and a partial unique index keeps it to one account. seedAdmin marks the account seeded from ADMIN_USERNAME on every start. Existing installs therefore get the mark on upgrade, and it moves if ADMIN_USERNAME changes. The mark is never set through the API. Other SUPER_ADMIN or admin accounts are not exempt.

Policy. sso_only is part of the existing login policy: auth_security_settings, PUT /admin/auth-security, gated by settings.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_DISABLED at each of these points:

  • Password sign-in (/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 reset (/admin/users/{id}/password), set-password links (/auth/password/set; the link is left unused), and password change (/users/me/password).
  • Password-only MFA enrollment (/auth/mfa/setup…).
  • LinkByEmail can't bypass it, because a linked account's password is refused like any other.
  • An SSO sign-in drops a pending must-change-password flag that could never be met. Without this, an account an admin created with a temporary password would be stuck on a change the API refuses.
  • Each break-glass password sign-in by the default super admin is logged as a warning, with the account and client IP.
  • Session and API-key revocation are not touched, as agreed in the issue.

Web.

  • When SSO-only is on, the login page shows only the SSO providers. A "Sign in as administrator" link (/?admin=1) opens the password form. The route prefetches a new public GET /auth/login-options, 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, with strings in all nine locales.

Docs. docs/guides/sso-oidc.md gets 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

  • Other (feature: SSO-only login mode)

Checklist

  • The change is focused and scoped.
  • Related documentation is updated.
  • New structure or direction is explained clearly.
  • I avoided unnecessary detail or premature abstraction.

Testing

  • go test ./... (excluding e2e) and golangci-lint run are clean. -race passes on the touched packages.
  • Unit tests cover the login gate (only the default super admin passes; it still needs MFA and the IP allow-list), the passkey step, provider validation on save, the password set, reset and change refusals (the token stays unused), the password-only enrollment endpoints, GET /auth/login-options, and the must-change-password drop on SSO sign-in.
  • A Postgres test (PACA_TEST_PG_DSN) covers the seed mark: idempotent, follows ADMIN_USERNAME, and the unique index allows only one marked account.
  • New API e2e test TestSSOOnlyMode runs on real Postgres and Redis. It covers no provider → 400, turning the mode on, password sign-in refused for another SUPER_ADMIN and 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 as bootstrap/app.go does. The full e2e suite passes with it, including TestRealMigrations_ApplyCleanlyFromScratch.
  • Web: biome check, tsc, the full vitest suite (including new LoginFormPanel and updated LoginSecuritySettings tests) and vite build pass.

… 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.

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues — two minor hardening notes.

Reviewed changes

  • SSO-only policy: sso_only joins auth_security_settings (migration 000086), is saved through PUT /admin/auth-security with an enabled-provider check (SSO_ONLY_NO_PROVIDER), and is exposed to the login page by the new public GET /auth/login-options.
  • Break-glass account: users.bootstrap_admin marks the account seeded from ADMIN_USERNAME; seedAdmin moves 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=1 administrator 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?

Pullfrog  | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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: LoginFormPanel now reads isError from the public SSO providers query and folds it into the existing empty-list condition, so a failed /auth/sso/providers request 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.

Pullfrog  | View workflow run | Using deepseek-v4.1-flash-1017 (free via Pullfrog for OSS) | 𝕏

@pikann pikann left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thank you for the contribution! 🚀

@pikann
pikann merged commit f828240 into Paca-AI:master Nov 13, 2026
7 checks passed
@pikann pikann mentioned this pull request Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] SSO-only mode: block local password login except for the default super admin

2 participants