Other cores had an installer but no updater — updates meant re-running the workstation tar-sync by hand. deploy/federated/update.sh ships inside the app dir (the installer stages deploy/), so every installed core already has its updater: sudo bash /federated/apps/superbrain/deploy/federated/update.sh [git-ref] Flow, in house-safety order: re-exec from /tmp (the sync overwrites the running script), clone the repo at REF (default main; sha refs fall back to full-clone+checkout), record current image ids, compressed pre-update pg_dump (last 5 retained, emptiness-checked), sync source (.env/data untouched, .git kept out of the app dir/build context), refresh lib+service suite files (parse-checked before replacing, backed up), rebuild, force-recreate (migrate one-shot applies new migrations), health-probe app+web for up to 3 minutes — and on ANY failure retag the previous images and recreate, pointing at the dump. Deliberate non-goal: an in-app update button. The scratch containers have no docker socket and must never get one (read_only + cap_drop ALL is the hardening model); host-level operator action is the trust boundary until CI publishes registry images, at which point the generic house upgrade flow and the panel button supersede this script (IMAGE_VERSION_HOLD comes out of .env). Also: .dockerignore gains .update-backups (dumps live under the app dir, which is the build context); README/STRATEGY/install.sh document the update path. shellcheck clean; tested live on the production core.
18 KiB
Federated Suite Deploy Strategy
How Superbrain becomes a first-class app in the /federated suite on core,
installable with /federated/bin/installapp superbrain, upgradeable with the
standard upgrade flow, and covered by the suite's monitors, DNS, Authelia
SSO, backups and superpanel catalog.
Current state (verified 2026-10-22)
Two parallel, conflicting realities exist on core:
- Ad-hoc source stack in
/federated/apps/superbrain/: an rsync of this repo running the full compose stack (own postgres volume, web published on host port:3100because bun holds:3000). Not integrated: no traefik labels, nocorenetwork IP, no pdns record, invisible toinstallapp/upgrade/monitors/superpanel. - n8n-shaped placeholders:
/federated/lib/superbrain.shand/federated/services/superbrain/servicewere copied from n8n and describe an app that does not exist — single imagesuperbrainio/superbrainon port 5678, n8n's/rest/owner/setup, n8n'sdeployment_key/user_api_keysschema for the mcpserver link, andINTERNAL_IP=192.168.0.71which collides with the real n8n. Both files must be rewritten, not patched.
installapp refuses to run while /federated/apps/superbrain exists, so the
ad-hoc stack must be migrated and removed (or moved aside) before the
federated install can proceed.
Target architecture
Superbrain is not one image. It is three artifacts built from this repo:
| Artifact | Source | Role |
|---|---|---|
superbrain-app |
Dockerfile (scratch, Go) |
API on :8080, --healthcheck, --seed |
superbrain-web |
web/Dockerfile (Next standalone) |
UI on :3000, API proxy, NextAuth |
superbrain-migrate |
NEW: FROM postgres:16.15-alpine + COPY db /db |
one-shot schema bootstrap + migration runner |
The federated upgrade_app flow only understands registry images
(docker pull CONTAINER:VERSION, btrfs snapshot, compose down/up, health
probe). Source-on-host builds fight that machinery, so:
Decision: publish versioned images from CI; the host never builds.
Interim mode (implemented now, 2026-10-25): until CI publishes images,
lib/superbrain.sh builds from source staged at /federated/tmp/superbrain-src
(tar-synced from the workstation; the exact command is in the script header).
For OTHER federated cores (any operator with repo access),
deploy/federated/install.sh packages the whole flow: preflights the suite
(Authelia required — the core tier is SSO-only — plus the fcore SMTP
credential source), stages the source by git clone (or $SUPERBRAIN_SRC),
installs lib/superbrain.sh + services/superbrain/service (with fixed-IP
collision checks and SUPERBRAIN_*_IP overrides), runs
/federated/bin/installapp superbrain, then verifies containers, the
Authelia client + claims policy, and the HTTPS login page.
Images are tagged superbrain-app:local / superbrain-web:local, .env
carries IMAGE_VERSION_HOLD=1 so the generic upgrade flow skips the app
cleanly, and the service file's CONTAINER=superbrain-app matches the
first image: line of the generated compose so upgrade_app's rewrite-sed
can never mangle it. Updates in interim mode run through
deploy/federated/update.sh (shipped inside the app dir): clone at REF →
pre-update pg_dump (5 retained) → sync (.env/data untouched) → refresh
lib+service files → build → force-recreate → health probe → automatic
rollback to the previous image tags on failure. A deliberate non-goal: an
in-app "update" button — the scratch containers have no docker socket and
must never get one (read_only + cap_drop ALL is the hardening model);
host-level operator action is the trust boundary until registry mode.
Switching to registry mode later = publish images, drop the
build: keys + hold marker, point CONTAINER/VERSION at the registry —
at which point the house upgrade flow and panel button take over and
update.sh retires.
For the registry target:
- House precedent: the operator publishes custom builds under Docker Hub
federatedcomputer/*(bookstack, calcom, wordpress, superpanel, pdns, federated-postgres). Superbrain images go there:federatedcomputer/superbrain-{app,web,migrate}. - CI release workflow triggers on tags matching
^[0-9]+\.[0-9]+\.[0-9]+$(the suite'sVERSION_RXis'^[0-9][0-9\.]*$'— novprefix), builds and pushes all three images under the same tag (plus:latest). /federated/services/superbrain/servicesetsCONTAINER=to the app image andVERSION=to the current release.upgrade_appgreps the firstimage:line of the app compose file and pulls only that one → in the generated compose,appmust be the first service with animage:key, and aservices/superbrain/upgrade/prehook shoulddocker compose pullsoweb/migrateare fetched too before the redeploy.upgrade_appthen rewritesIMAGE_VERSIONin/federated/apps/superbrain/.env(itssedonVERSION=matches theIMAGE_VERSION=line) and restarts.upgrade_appalso probesdocker container inspect superbrain— the web container must be named exactlysuperbrain(plane/jitsi are special-cased infunctions.shfor not doing this; we avoid that by complying).
Database: shared postgresql container
Suite convention (DEPENDS="postgresql"): per-app user + database created via
docker exec postgresql psql, covered by the existing backuptool and
restore-db-from-backup flows, plus pre-upgrade btrfs snapshots. No dedicated
db container, no host-published ports.
Critical bootstrap order (verified against db/check-convergence.sh):
migrations run on top of schema.sql; migration 001_legacy_additive is
not a full initial schema. A fresh database must get schema.sql first, then
migrate.sh. The superbrain-migrate image therefore ships a wrapper
(db/bootstrap.sh, new in this repo): if the target database has no tables,
apply /db/schema.sql, then always run /db/migrate.sh. This makes
fresh-install and upgrade the same command, and stays compatible with the
repo's own compose stack (where initdb already applied schema.sql).
Version note: the shared server is federatedcomputer/federated-postgres:
17.6 while this repo develops/tests against 16.15. Run the integration
suite (or at least the converge check) against Postgres 17 once before first
install.
Networking & routing
House pattern (verified against immich/plane/docuseal/vaultwarden): all
containers on the external core network with fixed IPs, env_file: ./.env
as the single config source, traefik labels on the front container only.
- Fixed IPs (provisional —
.90–.92belong to mcpserver/hermes,.120/.121to nextcloudtalk; re-verify at install time): web192.168.0.93, app.94, migrate.95. web(container namesuperbrain, hostnamesuperbrain.$DOMAIN) carries the traefik labels:Host(\superbrain.$DOMAIN`),entrypoints=websecure,certresolver=letsencrypt, loadbalancer port **3000**.app/migrateget no labels — onlyweb` is routable.webreaches the API viaAPI_BASE_URL=http://superbrain-app:8080(container-name DNS oncore). Nothing is published on host ports.webpinsextra_hosts: authelia.$DOMAIN:$EXTERNALIP(the hairpin pattern gitea/vaultwarden/immich/calcom use) so in-container OIDC discovery against the public issuer URL works.NEXTAUTH_URL=https://superbrain.$DOMAIN— mandatory exact match; the API proxy's origin allowlist 403s every mutating request otherwise.- DNS:
start_superbrainadds the pdns A recordsuperbrain.$DOMAIN → $EXTERNALIP, same as every other app. - Monitor:
MONITOR="https://superbrain.@DOMAIN@/login|http_2xx"(/loginrenders without a session and is what the web healthcheck already probes). - Hardening from the repo compose is kept:
read_only,cap_drop: [ALL],no-new-privileges,tmpfs: [/tmp]on web.
Security env (production, per .env.example + AGENTS.md)
Written by config_superbrain into /federated/apps/superbrain/.env
(chmod 600), all secrets via create_password:
AUTH_SECRET— NextAuth JWT + Go session bridge + assertion HMAC signing.ENCRYPTION_KEY— dedicated key for stored IMAP credentials; rotating AUTH_SECRET must not invalidate them.POSTGRES_PASSWORDfor thesuperbrainDB user.ADMIN_EMAILS=admin@$DOMAIN,ALLOW_BOOTSTRAP_SIGNUP=0,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 isTIER=core: Authelia-only (AUTH_MODE=oidcderived), 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 isTIER=multi:AUTH_MODE=passwordderived (signup/login/ self-reset; OIDC bridge refused even with variables set) — SMTP-backed password reset belongs to that tier (see RUNNING.md). Core DOES carry SMTP config (mail.$DOMAIN:587as shared senderfcore, plus aNETGUARD_TRUSTED_HOSTSpin for split-horizon DNS): password reset is refused in oidc mode, but the notification engine's email channel needs the relay. 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_EMAILSaddress becomes ADMIN at first SSO login (ProvisionExternal); a fresh SSO user is USER. - Operator account:
docker exec -e SEED_EMAIL=admin@$DOMAIN 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
X-Forwarded-For (leftmost entry is client-supplied). Traefik does not set
X-Real-IP, so behind traefik either (a) leave TRUSTED_PROXY unset and
accept that all clients share one rate-limit bucket (web logs a startup
warning), or (b) do the small repo work item: derive the client IP from XFF
when pinned by trusted-entrypoint config (traefik forwardedHeaders.trustedIPs).
Decide before cutover; (a) is safe to start with.
SSO: configsso_superbrain (Authelia)
Follows the bookstack pattern in lib/bookstack.sh:
- Append a client to
/federated/apps/authelia/data/config/idproviders.yml:client_id: superbrain,claims_policy: superbrain,consent_mode: implicit,authorization_policy: one_factor, scopesopenid profile email,redirect_uris: [https://superbrain.$DOMAIN/api/auth/callback/authelia](the NextAuth provider id isauthelia), plus aclaims_policiesentrysuperbrain: {id_token: [email, email_verified, name, preferred_username]}— without it Authelia keepsemailout 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), validate withdocker exec authelia authelia validate-config --config /config/configuration.yml --config /config/idproviders.yml --config.experimental.filters template, thenrestart_service authelia. The uninstall path removes the claims block by its### Superbrain claimsmarker (marker + exactly 2 lines), drops a then-emptyclaims_policies:key, and must run BEFORE the client-block range deletion — that range starts at the first### Superbrainmatch. - Append
OIDC_ISSUER=https://authelia.$DOMAIN,OIDC_CLIENT_ID=superbrain,OIDC_CLIENT_SECRET=<create_password>to the app.env, thendocker compose up -d --force-recreate web— notrestart_service: compose does not recreate containers when only env_file content changed (hit in production 2026-10-25: web came up with zero OIDC vars and NextAuth returnederror=Configuration).
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, 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 — 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
The n8n-template config_mcpserver_superbrain (minting an HS256 public-API
JWT from deployment_key, inserting into user_api_keys, n8n scope list)
describes n8n's schema and does not apply to this codebase — Superbrain has no
equivalent long-lived API-key surface yet (browser sessions + 60s Bearer
assertions only). Remove it from lib/superbrain.sh until/unless Superbrain
grows a real API-key mechanism; revisit then.
Not applicable
email_superbrain: since the notification engine (2026-10-26) the app DOES send outbound mail through the house relay (SMTP_*= fcore submission on mail.$DOMAIN:587). The suite's standard welcome mail is still optional; superbrain's own mail is transactional only (notifications; password reset is refused in the oidc tier).data/volume: the app is stateless apart from postgres. No/home/node/.superbrainvolume (that was n8n's). Nothing tochown.
Cutover plan (existing ad-hoc directory → federated app)
Executed 2026-10-25. The ad-hoc stack never ran (no containers, no volumes, empty schema-only database), so there was no data to migrate:
- ✅ Verified the manual database was empty, dropped it and its user.
- ✅ Moved the ad-hoc dir to
/federated/tmp/superbrain-adhoc-20261025. - ✅ Staged fresh source at
/federated/tmp/superbrain-src, installedlib/superbrain.sh+services/superbrain/service. - ✅ Ran
/federated/bin/installapp superbrain(config → build → start → pdns → seed admin → Authelia SSO → monitors → superpanel catalog). - Remaining: verify
https://superbrain.$DOMAIN/login, admin login, traefik cert, monitor green (/federated/bin/check superbrain); link the admin account to SSO via oidc-link; soak; then delete the ad-hoc backup dir and the orphanedsuperbrain-{app,web}:latestimages from the earlier manual build.
Rollback: uninstallapp superbrain (drops the database, removes DNS,
Authelia client, images and app dir) and restore
/federated/tmp/superbrain-adhoc-20261025 if ever needed.
Repo work items (this repository)
- CI release workflow — on semver tags: build & push
superbrain-app,superbrain-web,superbrain-migrateto the chosen registry (single tag for all three +latest). Reuse the Dockerfiles; the migrate image isFROM postgres:16.15-alpine+COPY db /db+ bootstrap wrapper. db/bootstrap.sh— applyschema.sqlonly to an empty database, thenmigrate.sh. Wire it as the migrate image's command (composemigrateservice keeps working unchanged since initdb already applied schema.sql).- Rate-limit decision — XFF support behind traefik or accept the shared bucket (see caveat above).
- Nothing else in the repo needs to change; the compose stack,
make checkgate andscripts/deploy.sh(standalone non-federated deploys) stay as-is.
Suite-side work items (on core, via the federated git repo)
- Rewrite
/federated/lib/superbrain.sh— draft inlib-superbrain.shnext to this document. - Rewrite
/federated/services/superbrain/service— draft inservice. - Add
/federated/services/superbrain/upgrade/prethat runsdocker compose pullin the app dir (upgrade_app only pulls the app image). - Allocate the fixed
core-network IP (grep currentipv4_addressassignments across/federated/lib/*.shanddocker network inspect core). - Test the whole flow on a staging VM (or a second federated host) before
touching
core:installapp superbrain→ verify →upgrade superbrainwith a bumped VERSION → verify →uninstallapp superbrain.
Open questions
Registry→ decided: Docker Hubfederatedcomputer/*(house precedent); confirm the operator will grant CI push access (token/secret).- Confirm the
.93/.94/.95IP allocation with the operator (nothing currently references them, but allocation is centrally tracked). - Should
SIGNUP_ENABLEDstay 0 (operator-provisioned only) for suite tenants? - Product name/description/docs URL/icon for the superpanel catalog entry.
- Postgres 17.6 (shared) vs 16.15 (repo-pinned): run the integration suite against 17 once and decide whether the repo should widen its pin.