Add deployment tiers, self-service password reset, and Authelia SSO fixes
release gate / check (push) Failing after 7m28s

Product tiers (decided 2026-10-26): TIER=core|multi is the deployment knob.
core (federated install, paying customers) derives AUTH_MODE=oidc with
signup/bootstrap off - Authelia is the only way in and accounts are
provisioned upstream (Superpanel -> LDAP -> Authelia). multi (hosted
self-service) derives AUTH_MODE=password: signup, password login and
SMTP-backed self-reset, with the OIDC bridge refused even when variables
are set. Explicit AUTH_MODE/SIGNUP_ENABLED/ALLOW_BOOTSTRAP_SIGNUP always
override the tier; invalid values fail startup instead of falling back.
Go enforces every gate at the API; the web UI mirrors it (conditional
credentials provider, SSO-only login page, signup/reset redirects).

Authelia-only bootstrap: ProvisionExternal grants ADMIN to ADMIN_EMAILS
addresses at first SSO login, and --seed accepts SEED_SUBJECT to link a
pre-existing password account offline - the only path when 409 'account
link required' meets a deployment where nobody can password-login to call
oidc-link.

Self-service password reset (multi tier): POST /api/password/forgot and
/api/password/reset with hashed single-use 30-minute tokens
(PasswordResetToken, migration 011 + schema.sql), enumeration-safe
identical 200s, per-IP rate limits, tokenVersion bump on success (all
prior sessions revoked), OIDC-only accounts excluded by design. New
internal/mailer sends via netguard+outbound budget; NETGUARD_TRUSTED_HOSTS
pins operator-chosen relays that resolve privately (split-horizon DNS)
without the blanket INTEGRATIONS_ALLOW_PRIVATE switch. Web gains
/forgot-password and /reset-password pages and a login-page link.

Federated install fixes: the Authelia client now registers a
claims_policy putting email in the ID token (production AccessDenied -
Auth.js builds OIDC profiles exclusively from ID-token claims), config is
validated before restarting the shared Authelia, uninstall removes the
claims block marker-safely, and generated .env switches to TIER=core with
a password-less admin seed.

