Track HiveGrid Cloud planning reference

This commit is contained in:
david committed 2026-06-26 20:48:01 +02:00
1 parent b3d5ea6764
commit e341c5938a
5784 files changed
+1104929 -3

No files matched your search

+115
View File
@@ -0,0 +1,115 @@
# infra/authentik/.env.example
#
# Copy to `.env` and fill before deploying via Coolify. Never commit the real
# .env — it is git-ignored (see .gitignore). Use Coolify's secret vault to
# manage production values; this file is only the template.
#
# Generate the secrets ONCE with the commands listed inline. Losing
# AUTHENTIK_SECRET_KEY destroys the encrypted-fields + active sessions of
# the entire instance — back it up to an offline password vault.
# -----------------------------------------------------------------------------
# Authentik image pin (mirrors UPSTREAM.md)
# -----------------------------------------------------------------------------
AUTHENTIK_TAG=2026.2.3
# -----------------------------------------------------------------------------
# Public URL — must match the Traefik-routed hostname (see traefik.labels.yml)
# -----------------------------------------------------------------------------
AUTHENTIK_BASE_URL=https://auth.boiler.saas-ctrl.com
# Optional: cookie domain for cross-subdomain SSO (only set if you have
# multiple boiler.saas-ctrl.com subdomains that should share the IdP cookie).
AUTHENTIK_COOKIE_DOMAIN=
# -----------------------------------------------------------------------------
# Authentik secret key — THE MOST IMPORTANT SECRET
# -----------------------------------------------------------------------------
# Generate ONCE with: openssl rand -base64 60
# Losing this key invalidates all session cookies AND makes encrypted fields
# (OIDC provider client_secrets, password-stage encrypted user data, etc.)
# unreadable. Store it in Coolify-Vault AND in an offline password vault
# (1Password / Bitwarden / Yubikey). Cannot be rotated without full reinstall.
AUTHENTIK_SECRET_KEY=replace-me-with-60-bytes-of-base64-entropy
# -----------------------------------------------------------------------------
# Postgres (Authentik-internal, NOT shared with the boilerplate app)
# -----------------------------------------------------------------------------
AUTHENTIK_POSTGRESQL__USER=authentik
AUTHENTIK_POSTGRESQL__NAME=authentik
# Generate with: openssl rand -base64 32
AUTHENTIK_POSTGRESQL__PASSWORD=replace-me-strong-postgres-password
# -----------------------------------------------------------------------------
# Initial admin bootstrap — forced password change on first login
# -----------------------------------------------------------------------------
AUTHENTIK_BOOTSTRAP_EMAIL=ops@example.com
# Generate with: openssl rand -base64 24
# Operator MUST change this on first login via the Authentik UI.
AUTHENTIK_BOOTSTRAP_PASSWORD=replace-me-strong-bootstrap-password
# API-token for bootstrap-time blueprint loading. Generate with:
# openssl rand -hex 32
# After bootstrap.sh succeeds, rotate or delete this token via the Authentik
# admin UI (Directory → Tokens). It grants full admin-API access.
AUTHENTIK_BOOTSTRAP_TOKEN=replace-me-64-hex-chars
# -----------------------------------------------------------------------------
# Telemetry / privacy
# -----------------------------------------------------------------------------
# Disable error-reporting to goauthentik.io — we already have our own Sentry
# (see AUTHENTIK_SENTRY__DSN below) and don't want to leak prod-stack info to
# upstream.
AUTHENTIK_ERROR_REPORTING__ENABLED=false
AUTHENTIK_DISABLE_UPDATE_CHECK=true
AUTHENTIK_DISABLE_STARTUP_ANALYTICS=true
AUTHENTIK_LOG_LEVEL=info
# -----------------------------------------------------------------------------
# Sentry self-hosted DSN (Phase 02 #29). Optional — leave blank to disable.
# DSN format: https://<key>@sentry.boiler.saas-ctrl.com/<project-id>
# Create a "boilerplate-authentik" project in the Sentry UI and paste its DSN.
# -----------------------------------------------------------------------------
AUTHENTIK_SENTRY__DSN=
AUTHENTIK_SENTRY__ENVIRONMENT=staging
# -----------------------------------------------------------------------------
# Email — required for password recovery / email-stage flows
# Leave HOST blank to disable email features; the bootstrap admin can still
# log in via the bootstrap password.
# -----------------------------------------------------------------------------
AUTHENTIK_EMAIL__HOST=
AUTHENTIK_EMAIL__PORT=587
AUTHENTIK_EMAIL__USERNAME=
AUTHENTIK_EMAIL__PASSWORD=
AUTHENTIK_EMAIL__USE_TLS=true
AUTHENTIK_EMAIL__USE_SSL=false
AUTHENTIK_EMAIL__TIMEOUT=10
AUTHENTIK_EMAIL__FROM=authentik@boiler.saas-ctrl.com
# -----------------------------------------------------------------------------
# OIDC client secret for the Toolctrl admin-panel provider
# (loaded by bootstrap/blueprints/03-application-toolctrl-admin.yaml)
# Generate with: openssl rand -hex 32
# After bootstrap, copy this secret into the admin-panel app's .env as
# AUTHENTIK_OIDC_CLIENT_SECRET (consumed in Phase 09 #82).
# -----------------------------------------------------------------------------
TOOLCTRL_ADMIN_OIDC_CLIENT_ID=toolctrl-admin-panel
TOOLCTRL_ADMIN_OIDC_CLIENT_SECRET=replace-me-64-hex-chars
TOOLCTRL_ADMIN_OIDC_REDIRECT_URI=https://admin.boiler.saas-ctrl.com/auth/callback
# -----------------------------------------------------------------------------
# S3 backup target (consumed by infra/authentik/backup/)
# Endpoint format examples:
# Hetzner: https://nbg1.your-objectstorage.com
# AWS: https://s3.eu-central-1.amazonaws.com
# MinIO local: https://minio.boiler.saas-ctrl.com
# -----------------------------------------------------------------------------
AUTHENTIK_S3_BACKUP_ENDPOINT=https://nbg1.your-objectstorage.com
AUTHENTIK_S3_BACKUP_BUCKET=boilerplate-authentik-backups
AUTHENTIK_S3_BACKUP_ACCESS_KEY=replace-me
AUTHENTIK_S3_BACKUP_SECRET_KEY=replace-me
# Optional: GPG recipient fingerprint to encrypt the backups with before
# upload. If left empty, backup.sh falls back to AES256-symmetric with
# AUTHENTIK_SECRET_KEY as passphrase (better than plaintext, but rotate
# carefully — losing the key destroys the backup readability).
AUTHENTIK_BACKUP_GPG_RECIPIENT=
+16
View File
@@ -0,0 +1,16 @@
# Runtime data — never commit
data/
postgres-data/
redis-data/
media/
custom-templates/
certs/
# Secrets
*.env
!.env.example
secrets/
# Local helper artifacts
*.log
.DS_Store
+95
View File
@@ -0,0 +1,95 @@
# `infra/authentik` — Self-Hosted Authentik IdP Stack
This directory contains the artifacts to deploy a **self-hosted Authentik**
identity-provider instance on the staging Hetzner host (`boilerplate-staging`,
see `docs/improvement-plan/archive/STAGING-ACCESS.md`) via the existing
Coolify-managed Docker-Compose runtime.
## Purpose
- Centralise **admin authentication** behind an external IdP (Phase 09 #82)
instead of trusting the application's own user table
- Enforce **MFA-TOTP for super-admins** at the IdP layer (group-policy)
- Provide a **group-based access model** (`toolctrl-admin`, `toolctrl-staff`,
`toolctrl-users`) that the admin panel + future tenant-SSO consume
- Provide a **federation target** for the Backlog #66 customer-tenant-SSO
(second OIDC provider definition is shipped as a disabled placeholder)
- Aggregate **auth-audit events** (login / logout / mfa-enroll /
group-change) so they can be ingested by the Phase 10 audit-log (#67)
The companion ultra-lite alternative (GLAuth, LDAP-only, ~50 MB RAM) is
documented in `docs/operations/authentik-alternatives.md` and is **not**
the default — it lacks OIDC, MFA-enforcement, brand-flows, and blueprints.
## Prerequisites
- Hetzner host with **≥ 2 GB RAM free for the Authentik stack**
(server: ~600 MB, worker: ~400 MB, postgres: ~300 MB, redis: ~150 MB,
plus headroom). The staging host has 30 GiB RAM with plenty of headroom.
- Docker Engine ≥ 24 + Docker Compose v2 (provided by Coolify)
- Traefik v3.6 reverse-proxy from `coolify-proxy` (Let's Encrypt ACME via
the `letsencrypt` cert-resolver)
- DNS record `auth.boiler.saas-ctrl.com` → `46.225.5.93`
(Cloudflare-managed; see `docs/operations/authentik-setup.md` for the
`cf-cli` snippet that creates it)
- Sentry self-hosted stack from Phase 02 #29 reachable at
`sentry.boiler.saas-ctrl.com` (Authentik containers report their own
errors to it via `AUTHENTIK_SENTRY__DSN`)
## Layout
```
infra/authentik/
├── README.md # this file
├── .gitignore # excludes runtime volumes + secrets
├── UPSTREAM.md # pinned Authentik tag + image pin rationale
├── docker-compose.yml # 4-service compose: server, worker, postgresql, redis
├── traefik.labels.yml # canonical Traefik label-set for auth.<domain>
├── .env.example # template for AUTHENTIK_* secrets
├── bootstrap/
│ ├── bootstrap.sh # waits for /-/health/ready/ then loads blueprints
│ └── blueprints/
│ ├── 01-groups.yaml # toolctrl-admin / -staff / -users groups + attrs
│ ├── 02-policies.yaml # password policy + MFA-enforce + brute-force
│ └── 03-application-toolctrl-admin.yaml # OIDC provider for admin panel
├── backup/ # daily backup container
│ ├── Dockerfile
│ ├── backup.sh
│ └── crontab
└── scripts/
└── smoke.sh # post-deploy smoke checks (curl-only)
```
## Deploy
See `docs/operations/authentik-setup.md` for the full Coolify-deploy + DNS +
backup + restore runbook. **Deployment is operator-owned** — this directory
ships the artifacts; the operator runs the Coolify side.
High-level:
1. Operator creates the Coolify "Docker Compose" service against this repo
pointing at `infra/authentik/docker-compose.yml`.
2. Operator copies `.env.example` → Coolify-Vault and fills in secrets
(`AUTHENTIK_SECRET_KEY` from `openssl rand -base64 60`, etc.).
3. Coolify deploy boots postgres, redis, then `server` + `worker`.
4. Operator runs `bootstrap/bootstrap.sh` once against the running stack
to apply blueprints (groups + policies + admin-panel OIDC provider).
5. Operator runs `scripts/smoke.sh` to verify TLS, health, OIDC discovery.
## Versioning
- Authentik pin: `ghcr.io/goauthentik/server:2026.2.3` and
`ghcr.io/goauthentik/proxy:2026.2.3` (see `UPSTREAM.md` for rationale).
- Postgres pin: `postgres:16-alpine`.
- Redis pin: `redis:7-alpine`.
## Scope
- Authentik **server** + **worker** + dedicated **postgresql** + dedicated
**redis** — these databases MUST NOT be shared with the boilerplate
application's own Postgres/Redis (separate compromise blast-radius +
separate backup/restore cycle).
- **No Outposts** — pure OIDC use-case; the reverse-proxy outpost concept
is intentionally out of scope for this phase.
- **No public self-registration** — admin-only invitation flow.
@@ -0,0 +1,52 @@
# Upstream Pin: `goauthentik/authentik`
## Pinned Version
| Field | Value |
| --- | --- |
| Upstream repo | <https://github.com/goauthentik/authentik> |
| Pinned image tag | **`2026.2.3`** |
| Image registry | `ghcr.io/goauthentik/server:2026.2.3` (web/api) and `ghcr.io/goauthentik/proxy:2026.2.3` (optional reverse-proxy outpost, NOT used in this phase) |
| Release line | `2026.2.x` (the latest stable line as of 2026-05-17 per `gh release list --repo goauthentik/authentik`) |
| Why not `2026.5.0-rc2` | RC; we wait for the GA promotion of the `2026.5.x` line before upgrading. |
| Why not `2025.12.5` | Older minor; `2026.2.3` is the latest stable and contains the security + flow-stage fixes we care about. |
| Postgres image | `postgres:16-alpine` (Authentik supports 14/15/16; we standardise on 16 to match the rest of the boilerplate) |
| Redis image | `redis:7-alpine` |
## Why we DO vendor the compose
Unlike the Sentry stack (which has ~70 upstream services and a non-trivial
install script), Authentik's compose surface is small: **4 services**
(server, worker, postgresql, redis). We author our own `docker-compose.yml`
based on the upstream reference at
<https://goauthentik.io/docs/install-config/install/docker-compose> so that:
- Our network topology (Coolify `coolify` external network + internal
`authentik-net`) is explicit, not merged at runtime.
- Volume paths are pinned onto Coolify's `/data/coolify/services/authentik/`
disk plane so backups + log-rotation use the same path as every other
Coolify stack.
- The Postgres + Redis instances stay strictly **Authentik-internal** —
we never share them with the boilerplate app's databases.
- No `ports:` mappings for Postgres/Redis → only reachable on the internal
Docker network.
## Update procedure
To upgrade to a newer `2026.2.x` patch:
1. Update the tag in this file and in `docker-compose.yml`
(`image: ghcr.io/goauthentik/server:<new-tag>` on both `server` and
`worker`).
2. Read upstream release notes
(<https://github.com/goauthentik/authentik/releases>) for any blueprint
schema changes; sync our blueprints in `bootstrap/blueprints/` if any
field was renamed/removed.
3. On staging, trigger a Coolify redeploy of the `authentik` stack. Volumes
are preserved; the `server` container runs schema migrations on boot.
4. Smoke-test via `scripts/smoke.sh` (TLS, health, OIDC discovery).
5. Commit the bumped tag + blueprint deltas as one commit.
For a major version jump (e.g. `2026.2.x → 2026.5.x`) see the runbook in
`docs/operations/authentik-setup.md` — that one is a manual operation
(pre-update backup mandatory; blueprint schema may have shifted).
@@ -0,0 +1,58 @@
# infra/authentik/backup/Dockerfile
#
# Sidecar container that backs up the self-hosted Authentik stack daily:
# - pg_dump --format=custom of the Authentik Postgres
# - tar of the `authentik-media` volume (uploaded user-avatars, branding
# assets, exported blueprints)
# - SECRETS-MANIFEST.txt listing the names of secrets that MUST be backed
# up separately (AUTHENTIK_SECRET_KEY, POSTGRES password, BOOTSTRAP token)
# since the Postgres dump alone is useless without them
# - all artifacts GPG-encrypted (or AES256-symmetric fallback) before
# upload to S3
#
# Triggered by an internal cron (see crontab) so the container stays running
# in the background. Re-uses postgres16-client (matches the postgres:16-alpine
# pin in docker-compose.yml).
FROM alpine:3.20
# --- Runtime deps ------------------------------------------------------------
# postgresql16-client -> pg_dump
# aws-cli -> S3 upload (works with Hetzner Object Storage + MinIO via --endpoint-url)
# rclone -> alternative S3 backend (handy for MinIO-compat)
# gnupg -> GPG encryption of dumps
# tini -> proper signal-handling as PID 1
# bash, coreutils -> POSIX-strict scripts need real coreutils
# tzdata -> consistent UTC timestamps
# busybox-extras (crond)
# curl -> health probe
RUN apk add --no-cache \
postgresql16-client \
aws-cli \
rclone \
gnupg \
tini \
bash \
coreutils \
tar \
tzdata \
busybox-extras \
curl \
&& rm -rf /var/cache/apk/*
ENV TZ=UTC \
BACKUP_HOME=/srv/backup \
PATH=/srv/backup:$PATH
WORKDIR ${BACKUP_HOME}
COPY backup.sh ${BACKUP_HOME}/backup.sh
COPY crontab /etc/crontabs/root
RUN chmod 0755 ${BACKUP_HOME}/backup.sh \
&& mkdir -p ${BACKUP_HOME}/logs ${BACKUP_HOME}/work
# Run cron in the foreground; tini handles SIGTERM cleanly so `docker compose
# down` doesn't strand a half-finished dump.
ENTRYPOINT ["/sbin/tini", "--"]
CMD ["crond", "-f", "-L", "/dev/stdout", "-l", "2"]
+176
View File
@@ -0,0 +1,176 @@
#!/usr/bin/env bash
# infra/authentik/backup/backup.sh
#
# Daily backup of the self-hosted Authentik stack. Triggered by crond at 03:30
# UTC (see crontab). Idempotent — re-running on the same day overwrites the
# same S3 prefix.
#
# Steps:
# 1. pg_dump --format=custom of the Authentik Postgres
# 2. tar of /media (Authentik media volume, mounted into this container)
# 3. SECRETS-MANIFEST.txt listing the env-var names that MUST be backed up
# out-of-band (Coolify-Vault export)
# 4. GPG-encrypt all three artifacts (recipient OR AES256 fallback)
# 5. Upload to S3 under s3://<bucket>/authentik/YYYY-MM-DD/
#
# Env (sourced from the Compose service `environment` block, which itself
# reads from infra/authentik/.env):
# AUTHENTIK_S3_BACKUP_ENDPOINT S3 endpoint URL
# AUTHENTIK_S3_BACKUP_BUCKET target bucket name
# AUTHENTIK_S3_BACKUP_ACCESS_KEY S3 access key
# AUTHENTIK_S3_BACKUP_SECRET_KEY S3 secret key
# AUTHENTIK_SECRET_KEY fallback symmetric passphrase for GPG
# AUTHENTIK_BACKUP_GPG_RECIPIENT optional GPG recipient fingerprint
#
# AUTHENTIK_PG_HOST default "postgresql" (compose service name)
# AUTHENTIK_PG_PORT default 5432
# AUTHENTIK_POSTGRESQL__USER default "authentik"
# AUTHENTIK_POSTGRESQL__NAME default "authentik"
# AUTHENTIK_POSTGRESQL__PASSWORD required (read via PGPASSWORD env)
set -Eeuo pipefail
shopt -s inherit_errexit 2>/dev/null || true
# -----------------------------------------------------------------------------
# Defaults + required-env guard
# -----------------------------------------------------------------------------
: "${AUTHENTIK_PG_HOST:=postgresql}"
: "${AUTHENTIK_PG_PORT:=5432}"
: "${AUTHENTIK_POSTGRESQL__USER:=authentik}"
: "${AUTHENTIK_POSTGRESQL__NAME:=authentik}"
: "${AUTHENTIK_S3_BACKUP_ENDPOINT:?AUTHENTIK_S3_BACKUP_ENDPOINT is required}"
: "${AUTHENTIK_S3_BACKUP_BUCKET:?AUTHENTIK_S3_BACKUP_BUCKET is required}"
: "${AUTHENTIK_S3_BACKUP_ACCESS_KEY:?AUTHENTIK_S3_BACKUP_ACCESS_KEY is required}"
: "${AUTHENTIK_S3_BACKUP_SECRET_KEY:?AUTHENTIK_S3_BACKUP_SECRET_KEY is required}"
: "${AUTHENTIK_POSTGRESQL__PASSWORD:?AUTHENTIK_POSTGRESQL__PASSWORD is required}"
TODAY="$(date -u +%Y-%m-%d)"
NOW="$(date -u +%Y-%m-%dT%H-%M-%SZ)"
WORK="${BACKUP_HOME:-/srv/backup}/work/${TODAY}"
mkdir -p "${WORK}"
log() { printf "[authentik-backup %s] %s\n" "${NOW}" "$*"; }
cleanup() { rm -rf "${WORK}"; }
trap cleanup EXIT
# -----------------------------------------------------------------------------
# Step 1: Postgres dump
# -----------------------------------------------------------------------------
log "dumping Postgres (${AUTHENTIK_PG_HOST}/${AUTHENTIK_POSTGRESQL__NAME})"
PG_DUMP_FILE="${WORK}/authentik-postgres-${NOW}.dump"
export PGPASSWORD="${AUTHENTIK_POSTGRESQL__PASSWORD}"
pg_dump \
--host "${AUTHENTIK_PG_HOST}" \
--port "${AUTHENTIK_PG_PORT}" \
--username "${AUTHENTIK_POSTGRESQL__USER}" \
--dbname "${AUTHENTIK_POSTGRESQL__NAME}" \
--format=custom \
--compress=9 \
--no-owner \
--no-privileges \
--file "${PG_DUMP_FILE}"
log "postgres dump size: $(du -h "${PG_DUMP_FILE}" | cut -f1)"
# -----------------------------------------------------------------------------
# Step 2: media volume tar
# -----------------------------------------------------------------------------
MEDIA_TAR="${WORK}/authentik-media-${NOW}.tar.gz"
if [[ -d /media ]]; then
log "archiving /media"
tar -czf "${MEDIA_TAR}" -C / media || log "media tar exited non-zero (continuing)"
log "media archive size: $(du -h "${MEDIA_TAR}" | cut -f1)"
else
log "/media not mounted in backup container — skipping media tar"
MEDIA_TAR=""
fi
# -----------------------------------------------------------------------------
# Step 3: SECRETS-MANIFEST.txt
# -----------------------------------------------------------------------------
# CRITICAL: without these secrets the Postgres dump is useless — Authentik
# encrypts OIDC provider client_secrets, password-stage data, etc. with
# AUTHENTIK_SECRET_KEY. Restoring a dump against a fresh instance with a
# DIFFERENT key will leave you with unreadable encrypted fields.
SECRETS_MANIFEST="${WORK}/SECRETS-MANIFEST-${NOW}.txt"
cat > "${SECRETS_MANIFEST}" <<EOF
Authentik Backup — SECRETS MANIFEST (${NOW})
The following secrets are REQUIRED to restore this backup. They are NOT
included in the Postgres dump. Back them up separately from Coolify-Vault
(or your equivalent secret-store) to an offline password vault.
REQUIRED for restore:
- AUTHENTIK_SECRET_KEY
Decrypts all Authentik-encrypted fields. CANNOT BE ROTATED without
destroying all encrypted-field data (sessions, OIDC client secrets,
password-stage data). Loss = full re-onboarding of all admin users.
- AUTHENTIK_POSTGRESQL__PASSWORD
Used by the new Authentik instance to connect to the restored Postgres.
- AUTHENTIK_BOOTSTRAP_TOKEN
Optional but useful for re-bootstrapping blueprints via API.
OPTIONAL but recommended:
- TOOLCTRL_ADMIN_OIDC_CLIENT_SECRET
The OIDC provider's client_secret is stored encrypted in Postgres;
the plaintext lives in Coolify-Vault and in the boilerplate app's
.env (consumed by Phase 09 #82).
- AUTHENTIK_SENTRY__DSN
If you ship error-reporting to the self-hosted Sentry.
- AUTHENTIK_EMAIL__PASSWORD
SMTP credentials for recovery mail.
Postgres dump artifact: $(basename "${PG_DUMP_FILE}")
Media archive: $([ -n "${MEDIA_TAR}" ] && basename "${MEDIA_TAR}" || echo "n/a")
EOF
# -----------------------------------------------------------------------------
# Step 4: encrypt
# -----------------------------------------------------------------------------
encrypt() {
local src="$1"
local dst="${src}.gpg"
if [[ -n "${AUTHENTIK_BACKUP_GPG_RECIPIENT:-}" ]]; then
log "encrypting ${src##*/} to GPG recipient ${AUTHENTIK_BACKUP_GPG_RECIPIENT}"
gpg --batch --yes --trust-model always --recipient "${AUTHENTIK_BACKUP_GPG_RECIPIENT}" \
--output "${dst}" --encrypt "${src}"
else
log "encrypting ${src##*/} symmetrically (AES256) with AUTHENTIK_SECRET_KEY"
gpg --batch --yes --symmetric --cipher-algo AES256 \
--passphrase "${AUTHENTIK_SECRET_KEY:?AUTHENTIK_SECRET_KEY missing for symmetric fallback}" \
--output "${dst}" "${src}"
fi
rm -f "${src}"
printf "%s" "${dst}"
}
PG_ENCRYPTED="$(encrypt "${PG_DUMP_FILE}")"
SECRETS_ENCRYPTED="$(encrypt "${SECRETS_MANIFEST}")"
if [[ -n "${MEDIA_TAR:-}" && -f "${MEDIA_TAR}" ]]; then
MEDIA_ENCRYPTED="$(encrypt "${MEDIA_TAR}")"
else
MEDIA_ENCRYPTED=""
fi
# -----------------------------------------------------------------------------
# Step 5: upload to S3
# -----------------------------------------------------------------------------
export AWS_ACCESS_KEY_ID="${AUTHENTIK_S3_BACKUP_ACCESS_KEY}"
export AWS_SECRET_ACCESS_KEY="${AUTHENTIK_S3_BACKUP_SECRET_KEY}"
export AWS_EC2_METADATA_DISABLED=true
S3_PREFIX="s3://${AUTHENTIK_S3_BACKUP_BUCKET}/authentik/${TODAY}"
log "uploading to ${S3_PREFIX}/"
aws s3 cp --endpoint-url "${AUTHENTIK_S3_BACKUP_ENDPOINT}" "${PG_ENCRYPTED}" "${S3_PREFIX}/$(basename "${PG_ENCRYPTED}")"
aws s3 cp --endpoint-url "${AUTHENTIK_S3_BACKUP_ENDPOINT}" "${SECRETS_ENCRYPTED}" "${S3_PREFIX}/$(basename "${SECRETS_ENCRYPTED}")"
if [[ -n "${MEDIA_ENCRYPTED}" ]]; then
aws s3 cp --endpoint-url "${AUTHENTIK_S3_BACKUP_ENDPOINT}" "${MEDIA_ENCRYPTED}" "${S3_PREFIX}/$(basename "${MEDIA_ENCRYPTED}")"
fi
log "authentik backup complete for ${TODAY}"
@@ -0,0 +1,15 @@
# infra/authentik/backup/crontab
#
# Daily Authentik backup. Times are UTC (TZ set in the Dockerfile).
# Format: m h dom mon dow command
#
# 03:30 UTC = quiet hour for both EU/US active windows. Authentik's worker
# doesn't have a heavy nightly job; we co-locate with the Sentry backup time
# (which also runs at 03:30 in infra/sentry/backup/crontab) for consistent
# operator runbooks.
30 3 * * * /srv/backup/backup.sh >> /srv/backup/logs/backup-$(date -u +\%Y\%m\%d).log 2>&1
# Heartbeat — write an "alive" marker hourly so operators can confirm crond
# is actually running inside the container.
0 * * * * date -u +%Y-%m-%dT%H:%M:%SZ > /srv/backup/logs/heartbeat.txt
@@ -0,0 +1,55 @@
# infra/authentik/bootstrap/blueprints/01-groups.yaml
#
# Authentik Blueprint — declarative group setup.
#
# Loaded by the worker on boot (mounted at /blueprints/toolctrl/01-groups.yaml
# via docker-compose.yml). Blueprints in /blueprints/* are evaluated by
# Authentik at startup and applied idempotently — re-applying the same
# blueprint is a no-op if entities already exist with the same `identifiers`.
#
# Spec: https://goauthentik.io/docs/customize/blueprints
#
# Groups created:
# - toolctrl-admin (attribute role=super_admin) — full Toolctrl super-admin
# - toolctrl-staff (attribute role=staff) — restricted admin (read +
# limited write per app rules)
# - toolctrl-users (attribute role=user) — placeholder for future
# customer-tenant-SSO (#66);
# no app uses this today
version: 1
metadata:
labels:
blueprints.goauthentik.io/instantiate: "true"
name: "Toolctrl Groups"
entries:
- identifiers:
name: toolctrl-admin
model: authentik_core.group
state: present
attrs:
is_superuser: false # we use the group attr, NOT Authentik's built-in superuser flag
attributes:
role: super_admin
toolctrl_managed: true
- identifiers:
name: toolctrl-staff
model: authentik_core.group
state: present
attrs:
is_superuser: false
attributes:
role: staff
toolctrl_managed: true
- identifiers:
name: toolctrl-users
model: authentik_core.group
state: present
attrs:
is_superuser: false
attributes:
role: user
toolctrl_managed: true
@@ -0,0 +1,111 @@
# infra/authentik/bootstrap/blueprints/02-policies.yaml
#
# Authentik Blueprint — security policies.
#
# Policies created:
# 1. toolctrl-password-policy
# - min 12 chars, mixed case + digit + symbol, no common-password dict
# - applied to the default password stage so every password set / reset
# goes through this gate
# 2. toolctrl-require-mfa-totp-for-admin (expression policy)
# - returns ak_message + denies the auth flow if a user in
# toolctrl-admin tries to authenticate without a verified TOTP factor
# - attached to the admin OIDC application access binding
# 3. toolctrl-bruteforce-lockout (reputation policy)
# - 5 failed authentication attempts in 1 minute from the same IP
# drops the reputation score below threshold and triggers a
# 15-minute IP lockout via the default reputation policy chain
#
# Note: the bind objects (PolicyBinding) are created against the default
# password stage and the admin application, but the admin-application binding
# only takes effect AFTER 03-application-toolctrl-admin.yaml has been
# applied (Authentik resolves cross-blueprint references on each apply pass;
# you may see a single retry on the first boot, which is normal).
version: 1
metadata:
labels:
blueprints.goauthentik.io/instantiate: "true"
name: "Toolctrl Policies"
entries:
# ---------- 1. Password policy ----------------------------------------
- identifiers:
name: toolctrl-password-policy
model: authentik_policies_password.passwordpolicy
state: present
attrs:
execution_logging: true
password_field: password
amount_uppercase: 1
amount_lowercase: 1
amount_digits: 1
amount_symbols: 1
length_min: 12
symbol_charset: "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"
error_message: "Password must be at least 12 characters and contain upper, lower, digit, and symbol."
check_static_rules: true
check_have_i_been_pwned: true
check_zxcvbn: true
zxcvbn_score_threshold: 3
hibp_allowed_count: 0
# Bind the password policy to the default password-change Flow so every
# new password / reset goes through it. Authentik 2026.x rejects binding
# a PolicyBinding.target to a Stage directly (Stage is not a
# PolicyBindingModel subclass); we target the Flow instead which IS a PBM
# and applies to all stages inside it. See B-007.
- identifiers:
target: !Find [authentik_flows.flow, [slug, default-password-change]]
policy: !Find [authentik_policies_password.passwordpolicy, [name, toolctrl-password-policy]]
order: 0
model: authentik_policies.policybinding
state: present
attrs:
enabled: true
# ---------- 2. Require MFA-TOTP for toolctrl-admin --------------------
- identifiers:
name: toolctrl-require-mfa-totp-for-admin
model: authentik_policies_expression.expressionpolicy
state: present
attrs:
execution_logging: true
expression: |
# Returns True (allow) only if the user is NOT in toolctrl-admin,
# OR the user has a verified TOTP factor attached.
# If they are in toolctrl-admin and have no TOTP, deny + message.
from authentik.stages.authenticator_totp.models import TOTPDevice
is_admin = ak_is_group_member(request.user, name="toolctrl-admin")
if not is_admin:
return True
has_totp = TOTPDevice.objects.filter(user=request.user, confirmed=True).exists()
if not has_totp:
ak_message("MFA-TOTP is required for super-admin accounts. Enroll a TOTP device first.")
return False
return True
# ---------- 3. Brute-force lockout (reputation policy) ----------------
- identifiers:
name: toolctrl-bruteforce-lockout
model: authentik_policies_reputation.reputationpolicy
state: present
attrs:
execution_logging: true
check_ip: true
check_username: true
# Reputation drops by 1 per failed login; -5 in 1min triggers the
# default flow-level deny. Authentik's built-in reputation policy chain
# applies a 15min cool-down before reputation recovers.
threshold: -5
# Bind the brute-force policy to the default authentication flow so it
# runs on every login attempt.
- identifiers:
target: !Find [authentik_flows.flow, [slug, default-authentication-flow]]
policy: !Find [authentik_policies_reputation.reputationpolicy, [name, toolctrl-bruteforce-lockout]]
order: 10
model: authentik_policies.policybinding
state: present
attrs:
enabled: true
@@ -0,0 +1,141 @@
# infra/authentik/bootstrap/blueprints/03-application-toolctrl-admin.yaml
#
# Authentik Blueprint — OIDC provider + application for the Toolctrl
# admin panel. Consumed by Phase 09 task #82 (admin-panel OIDC login).
#
# Creates:
# - OIDC Provider `toolctrl-admin-panel`
# * client_type=confidential
# * client_id from env (TOOLCTRL_ADMIN_OIDC_CLIENT_ID)
# * client_secret from env (TOOLCTRL_ADMIN_OIDC_CLIENT_SECRET)
# * scope_mappings: openid, email, profile, groups
# * subject_mode=hashed_user_id (avoids leaking the Authentik integer PK)
# * token TTLs: code 1m, access 10m, refresh 7d, id-token 10m
# * include_claims_in_id_token=true
# - Application `Toolctrl Admin Panel`
# * launchURL points at https://admin.boiler.saas-ctrl.com/
# * Access binding: only members of toolctrl-admin OR toolctrl-staff
#
# Also creates a DISABLED placeholder provider `toolctrl-tenant-sso` reserved
# for Backlog #66. It is created with enabled=false so it occupies the slug
# without affecting routing. When #66 is picked up, just flip `enabled` and
# add the per-tenant redirect_uri templates.
version: 1
metadata:
labels:
blueprints.goauthentik.io/instantiate: "true"
name: "Toolctrl Admin Panel OIDC"
context:
client_id: "%(env:TOOLCTRL_ADMIN_OIDC_CLIENT_ID)s"
client_secret: "%(env:TOOLCTRL_ADMIN_OIDC_CLIENT_SECRET)s"
redirect_uri: "%(env:TOOLCTRL_ADMIN_OIDC_REDIRECT_URI)s"
entries:
# ---------- Signing key (use the bundled self-signed by default) -----
# Authentik ships a `authentik Self-signed Certificate` after install; we
# reference it by name so the blueprint applies cleanly on a fresh boot.
# ---------- OIDC Provider: toolctrl-admin-panel ----------------------
- identifiers:
name: toolctrl-admin-panel
model: authentik_providers_oauth2.oauth2provider
state: present
attrs:
client_type: confidential
client_id: !Context client_id
client_secret: !Context client_secret
authorization_flow: !Find [authentik_flows.flow, [slug, default-provider-authorization-implicit-consent]]
authentication_flow: !Find [authentik_flows.flow, [slug, default-authentication-flow]]
invalidation_flow: !Find [authentik_flows.flow, [slug, default-provider-invalidation-flow]]
property_mappings:
- !Find [authentik_providers_oauth2.scopemapping, [scope_name, openid]]
- !Find [authentik_providers_oauth2.scopemapping, [scope_name, email]]
- !Find [authentik_providers_oauth2.scopemapping, [scope_name, profile]]
property_mappings_group:
- !Find [authentik_providers_oauth2.scopemapping, [scope_name, openid]]
signing_key: !Find [authentik_crypto.certificatekeypair, [name, authentik Self-signed Certificate]]
sub_mode: hashed_user_id
include_claims_in_id_token: true
issuer_mode: per_provider
# Authentik 2026.x changed redirect_uris from a string to a list of
# {matching_mode, url} dicts (RedirectURI dataclass). See B-007.
redirect_uris:
- matching_mode: strict
url: !Context redirect_uri
# Short-lived auth code + access token; longer refresh window for
# admin-panel sessions (operator can revoke in Authentik UI).
access_code_validity: minutes=1
access_token_validity: minutes=10
refresh_token_validity: days=7
# ---------- Application: Toolctrl Admin Panel -------------------------
- identifiers:
slug: toolctrl-admin-panel
model: authentik_core.application
state: present
attrs:
name: "Toolctrl Admin Panel"
provider: !Find [authentik_providers_oauth2.oauth2provider, [name, toolctrl-admin-panel]]
meta_launch_url: "https://admin.boiler.saas-ctrl.com/"
meta_description: "Toolctrl admin panel — super-admin + staff console"
policy_engine_mode: any
open_in_new_tab: false
# ---------- Access bindings: admin OR staff group --------------------
- identifiers:
target: !Find [authentik_core.application, [slug, toolctrl-admin-panel]]
group: !Find [authentik_core.group, [name, toolctrl-admin]]
order: 0
model: authentik_policies.policybinding
state: present
attrs:
enabled: true
- identifiers:
target: !Find [authentik_core.application, [slug, toolctrl-admin-panel]]
group: !Find [authentik_core.group, [name, toolctrl-staff]]
order: 10
model: authentik_policies.policybinding
state: present
attrs:
enabled: true
# ---------- MFA-TOTP-for-admin binding on the application -----------
- identifiers:
target: !Find [authentik_core.application, [slug, toolctrl-admin-panel]]
policy: !Find [authentik_policies_expression.expressionpolicy, [name, toolctrl-require-mfa-totp-for-admin]]
order: 20
model: authentik_policies.policybinding
state: present
attrs:
enabled: true
# ---------- DISABLED placeholder: toolctrl-tenant-sso (#66) ---------
- identifiers:
name: toolctrl-tenant-sso
model: authentik_providers_oauth2.oauth2provider
state: present
attrs:
client_type: confidential
# Sentinel values; #66 will rewrite these.
client_id: "toolctrl-tenant-sso-placeholder"
client_secret: "placeholder-do-not-use"
authorization_flow: !Find [authentik_flows.flow, [slug, default-provider-authorization-implicit-consent]]
authentication_flow: !Find [authentik_flows.flow, [slug, default-authentication-flow]]
invalidation_flow: !Find [authentik_flows.flow, [slug, default-provider-invalidation-flow]]
signing_key: !Find [authentik_crypto.certificatekeypair, [name, authentik Self-signed Certificate]]
sub_mode: hashed_user_id
include_claims_in_id_token: true
issuer_mode: per_provider
# Authentik has no `enabled` flag at the provider level; we keep this
# provider un-attached to any Application so it has no live route.
# 2026.x requires redirect_uris even on unattached providers — use a
# non-routable placeholder. #66 will rewrite when tenant SSO lands.
redirect_uris:
- matching_mode: strict
url: "https://placeholder.invalid/oidc/callback"
access_code_validity: minutes=1
access_token_validity: minutes=10
refresh_token_validity: days=7
+105
View File
@@ -0,0 +1,105 @@
#!/usr/bin/env bash
# infra/authentik/bootstrap/bootstrap.sh
#
# Idempotent post-deploy bootstrap. Waits for the Authentik server to become
# ready, then ensures the project blueprints (./blueprints/*.yaml) are loaded
# and applied. The blueprint files themselves are also mounted into the
# server/worker containers via docker-compose.yml — the worker auto-applies
# them at startup. This script is a belt-and-braces re-trigger that:
# 1. polls /-/health/ready/ until it returns 200,
# 2. triggers /api/v3/managed/blueprints/<id>/apply/ for every blueprint
# so they re-apply immediately rather than waiting for the next worker
# tick,
# 3. prints the operator-actionable next steps (rotate bootstrap token,
# enable MFA on the admin account, etc.).
#
# Run this from the operator's machine OR inside a Coolify post-deploy hook:
#
# export AUTHENTIK_BASE_URL=https://auth.boiler.saas-ctrl.com
# export AUTHENTIK_BOOTSTRAP_TOKEN=$(cat ~/.cli-tokens/authentik-bootstrap)
# bash infra/authentik/bootstrap/bootstrap.sh
set -Eeuo pipefail
: "${AUTHENTIK_BASE_URL:?AUTHENTIK_BASE_URL must be set (e.g. https://auth.boiler.saas-ctrl.com)}"
: "${AUTHENTIK_BOOTSTRAP_TOKEN:?AUTHENTIK_BOOTSTRAP_TOKEN must be set (see .env.example)}"
WAIT_MAX_SECONDS="${WAIT_MAX_SECONDS:-300}"
WAIT_INTERVAL_SECONDS="${WAIT_INTERVAL_SECONDS:-5}"
log() { printf "\033[1;34m[authentik-bootstrap]\033[0m %s\n" "$*"; }
err() { printf "\033[1;31m[authentik-bootstrap:ERROR]\033[0m %s\n" "$*" >&2; }
die() { err "$*"; exit 1; }
# ----------------------------------------------------------------------------
# Step 1: wait for /-/health/ready/
# ----------------------------------------------------------------------------
log "waiting for ${AUTHENTIK_BASE_URL}/-/health/ready/ (timeout ${WAIT_MAX_SECONDS}s)"
deadline=$(( $(date +%s) + WAIT_MAX_SECONDS ))
while true; do
if curl -fsS -o /dev/null -w "%{http_code}" "${AUTHENTIK_BASE_URL}/-/health/ready/" | grep -q "^200$"; then
log "server ready"
break
fi
if [[ $(date +%s) -ge ${deadline} ]]; then
die "timed out waiting for /-/health/ready/"
fi
sleep "${WAIT_INTERVAL_SECONDS}"
done
# ----------------------------------------------------------------------------
# Step 2: list blueprints and trigger re-apply
# ----------------------------------------------------------------------------
auth_header="Authorization: Bearer ${AUTHENTIK_BOOTSTRAP_TOKEN}"
log "listing managed blueprints"
blueprints_json="$(curl -fsS -H "${auth_header}" "${AUTHENTIK_BASE_URL}/api/v3/managed/blueprints/?page_size=200")" || die "blueprint listing failed (check AUTHENTIK_BOOTSTRAP_TOKEN)"
# Extract pk for any blueprint whose `path` starts with /blueprints/toolctrl/.
ids="$(printf "%s" "${blueprints_json}" \
| python3 -c 'import sys, json; data=json.load(sys.stdin); [print(b["pk"]) for b in data.get("results", []) if b.get("path","").startswith("/blueprints/toolctrl/")]')"
if [[ -z "${ids}" ]]; then
log "no /blueprints/toolctrl/* blueprints found yet — the worker has not picked them up"
log "this is expected on the very first boot; the worker auto-discovers them within ~30s"
log "re-run this script in 1 minute to apply explicitly"
exit 0
fi
# ----------------------------------------------------------------------------
# Step 3: apply each blueprint
# ----------------------------------------------------------------------------
for id in ${ids}; do
log "applying blueprint ${id}"
curl -fsS -X POST -H "${auth_header}" "${AUTHENTIK_BASE_URL}/api/v3/managed/blueprints/${id}/apply/" \
-o /dev/null \
|| err "apply failed for blueprint ${id} (will be retried by the worker)"
done
log "bootstrap complete"
cat <<'EONOTE'
----------------------------------------------------------------------
NEXT STEPS (operator)
----------------------------------------------------------------------
1. Log into https://auth.boiler.saas-ctrl.com using AUTHENTIK_BOOTSTRAP_EMAIL
+ AUTHENTIK_BOOTSTRAP_PASSWORD. The first login forces a password change.
2. In the Authentik UI, enroll TOTP for your account
(User Settings -> Authenticators -> Set up TOTP). Required because
the toolctrl-require-mfa-totp-for-admin policy denies access to the
admin OIDC application without a verified TOTP device.
3. Rotate AUTHENTIK_BOOTSTRAP_TOKEN — it grants full admin-API access
and is no longer needed after this bootstrap. Generate a fresh
personal admin token instead, and store it in Coolify-Vault.
4. Add real human admins by creating users in the Authentik UI and
adding them to the `toolctrl-admin` group. Force TOTP enrollment
on each.
5. Verify OIDC discovery from the admin-panel side once #82 is wired:
curl -fsS https://auth.boiler.saas-ctrl.com/application/o/toolctrl-admin-panel/.well-known/openid-configuration | jq .issuer
----------------------------------------------------------------------
EONOTE
@@ -0,0 +1,198 @@
# Self-hosted Authentik IdP stack pinned at 2026.2.3 (see UPSTREAM.md).
#
# Four services on an internal `authentik-net` network, with the `server`
# service additionally attached to the Coolify-managed `coolify` external
# network so Traefik can route inbound HTTPS to it (see traefik.labels.yml
# for the Traefik label-set — those labels are applied at the operator's
# Coolify-service level rather than inline here, so this file stays portable
# between staging and any future dedicated-host deployment).
#
# Postgres + Redis are strictly Authentik-internal — never share with the
# boilerplate app's databases. No `ports:` mappings anywhere; ingress is
# Traefik-only.
#
# Volume convention: named volumes are managed by Docker; on staging Coolify
# binds them under /var/lib/docker/volumes/authentik_*. The backup container
# (see infra/authentik/backup/) reads from the same network.
version: "3.8"
# ----------------------------------------------------------------------------
# Networks
# ----------------------------------------------------------------------------
networks:
authentik-net:
name: authentik-net
driver: bridge
coolify:
external: true
# ----------------------------------------------------------------------------
# Volumes
# ----------------------------------------------------------------------------
volumes:
authentik-pg-data:
name: authentik-pg-data
authentik-redis-data:
name: authentik-redis-data
authentik-media:
name: authentik-media
authentik-certs:
name: authentik-certs
authentik-templates:
name: authentik-templates
# ----------------------------------------------------------------------------
# Services
# ----------------------------------------------------------------------------
services:
# --- Postgres 16 ---------------------------------------------------------
postgresql:
image: postgres:16-alpine
restart: unless-stopped
networks:
- authentik-net
healthcheck:
test: ["CMD-SHELL", "pg_isready -U ${AUTHENTIK_POSTGRESQL__USER:-authentik} -d ${AUTHENTIK_POSTGRESQL__NAME:-authentik}"]
start_period: 20s
interval: 30s
retries: 5
timeout: 5s
volumes:
- authentik-pg-data:/var/lib/postgresql/data
environment:
POSTGRES_USER: ${AUTHENTIK_POSTGRESQL__USER:-authentik}
POSTGRES_PASSWORD: ${AUTHENTIK_POSTGRESQL__PASSWORD:?must be set in .env}
POSTGRES_DB: ${AUTHENTIK_POSTGRESQL__NAME:-authentik}
# --- Redis 7 -------------------------------------------------------------
redis:
image: redis:7-alpine
command: --save 60 1 --loglevel warning
restart: unless-stopped
networks:
- authentik-net
healthcheck:
test: ["CMD-SHELL", "redis-cli ping | grep PONG"]
start_period: 10s
interval: 30s
retries: 5
timeout: 3s
volumes:
- authentik-redis-data:/data
# --- Authentik server (web/api/HTTP) ------------------------------------
server:
image: ghcr.io/goauthentik/server:2026.2.3
restart: unless-stopped
command: server
networks:
- authentik-net
- coolify
healthcheck:
# Authentik exposes /-/health/live/ + /-/health/ready/ on port 9000.
# We use `wget` (image ships busybox-wget); fallback to curl if wget is
# missing in a future image.
test:
- "CMD-SHELL"
- "wget -qO- http://localhost:9000/-/health/live/ >/dev/null 2>&1 || curl -fsS http://localhost:9000/-/health/live/ >/dev/null 2>&1 || exit 1"
start_period: 60s
interval: 30s
retries: 5
timeout: 10s
environment:
AUTHENTIK_REDIS__HOST: redis
AUTHENTIK_POSTGRESQL__HOST: postgresql
AUTHENTIK_POSTGRESQL__USER: ${AUTHENTIK_POSTGRESQL__USER:-authentik}
AUTHENTIK_POSTGRESQL__NAME: ${AUTHENTIK_POSTGRESQL__NAME:-authentik}
AUTHENTIK_POSTGRESQL__PASSWORD: ${AUTHENTIK_POSTGRESQL__PASSWORD:?must be set in .env}
AUTHENTIK_SECRET_KEY: ${AUTHENTIK_SECRET_KEY:?must be set in .env}
AUTHENTIK_ERROR_REPORTING__ENABLED: ${AUTHENTIK_ERROR_REPORTING__ENABLED:-false}
AUTHENTIK_LOG_LEVEL: ${AUTHENTIK_LOG_LEVEL:-info}
AUTHENTIK_DISABLE_UPDATE_CHECK: ${AUTHENTIK_DISABLE_UPDATE_CHECK:-true}
AUTHENTIK_DISABLE_STARTUP_ANALYTICS: ${AUTHENTIK_DISABLE_STARTUP_ANALYTICS:-true}
AUTHENTIK_BOOTSTRAP_PASSWORD: ${AUTHENTIK_BOOTSTRAP_PASSWORD:-}
AUTHENTIK_BOOTSTRAP_EMAIL: ${AUTHENTIK_BOOTSTRAP_EMAIL:-}
AUTHENTIK_BOOTSTRAP_TOKEN: ${AUTHENTIK_BOOTSTRAP_TOKEN:-}
AUTHENTIK_COOKIE_DOMAIN: ${AUTHENTIK_COOKIE_DOMAIN:-}
# Internal SSL OFF — TLS is terminated by Traefik in front.
AUTHENTIK_LISTEN__HTTP: 0.0.0.0:9000
AUTHENTIK_LISTEN__HTTPS: 0.0.0.0:9443
# Optional Sentry integration (Phase 02 #29 DSN goes here).
AUTHENTIK_SENTRY__DSN: ${AUTHENTIK_SENTRY__DSN:-}
AUTHENTIK_SENTRY__ENVIRONMENT: ${AUTHENTIK_SENTRY__ENVIRONMENT:-staging}
# Optional SMTP for recovery mails.
AUTHENTIK_EMAIL__HOST: ${AUTHENTIK_EMAIL__HOST:-}
AUTHENTIK_EMAIL__PORT: ${AUTHENTIK_EMAIL__PORT:-587}
AUTHENTIK_EMAIL__USERNAME: ${AUTHENTIK_EMAIL__USERNAME:-}
AUTHENTIK_EMAIL__PASSWORD: ${AUTHENTIK_EMAIL__PASSWORD:-}
AUTHENTIK_EMAIL__USE_TLS: ${AUTHENTIK_EMAIL__USE_TLS:-true}
AUTHENTIK_EMAIL__USE_SSL: ${AUTHENTIK_EMAIL__USE_SSL:-false}
AUTHENTIK_EMAIL__TIMEOUT: ${AUTHENTIK_EMAIL__TIMEOUT:-10}
AUTHENTIK_EMAIL__FROM: ${AUTHENTIK_EMAIL__FROM:-authentik@boiler.saas-ctrl.com}
volumes:
- authentik-media:/media
- authentik-certs:/certs
- authentik-templates:/templates
# Blueprints baked into the image are loaded automatically. Operator
# mounts the project blueprints over the default path during bootstrap
# (see infra/authentik/bootstrap/bootstrap.sh).
- ./bootstrap/blueprints:/blueprints/toolctrl:ro
depends_on:
postgresql:
condition: service_healthy
redis:
condition: service_healthy
# NO `ports:` — Traefik routes inbound on the `coolify` network.
# --- Authentik worker (background jobs, blueprint apply, email) ---------
worker:
image: ghcr.io/goauthentik/server:2026.2.3
restart: unless-stopped
command: worker
networks:
- authentik-net
healthcheck:
test: ["CMD-SHELL", "ak healthcheck"]
start_period: 60s
interval: 30s
retries: 5
timeout: 30s
# Worker needs the docker socket only if you intend to manage Outposts
# via Docker. We don't ship Outposts in this phase, so the socket is
# intentionally NOT mounted. If a future phase enables Outposts, mount
# /var/run/docker.sock:/var/run/docker.sock:ro then.
environment:
AUTHENTIK_REDIS__HOST: redis
AUTHENTIK_POSTGRESQL__HOST: postgresql
AUTHENTIK_POSTGRESQL__USER: ${AUTHENTIK_POSTGRESQL__USER:-authentik}
AUTHENTIK_POSTGRESQL__NAME: ${AUTHENTIK_POSTGRESQL__NAME:-authentik}
AUTHENTIK_POSTGRESQL__PASSWORD: ${AUTHENTIK_POSTGRESQL__PASSWORD:?must be set in .env}
AUTHENTIK_SECRET_KEY: ${AUTHENTIK_SECRET_KEY:?must be set in .env}
AUTHENTIK_ERROR_REPORTING__ENABLED: ${AUTHENTIK_ERROR_REPORTING__ENABLED:-false}
AUTHENTIK_LOG_LEVEL: ${AUTHENTIK_LOG_LEVEL:-info}
AUTHENTIK_DISABLE_UPDATE_CHECK: ${AUTHENTIK_DISABLE_UPDATE_CHECK:-true}
AUTHENTIK_DISABLE_STARTUP_ANALYTICS: ${AUTHENTIK_DISABLE_STARTUP_ANALYTICS:-true}
AUTHENTIK_BOOTSTRAP_PASSWORD: ${AUTHENTIK_BOOTSTRAP_PASSWORD:-}
AUTHENTIK_BOOTSTRAP_EMAIL: ${AUTHENTIK_BOOTSTRAP_EMAIL:-}
AUTHENTIK_BOOTSTRAP_TOKEN: ${AUTHENTIK_BOOTSTRAP_TOKEN:-}
AUTHENTIK_SENTRY__DSN: ${AUTHENTIK_SENTRY__DSN:-}
AUTHENTIK_SENTRY__ENVIRONMENT: ${AUTHENTIK_SENTRY__ENVIRONMENT:-staging}
AUTHENTIK_EMAIL__HOST: ${AUTHENTIK_EMAIL__HOST:-}
AUTHENTIK_EMAIL__PORT: ${AUTHENTIK_EMAIL__PORT:-587}
AUTHENTIK_EMAIL__USERNAME: ${AUTHENTIK_EMAIL__USERNAME:-}
AUTHENTIK_EMAIL__PASSWORD: ${AUTHENTIK_EMAIL__PASSWORD:-}
AUTHENTIK_EMAIL__USE_TLS: ${AUTHENTIK_EMAIL__USE_TLS:-true}
AUTHENTIK_EMAIL__USE_SSL: ${AUTHENTIK_EMAIL__USE_SSL:-false}
AUTHENTIK_EMAIL__TIMEOUT: ${AUTHENTIK_EMAIL__TIMEOUT:-10}
AUTHENTIK_EMAIL__FROM: ${AUTHENTIK_EMAIL__FROM:-authentik@boiler.saas-ctrl.com}
volumes:
- authentik-media:/media
- authentik-certs:/certs
- authentik-templates:/templates
- ./bootstrap/blueprints:/blueprints/toolctrl:ro
depends_on:
postgresql:
condition: service_healthy
redis:
condition: service_healthy
+95
View File
@@ -0,0 +1,95 @@
#!/usr/bin/env bash
# infra/authentik/scripts/smoke.sh
#
# Post-deploy smoke checks for the self-hosted Authentik stack. Runs
# read-only HTTP probes from the operator's machine; safe to re-run.
#
# Probes:
# 1. https://auth.<host>/ -> 200 (login page)
# 2. https://auth.<host>/-/health/live/ -> 200
# 3. https://auth.<host>/-/health/ready/ -> 200
# 4. https://auth.<host>/application/o/<app-slug>/.well-known/openid-configuration -> 200 JSON
# with `issuer`, `authorization_endpoint`, `token_endpoint`, `jwks_uri`
# 5. (optional) self-registration endpoint returns 404
#
# Usage:
# export AUTHENTIK_BASE_URL=https://auth.boiler.saas-ctrl.com
# export AUTHENTIK_APP_SLUG=toolctrl-admin-panel
# bash infra/authentik/scripts/smoke.sh
#
# Exit codes:
# 0 = all probes passed
# 1 = at least one probe failed
set -Eeuo pipefail
: "${AUTHENTIK_BASE_URL:?AUTHENTIK_BASE_URL must be set (e.g. https://auth.boiler.saas-ctrl.com)}"
: "${AUTHENTIK_APP_SLUG:=toolctrl-admin-panel}"
FAILED=0
PASSED=0
log_ok() { printf "\033[1;32m[smoke:OK]\033[0m %s\n" "$*"; PASSED=$((PASSED+1)); }
log_fail() { printf "\033[1;31m[smoke:FAIL]\033[0m %s\n" "$*" >&2; FAILED=$((FAILED+1)); }
log_info() { printf "\033[1;34m[smoke]\033[0m %s\n" "$*"; }
probe_status() {
local label="$1"
local url="$2"
local want="$3"
local got
got="$(curl -ksS -o /dev/null -w "%{http_code}" "${url}" || echo "000")"
if [[ "${got}" == "${want}" ]]; then
log_ok "${label} -> ${got}"
else
log_fail "${label} -> got ${got}, want ${want} (${url})"
fi
}
probe_oidc_discovery() {
local url="${AUTHENTIK_BASE_URL}/application/o/${AUTHENTIK_APP_SLUG}/.well-known/openid-configuration"
local body
body="$(curl -ksS -o - -w "\nHTTP_STATUS:%{http_code}" "${url}" || true)"
local status
status="$(printf "%s" "${body}" | grep -E "^HTTP_STATUS:" | tail -1 | cut -d: -f2 | tr -d '[:space:]')"
local payload
payload="$(printf "%s" "${body}" | sed -e '/^HTTP_STATUS:/d')"
if [[ "${status}" != "200" ]]; then
log_fail "oidc-discovery -> got ${status}, want 200 (${url})"
return
fi
for k in issuer authorization_endpoint token_endpoint jwks_uri; do
if printf "%s" "${payload}" | grep -q "\"${k}\""; then
log_ok "oidc-discovery field ${k} present"
else
log_fail "oidc-discovery field ${k} MISSING (${url})"
fi
done
}
log_info "smoke target: ${AUTHENTIK_BASE_URL}"
log_info "app slug: ${AUTHENTIK_APP_SLUG}"
# 1. Root login page reachable
probe_status "root (login page)" "${AUTHENTIK_BASE_URL}/" "200"
# 2. Health probes
probe_status "health-live" "${AUTHENTIK_BASE_URL}/-/health/live/" "200"
probe_status "health-ready" "${AUTHENTIK_BASE_URL}/-/health/ready/" "200"
# 3. OIDC discovery (depends on blueprint 03-application-toolctrl-admin.yaml
# having applied — fails until bootstrap is done)
probe_oidc_discovery
# 4. Self-registration disabled (Authentik default-source-enrollment flow)
log_info "verifying public self-registration is OFF"
self_enroll_status="$(curl -ksS -o /dev/null -w "%{http_code}" "${AUTHENTIK_BASE_URL}/if/flow/default-source-enrollment/" || echo "000")"
if [[ "${self_enroll_status}" == "404" || "${self_enroll_status}" == "302" ]]; then
log_ok "self-enrollment endpoint returns ${self_enroll_status} (registration disabled or redirect-to-deny)"
else
log_fail "self-enrollment endpoint returns ${self_enroll_status} (expected 404 or 302)"
fi
echo
log_info "summary: ${PASSED} passed, ${FAILED} failed"
[[ ${FAILED} -eq 0 ]] || exit 1
@@ -0,0 +1,66 @@
# Canonical Traefik label-set for the self-hosted Authentik IdP stack.
#
# This file is a YAML fragment (NOT a runnable compose by itself). The operator
# attaches the same labels to the `server` service via the Coolify-UI
# "Service Labels" panel when wiring the stack to Traefik; we ship them here
# in one place for review + traceability. Coolify-injected labels (project
# id, environment) are merged on top automatically.
#
# Coolify (v4) ships Traefik v3.6 with two entrypoints (`http`:80, `https`:443)
# and a default ACME cert-resolver named `letsencrypt`. The labels below match
# that convention; they exactly mirror the shape used by infra/sentry/.
#
# Host: auth.boiler.saas-ctrl.com -> DNS A record points at 46.225.5.93
# (created via Cloudflare API — see docs/operations/authentik-setup.md).
# ---- ROUTERS ----------------------------------------------------------------
# Primary HTTPS router — terminates TLS, forwards to authentik-server:9000.
traefik.enable: "true"
traefik.docker.network: "coolify"
traefik.http.routers.authentik.rule: "Host(`auth.boiler.saas-ctrl.com`)"
traefik.http.routers.authentik.entrypoints: "https"
traefik.http.routers.authentik.tls: "true"
traefik.http.routers.authentik.tls.certresolver: "letsencrypt"
traefik.http.services.authentik.loadbalancer.server.port: "9000"
# HTTP -> HTTPS redirect (port 80 catches plain-HTTP hits and 308s them to TLS).
traefik.http.routers.authentik-http.rule: "Host(`auth.boiler.saas-ctrl.com`)"
traefik.http.routers.authentik-http.entrypoints: "http"
traefik.http.routers.authentik-http.middlewares: "authentik-https-redirect"
traefik.http.middlewares.authentik-https-redirect.redirectscheme.scheme: "https"
# ---- SECURITY HEADERS (recommended) ----------------------------------------
#
# Attach `authentik-secure-headers` to the router's `middlewares` list:
# traefik.http.routers.authentik.middlewares: "authentik-secure-headers"
#
# Authentik itself sets a reasonable CSP for its own UI; the headers below
# tighten the response at the edge. HSTS-preload is intentionally OFF until
# the operator confirms all dependent subdomains are HTTPS-only (HSTS-preload
# is a one-way commitment).
traefik.http.middlewares.authentik-secure-headers.headers.stsSeconds: "63072000"
traefik.http.middlewares.authentik-secure-headers.headers.stsIncludeSubdomains: "true"
traefik.http.middlewares.authentik-secure-headers.headers.stsPreload: "false"
traefik.http.middlewares.authentik-secure-headers.headers.contentTypeNosniff: "true"
traefik.http.middlewares.authentik-secure-headers.headers.browserXssFilter: "true"
traefik.http.middlewares.authentik-secure-headers.headers.frameDeny: "true"
traefik.http.middlewares.authentik-secure-headers.headers.referrerPolicy: "no-referrer"
# Authentik renders no third-party iframes; deny embedding the IdP UI entirely.
traefik.http.middlewares.authentik-secure-headers.headers.customResponseHeaders.X-Robots-Tag: "noindex, nofollow"
# ---- RATE-LIMIT MIDDLEWARE (recommended for /api/v3/flows/executor/*) ------
#
# Authentik has an internal brute-force policy (see bootstrap/blueprints/
# 02-policies.yaml — 5 failed/min IP-lockout for 15min). The Traefik
# rate-limit is a defence-in-depth layer that catches credential-stuffing
# bursts BEFORE they reach Authentik's flow executor. Attach to the router by
# appending `authentik-ratelimit` to the router's `middlewares` list when
# applying both at once:
#
# traefik.http.routers.authentik.middlewares: "authentik-secure-headers,authentik-ratelimit"
traefik.http.middlewares.authentik-ratelimit.ratelimit.average: "60"
traefik.http.middlewares.authentik-ratelimit.ratelimit.burst: "120"
traefik.http.middlewares.authentik-ratelimit.ratelimit.period: "1m"