Move the Authelia stack (compose, config, snippets, docs) out of the separate /opt/authelia repo into authelia/, so the whole deployment shares ONE operator .env at the repo root. The four shared infra vars (TS_OAUTH_CLIENT_SECRET, TS_TAILNET, DB_MAGIC_NAME, REDIS_MAGIC_NAME) are defined once; authelia/.env is a symlink to ../.env (gitignored, recreated per host). .env.example + .gitignore folded in. Run from the repo root: docker compose -f authelia/docker-compose.yml up -d (or: cd authelia && docker compose up -d — the .env symlink makes it resolve). The standalone /opt/authelia is left intact as a history archive; remove once this is verified. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
4.5 KiB
CLAUDE.md — authelia
Guidance for Claude Code in this repo. Read before editing.
What this is
A standalone Authelia deployment — SSO portal, 2FA,
and (optional) OIDC provider — as a Tailscale sidecar, plugged into the shared
tailnet Postgres (storage) and Redis (sessions), with the shared SMTP
relay for reset/2FA mail. Sibling to tailwart; same pattern, different job.
Domain: infinidim.net (portal auth.infinidim.net).
Self-contained and outside any upstream repo (own .env, compose, config,
ACL snippet). Reads only the tailnet at runtime.
Architecture
main box Caddy (tag:reverse-proxy) tailnet-only auth
┌────────────────────────────┐ ┌───────────────────────┐
│ auth.infinidim.net ───────┼──────────────▶│ ts-authelia sidecar │
│ reverse_proxy :9091 │ tailnet │ authelia (no WAN, no │
│ protected vhosts: │ │ host ports) :9091 │
│ forward_auth → :9091 │ └──────────┬─────────────┘
└────────────────────────────┘ │
┌───────┴───────┐
▼ ▼ ▼
Postgres Redis SMTP relay
- Sidecar (
tag:authelia),network_mode: service:ts-authelia, no host ports. - Authelia listens
:9091on the tailnet. The main box Caddy (layer 7, not a separate edge) fronts the portal and wiresforward_authfor protected services — seecaddy-forward-auth.snippet. This is ordinary L7, unlike tailwart's L4 mail edge. - Storage → Postgres (
autheliarole/db), sessions → Redis (logical DBAUTHELIA_REDIS_DB), mail → shared relay.
The .env contract
.env (gitignored) is the whole surface. Secrets and infra hostnames reach
Authelia as AUTHELIA_* env overrides (set in docker-compose.yml), which
take precedence over config/configuration.yml. That keeps the committed yml
free of secrets and MagicDNS names. The yml holds only non-secret structure
(access_control, session.cookies, totp, regulation).
Prerequisites (shared tailnet infra)
- Postgres role+db:
authelia/AUTHELIA_DB_NAME. Create via a one-offCREATE ROLE authelia LOGIN PASSWORD '…'; CREATE DATABASE authelia OWNER authelia;againstthe-record-prod(the federatedSocial shared Postgres). - Redis: nothing to create — uses logical DB index
AUTHELIA_REDIS_DB(4) so it won't collide with the fediverse apps or tailwart (which uses 3). config/users_database.yml: at least one user with an argon2id hash:docker run --rm authelia/authelia:latest authelia crypto hash generate argon2 --password 'PASS'.- Admin console: assign
tag:autheliato the OAuth client (Devices/Core + Keys/AuthKeys) and addacl-snippet.hujsonto the policy. - Main box Caddy: add
caddy-forward-auth.snippet(portal vhost + the(authelia)import) and a cert forauth.infinidim.net.
Pitfalls
- Authelia config schema drifts hard between minor versions (4.37→4.38 moved
session to
cookies[], addedidentity_validation, changedstorage.postgrestoaddress). The image is pinned to 4.39.20 and the yml passesauthelia config validateagainst it. Re-validate before bumping the tag:docker run --rm -e ... -v ./config:/config:ro authelia/authelia:<tag> authelia config validate. - Don't put secrets in
configuration.yml. Use theAUTHELIA_*env path. - Redis DB index collisions. tailwart=3, authelia=4. Keep them distinct.
- Postgres password drift. Role passwords only apply on
CREATE/ALTER; test auth over the tailnet (scram), never127.0.0.1(that pg_hba line istrustand accepts any password — it'll lie to you). - forward_auth is layer 7, on the main Caddy. Don't confuse it with tailwart's L4 edge — different mechanism entirely.
What not to do
- Don't write into
/opt/federatedSocial(read its.envif needed). - Don't add
ports:to the Authelia container — the main Caddy is the only public path in. - Don't commit
.env. - Don't break the sidecar netns boundary.