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
+53 -15
View File
@@ -132,12 +132,30 @@ Written by `config_superbrain` into `/federated/apps/superbrain/.env`
AUTH_SECRET must not invalidate them**.
- `POSTGRES_PASSWORD` for the `superbrain` DB user.
- `ADMIN_EMAILS=admin@$DOMAIN`, `ALLOW_BOOTSTRAP_SIGNUP=0`,
`SIGNUP_ENABLED=0` (private instance; accounts provisioned by operator),
`COOKIE_SECURE=1`.
- Decision 2026-10-26 (supersedes the 2026-10-25 open-signup experiment):
deployments have a product **tier** — `TIER=core|multi` — which derives
the mechanism defaults (`AUTH_MODE`, `SIGNUP_ENABLED`,
`ALLOW_BOOTSTRAP_SIGNUP`); explicit variables override. The core install
is `TIER=core`: Authelia-only (`AUTH_MODE=oidc` derived), signup and
bootstrap off. Go refuses password login, signup and password reset at
the API (hiding the web UI is not the barrier); the identity bridge is
the only way in. Account creation happens upstream in Superpanel → LDAP
→ Authelia and materializes locally on first SSO login. The hosted
product is `TIER=multi`: `AUTH_MODE=password` derived (signup/login/
self-reset; OIDC bridge refused even with variables set) — SMTP-backed
password reset belongs to that tier (see RUNNING.md); core needs no SMTP
config. Longer term the multi tier is meant to grow ORGANIZATION-level
tenancy (tenant_id, memberships, per-tenant admin/billing) — decided
2026-10-26, not built yet; today it is multi-user.
- Admin bootstrap on the core tier: an `ADMIN_EMAILS` address becomes ADMIN
at first SSO login (`ProvisionExternal`); a fresh SSO user is USER.
- Operator account: `docker exec -e SEED_EMAIL=admin@$DOMAIN
-e SEED_PASSWORD="$ADMINPASS" superbrain-app /superbrain --seed` — verified
idempotent (no-op if the email exists) and grants ADMIN when the email is in
`ADMIN_EMAILS`.
superbrain-app /superbrain --seed` — password-less on purpose: a password
is unusable with login disabled and would block the SSO verified-email
auto-link (409). Idempotent; grants ADMIN via ADMIN_EMAILS. Pre-existing
password accounts (e.g. from before the mode switch) must be linked
offline: same command plus `-e SEED_SUBJECT=<authelia sub>`.
**Rate-limiting caveat (open item):** with `TRUSTED_PROXY=1` the web container
reads the client IP from `X-Real-IP` **only** — it deliberately ignores
@@ -153,12 +171,24 @@ Decide before cutover; (a) is safe to start with.
Follows the bookstack pattern in `lib/bookstack.sh`:
1. Append a client to `/federated/apps/authelia/data/config/idproviders.yml`:
`client_id: superbrain`, `consent_mode: implicit`,
`authorization_policy: one_factor`, scopes `openid profile email`,
`client_id: superbrain`, `claims_policy: superbrain`,
`consent_mode: implicit`, `authorization_policy: one_factor`, scopes
`openid profile email`,
`redirect_uris: [https://superbrain.$DOMAIN/api/auth/callback/authelia]`
(the NextAuth provider id is `authelia`), save a copy to
(the NextAuth provider id is `authelia`), plus a `claims_policies` entry
`superbrain: {id_token: [email, email_verified, name, preferred_username]}`
— without it Authelia keeps `email` out of the ID token (hit in production
2026-10-25: Auth.js builds the OIDC profile exclusively from ID-token
claims, the Go bridge answered 400 "Subject and email are required", and
every login ended in AccessDenied). Save a copy of the client block to
`/federated/apps/superbrain/.superbrain.oidc-client.yml` (chmod 600),
`restart_service authelia`.
validate with `docker exec authelia authelia validate-config --config
/config/configuration.yml --config /config/idproviders.yml
--config.experimental.filters template`, then `restart_service authelia`.
The uninstall path removes the claims block by its `### Superbrain claims`
marker (marker + exactly 2 lines), drops a then-empty `claims_policies:`
key, and must run BEFORE the client-block range deletion — that range
starts at the first `### Superbrain` match.
2. Append `OIDC_ISSUER=https://authelia.$DOMAIN`, `OIDC_CLIENT_ID=superbrain`,
`OIDC_CLIENT_SECRET=<create_password>` to the app `.env`, then
`docker compose up -d --force-recreate web` — **not** `restart_service`:
@@ -166,16 +196,24 @@ Follows the bookstack pattern in `lib/bookstack.sh`:
(hit in production 2026-10-25: web came up with zero OIDC vars and
NextAuth returned `error=Configuration`).
Verified end-to-end: in-container issuer discovery works through the
`extra_hosts` pin, and `/api/auth/signin/authelia` 302s to
Verified: in-container issuer discovery works through the `extra_hosts` pin,
`/api/auth/signin/authelia` 302s to
`https://authelia.$DOMAIN/api/oidc/authorization` with the exact registered
redirect URI, `openid profile email` and PKCE S256.
redirect URI, `openid profile email` and PKCE S256, and (after the claims
policy fix of 2026-10-25) the identity bridge receives `email` in the ID
token. Other house apps (gitea, bookstack, immich) never needed a claims
policy because they call the userinfo endpoint themselves; superbrain's
Auth.js flow does not.
Operator note (product invariant): SSO sign-in auto-provisions **new** users,
but existing password accounts require explicit linking via
`POST /api/admin/oidc-link` — email match alone is intentionally not proof.
Seed the admin with password first, then link, or let SSO provision and
promote via `ADMIN_EMAILS`.
but existing password accounts require explicit linking — email match alone
is intentionally not proof. In `AUTH_MODE=oidc` the admin API link
(`POST /api/admin/oidc-link`) needs a session nobody can obtain, so the
offline path is the seed CLI: `docker exec -e SEED_EMAIL=... -e SEED_SUBJECT=...
superbrain-app /superbrain --seed`. Standard flow on core: seed the admin
password-less (ADMIN via `ADMIN_EMAILS`), first SSO login links by verified
email; everyone else is provisioned by Superpanel → LDAP → Authelia and
auto-provisions on first login.
### mcpserver link: drop for now
+73 -9
View File
@@ -167,10 +167,23 @@ NEXTAUTH_URL=https://superbrain.$DOMAIN
AUTH_TRUST_HOST=true
API_BASE_URL=http://superbrain-app:8080
# --- Access policy (private instance: operator-provisioned accounts) ---
# --- Access policy ---
# Decision 2026-10-26: the core/federated install is the CORE TIER —
# TIER=core derives AUTH_MODE=oidc (Authelia only: Go refuses password
# login, signup and password reset at the API), signup off and bootstrap
# off; no explicit overrides are set here on purpose, so the tier defaults
# are the single source of truth. Accounts are provisioned upstream
# (Superpanel -> LDAP -> Authelia) and materialize locally on first SSO
# login. ADMIN_EMAILS makes a listed address ADMIN at first SSO login —
# the only bootstrap path in this tier. The operator account is seeded
# password-less; a pre-existing password account can be linked offline:
# docker exec -e SEED_EMAIL=... -e SEED_SUBJECT=... superbrain-app
# /superbrain --seed (needed because the SSO bridge refuses to auto-link
# password accounts by email alone). The hosted self-service product is
# the other tier: TIER=multi (AUTH_MODE=password, signup + SMTP-backed
# self-reset; see RUNNING.md).
ADMIN_EMAILS=admin@$DOMAIN
ALLOW_BOOTSTRAP_SIGNUP=0
SIGNUP_ENABLED=0
TIER=core
COOKIE_SECURE=1
# TRUSTED_PROXY deliberately unset — traefik does not send X-Real-IP.
EOF
@@ -208,8 +221,13 @@ start_superbrain() {
# Provision the operator account. Verified idempotent (no-op when the email
# already exists); grants ADMIN because admin@$DOMAIN is in ADMIN_EMAILS.
# Password-less on purpose (AUTH_MODE=oidc): a password would be unusable
# with login disabled AND would block the SSO bridge's verified-email
# auto-link (409). First Authelia login links the account; if Authelia ever
# stops asserting email_verified, link offline instead with
# -e SEED_SUBJECT=<authelia sub> on the same command.
for i in $(seq 1 10); do
docker exec -e SEED_EMAIL="admin@$DOMAIN" -e SEED_PASSWORD="$ADMINPASS" -e SEED_NAME="Admin" \
docker exec -e SEED_EMAIL="admin@$DOMAIN" -e SEED_NAME="Admin" \
superbrain-app /superbrain --seed &>/dev/null && break
sleep 3
done
@@ -230,10 +248,29 @@ uninstall_superbrain() {
docker exec pdns pdnsutil delete-rrset $DOMAIN superbrain.$DOMAIN A &>/dev/null
# Remove Authelia SSO config if present (immich pattern)
if grep -q "### Superbrain" /federated/apps/authelia/data/config/idproviders.yml 2>/dev/null; then
sed -i '/### Superbrain/,/### /{/### [A-Z]/!{/### /!d}}' /federated/apps/authelia/data/config/idproviders.yml
sed -i '/### Superbrain/d' /federated/apps/authelia/data/config/idproviders.yml
# Remove Authelia SSO config if present (immich pattern). Two blocks exist:
# the claims policy ("### Superbrain claims", possibly with the
# claims_policies: key we created) and the client ("### Superbrain").
# Remove the claims block FIRST and by exact line count - the client-block
# range deletion below starts at the first "### Superbrain" match, and a
# leftover claims marker would make it eat the claims_policies:/clients: keys.
AUTH_YML=/federated/apps/authelia/data/config/idproviders.yml
if grep -q "### Superbrain" "$AUTH_YML" 2>/dev/null; then
sed -i '/### Superbrain claims/{N;N;d}' "$AUTH_YML"
# Drop claims_policies: again when our policy was its only entry.
awk '
/^ claims_policies:$/ {
if ((getline nxt) > 0) {
if (nxt ~ /^ /) { print; print nxt } else { print nxt }
}
next
}
{ print }
' "$AUTH_YML" > "$AUTH_YML.tmp" && mv "$AUTH_YML.tmp" "$AUTH_YML"
sed -i '/### Superbrain/,/### /{/### [A-Z]/!{/### /!d}}' "$AUTH_YML"
sed -i '/### Superbrain/d' "$AUTH_YML"
docker exec authelia authelia validate-config --config /config/configuration.yml --config /config/idproviders.yml --config.experimental.filters template \
|| echo "WARNING: Authelia config does not validate after superbrain removal - inspect $AUTH_YML before relying on SSO"
restart_service authelia
fi
@@ -250,10 +287,29 @@ configsso_superbrain() {
SUPERBRAIN_CLIENT_SECRET=$(create_password)
SUPERBRAIN_CLIENT_SECRET_HASH=$(docker run --rm authelia/authelia:latest authelia crypto hash generate pbkdf2 --password $SUPERBRAIN_CLIENT_SECRET | awk '{ print $2 }')
# Authelia only includes claims listed in a claims policy's id_token set in
# the ID token, and Auth.js builds the OIDC profile EXCLUSIVELY from ID-token
# claims (it only calls userinfo when a provider sets idToken:false, which
# superbrain must not). Without email in the id_token the Go bridge answers
# 400 "Subject and email are required" and every SSO login ends in
# AccessDenied (hit in production 2026-10-25). Register the policy next to
# the client; the uninstall path removes both.
AUTH_YML=/federated/apps/authelia/data/config/idproviders.yml
SUPERBRAIN_CLAIMS="['email', 'email_verified', 'name', 'preferred_username']"
cp -a "$AUTH_YML" "$AUTH_YML.bak-superbrain"
if grep -q '^ superbrain:$' "$AUTH_YML"; then
echo " claims policy 'superbrain' already present, keeping it"
elif grep -q '^ claims_policies:' "$AUTH_YML"; then
sed -i "/^ claims_policies:/a\\ ### Superbrain claims\n superbrain:\n id_token: $SUPERBRAIN_CLAIMS" "$AUTH_YML"
else
sed -i "/^ clients:/i\\ claims_policies:\n ### Superbrain claims\n superbrain:\n id_token: $SUPERBRAIN_CLAIMS" "$AUTH_YML"
fi
SUPERBRAIN_OIDC_CLIENT_YAML=$(cat <<EOF
### Superbrain
- client_id: 'superbrain'
client_name: 'Superbrain'
claims_policy: 'superbrain'
client_secret: $SUPERBRAIN_CLIENT_SECRET_HASH
consent_mode: 'implicit'
public: false
@@ -267,10 +323,18 @@ configsso_superbrain() {
userinfo_signed_response_alg: 'none'
EOF
)
printf '%s\n' "$SUPERBRAIN_OIDC_CLIENT_YAML" >> /federated/apps/authelia/data/config/idproviders.yml
printf '%s\n' "$SUPERBRAIN_OIDC_CLIENT_YAML" >> "$AUTH_YML"
printf '%s\n' "$SUPERBRAIN_OIDC_CLIENT_YAML" > /federated/apps/superbrain/.superbrain.oidc-client.yml
chmod 600 /federated/apps/superbrain/.superbrain.oidc-client.yml
# idproviders.yml is shared by every SSO app: validate the merged config
# before restarting, and restore the backup when it does not parse.
if ! docker exec authelia authelia validate-config --config /config/configuration.yml --config /config/idproviders.yml --config.experimental.filters template; then
cp -a "$AUTH_YML.bak-superbrain" "$AUTH_YML"
failcheck "Authelia config invalid after adding superbrain - restored $AUTH_YML.bak-superbrain"
fi
rm -f "$AUTH_YML.bak-superbrain"
restart_service authelia
# env_file pattern: appending here is enough — web picks the values up on