Tests: tier derivation/override unit tests, mode and tier integration
tests (403 gates, bridge refusal, ADMIN_EMAILS promotion, offline link),
reset-flow integration tests against a loopback SMTP fake, netguard
trusted-host tests. Docs: RUNNING.md, web/docs/AUTHELIA.md section 7,
.env.example, STRATEGY.md.
This commit is contained in:
Andrew S Erwin
2026-10-26 12:28:43 -05:00
parent d7a2abc683
commit f372936894
33 changed files with 1879 additions and 64 deletions
+52 -8
View File
@@ -3,7 +3,9 @@
superbrain uses Authelia as its primary OpenID Connect provider. The trusted
Next.js server runs the authorization-code flow, validates the ID token, and
then exchanges the verified identity for a local Go user. Email/password login
remains available as a fallback.
remains available as a fallback in the default `AUTH_MODE=both`; see §7 for
the Authelia-only (`AUTH_MODE=oidc`) and password-only (`AUTH_MODE=password`)
deployment shapes.
This guide covers the Authelia client configuration and how the identity bridge
maps a verified subject to the PostgreSQL users that Go authorizes.
@@ -204,7 +206,7 @@ a local user ID.
| Symptom | Likely cause |
|---|---|
| Config says Not connected | One of the variables is empty or a placeholder, or containers were not recreated after editing `.env` |
| NextAuth returns AccessDenied | The Go identity bridge rejected the exchange; check the Go logs for `oidc provision` or a `409 Account link required` |
| NextAuth returns AccessDenied | The Go identity bridge rejected the exchange. The **web** container logs `oidc provision: Go answered <status>`: `409` = local password account needs explicit linking; `400` = missing subject/email (client lacks a `claims_policy`, so Authelia kept `email` out of the ID token) or an issuer mismatch between the web and app containers |
| Go callback returns 501 | Expected stub; the browser callback must reach Next.js, not Go |
| Authelia shows "invalid redirect_uri" | Callback URL not listed exactly in `redirect_uris` |
| Authelia logs "The state is missing or does not have enough characters" | Auth.js omits `state` for OIDC providers by default (PKCE-only); the provider must set `checks: ['pkce', 'state']` (it does — don't remove it) |
@@ -212,10 +214,52 @@ a local user ID.
| Required identity claims are missing | Check Authelia's claims policy and user profile |
| Browser has a session, but Go returns 401 | Check that the session ID is the resolved local `User.id`, not the OIDC subject |
## 7. Optional: Authelia-only login
## 7. Deployment tiers and auth modes
Email/password remains as a fallback. An Authelia-only deployment requires
disabling the credentials provider, local login/signup screens, and local
signup/login endpoints in both Next.js and Go, while preserving the trusted
OIDC identity-provisioning path. Hiding the email form alone does not disable
the backend password login routes.
Deployments have a product tier: `TIER=core` (federated install for paying
customers — Authelia exclusively) or `TIER=multi` (hosted self-service —
signup, password login, self-reset). The tier derives the mechanism-level
variables; an explicitly set variable always wins. `AUTH_MODE` selects the
authentication personality directly. Go enforces everything at the API; the
web UI follows (hiding a form is never the only barrier):
| Mode | Password login | Signup | Password reset | Authelia OIDC |
|---|---|---|---|---|
| `both` (default, no tier) | ✅ | ✅ (`SIGNUP_ENABLED`) | ✅ (needs `SMTP_*`) | ✅ when the three `OIDC_*` vars are real |
| `password` (`TIER=multi`) | ✅ | ✅ (`SIGNUP_ENABLED`) | ✅ (needs `SMTP_*`) | ⛔ disabled even with `OIDC_*` set |
| `oidc` (`TIER=core`) | ⛔ 403 | ⛔ 403 | ⛔ 403 | ✅ required |
`TIER=core` additionally defaults `SIGNUP_ENABLED` and
`ALLOW_BOOTSTRAP_SIGNUP` to off (accounts are provisioned upstream, e.g.
Superpanel → LDAP → Authelia). `TIER=multi` keeps the historical defaults.
The multi tier is intended to grow organization-level tenancy (memberships,
per-tenant admin/billing) — decided 2026-10-26, not built yet.
In `oidc` mode:
- The credentials provider is not registered in NextAuth, `/signup`,
`/forgot-password` and `/reset-password` redirect to `/login`, and Go
refuses `POST /api/auth/login`, `POST /api/signup` and the password-reset
endpoints. The OIDC identity bridge is the only way in.
- Accounts are provisioned upstream (on the federated core: Superpanel →
LDAP → Authelia) and materialize locally on first SSO login.
- Admin bootstrap: an address listed in `ADMIN_EMAILS` becomes ADMIN at its
first SSO login; everyone else is USER.
- The operator account can be seeded password-less
(`SEED_EMAIL=... /superbrain --seed`). Do NOT seed a password in this
mode: it is unusable (login is disabled) and it blocks the SSO bridge's
verified-email auto-link with `409 Account link required`.
- Pre-existing password accounts (e.g. from before a mode switch) must be
linked deliberately — email match alone is not proof. With login disabled
nobody can obtain the admin session `POST /api/admin/oidc-link` requires,
so use the offline path:
`docker exec -e SEED_EMAIL=<email> -e SEED_SUBJECT=<authelia sub> superbrain-app /superbrain --seed`
(idempotent; refuses subjects already linked to a different user).
In `password` mode the bridge (`POST /api/auth/oidc/identity`) is refused
even with a valid service token, and the status endpoint reports OIDC
disabled so the UI hides Authelia.
Unknown `AUTH_MODE` values fail startup (`Validate`) instead of silently
falling back to `both` — a typo must never re-enable password login on an
SSO-only deployment.