chore: remove Authentik SSO path
Homelab Main / validate (push) Successful in 16s Details
Homelab Main / running-update (push) Successful in 10s Details
Homelab Main / debian-ops (push) Successful in 1m13s Details

This commit is contained in:
juvenal.diaz 2026-09-30 11:42:30 -06:00
parent 41f2b05704
commit a7a93382a9
12 changed files with 58 additions and 501 deletions

View File

@ -14,38 +14,38 @@ locals {
crowdsec_whitelist = templatefile("${path.module}/templates/crowdsec-homelab-whitelist.yaml.tftpl", {})
heimdall_server_name = "heimdall.${var.server_name}"
homepage_server_name = "homepage.${var.server_name}"
authentik_server_name = "auth.${var.server_name}"
oidc_server_name = "auth.${var.server_name}"
jellyfin_server_name = "jellyfin.${var.server_name}"
heimdall_backend_host = var.heimdall_backend_host != "" ? var.heimdall_backend_host : var.gitea_backend_host
homepage_backend_host = var.homepage_backend_host != "" ? var.homepage_backend_host : var.gitea_backend_host
authentik_backend_host = (
var.authentik_backend_host != "" ? var.authentik_backend_host : var.gitea_backend_host
oidc_backend_host = (
var.oidc_backend_host != "" ? var.oidc_backend_host : var.gitea_backend_host
)
jellyfin_backend_host = var.jellyfin_backend_host != "" ? var.jellyfin_backend_host : var.gitea_backend_host
server_names = distinct(concat([var.server_name, local.heimdall_server_name, local.homepage_server_name, local.authentik_server_name, local.jellyfin_server_name], var.additional_server_names))
server_names = distinct(concat([var.server_name, local.heimdall_server_name, local.homepage_server_name, local.oidc_server_name, local.jellyfin_server_name], var.additional_server_names))
matrix_server_names = var.matrix_enabled ? [var.matrix_server_name, var.element_server_name] : []
main_server_names = [for name in local.server_names : name if !contains([local.heimdall_server_name, local.homepage_server_name, local.authentik_server_name, local.jellyfin_server_name], name) && !contains(local.matrix_server_names, name)]
main_server_names = [for name in local.server_names : name if !contains([local.heimdall_server_name, local.homepage_server_name, local.oidc_server_name, local.jellyfin_server_name], name) && !contains(local.matrix_server_names, name)]
default_conf = templatefile("${path.module}/templates/default.conf.tftpl", {
server_name = var.server_name
server_names = join(" ", local.server_names)
main_server_names = join(" ", local.main_server_names)
backend_host = var.backend_host
backend_port = tostring(var.backend_port)
demos_backend_port = var.demos_backend_port
gitea_backend_host = var.gitea_backend_host
gitea_backend_port = var.gitea_backend_port
heimdall_server_name = local.heimdall_server_name
heimdall_backend_host = local.heimdall_backend_host
heimdall_backend_port = tostring(var.heimdall_backend_port)
homepage_server_name = local.homepage_server_name
homepage_backend_host = local.homepage_backend_host
homepage_backend_port = tostring(var.homepage_backend_port)
authentik_server_name = local.authentik_server_name
authentik_backend_host = local.authentik_backend_host
authentik_backend_port = tostring(var.authentik_backend_port)
jellyfin_server_name = local.jellyfin_server_name
jellyfin_backend_host = local.jellyfin_backend_host
jellyfin_backend_port = tostring(var.jellyfin_backend_port)
server_name = var.server_name
server_names = join(" ", local.server_names)
main_server_names = join(" ", local.main_server_names)
backend_host = var.backend_host
backend_port = tostring(var.backend_port)
demos_backend_port = var.demos_backend_port
gitea_backend_host = var.gitea_backend_host
gitea_backend_port = var.gitea_backend_port
heimdall_server_name = local.heimdall_server_name
heimdall_backend_host = local.heimdall_backend_host
heimdall_backend_port = tostring(var.heimdall_backend_port)
homepage_server_name = local.homepage_server_name
homepage_backend_host = local.homepage_backend_host
homepage_backend_port = tostring(var.homepage_backend_port)
oidc_server_name = local.oidc_server_name
oidc_backend_host = local.oidc_backend_host
oidc_backend_port = tostring(var.oidc_backend_port)
jellyfin_server_name = local.jellyfin_server_name
jellyfin_backend_host = local.jellyfin_backend_host
jellyfin_backend_port = tostring(var.jellyfin_backend_port)
})
default_vcl = templatefile("${path.module}/templates/default.vcl.tftpl", {
backend_host = var.backend_host
@ -95,8 +95,8 @@ resource "null_resource" "edge_services" {
gitea_backend_port = tostring(var.gitea_backend_port)
heimdall_host = local.heimdall_backend_host
heimdall_port = tostring(var.heimdall_backend_port)
authentik_host = local.authentik_backend_host
authentik_port = tostring(var.authentik_backend_port)
oidc_host = local.oidc_backend_host
oidc_port = tostring(var.oidc_backend_port)
jellyfin_host = local.jellyfin_backend_host
jellyfin_port = tostring(var.jellyfin_backend_port)
enable_letsencrypt = tostring(var.enable_letsencrypt)
@ -176,8 +176,8 @@ gitea_backend_host="${self.triggers.gitea_backend_host}"
gitea_backend_port="${self.triggers.gitea_backend_port}"
heimdall_host="${self.triggers.heimdall_host}"
heimdall_port="${self.triggers.heimdall_port}"
authentik_host="${self.triggers.authentik_host}"
authentik_port="${self.triggers.authentik_port}"
oidc_host="${self.triggers.oidc_host}"
oidc_port="${self.triggers.oidc_port}"
jellyfin_host="${self.triggers.jellyfin_host}"
jellyfin_port="${self.triggers.jellyfin_port}"
enable_letsencrypt="${self.triggers.enable_letsencrypt}"
@ -216,8 +216,8 @@ if ! curl -sS --connect-timeout 10 "http://$heimdall_host:$heimdall_port/" >/dev
echo "Run ./jeannie deploy-heimdall on the Debian host if the service is missing." >&2
fi
if ! curl -sS --connect-timeout 10 "http://$authentik_host:$authentik_port/healthz" >/dev/null; then
echo "Warning: cannot reach Dex backend http://$authentik_host:$authentik_port/ from the edge host." >&2
if ! curl -sS --connect-timeout 10 "http://$oidc_host:$oidc_port/healthz" >/dev/null; then
echo "Warning: cannot reach Dex backend http://$oidc_host:$oidc_port/ from the edge host." >&2
echo "Run ./jeannie deploy-dex on the Debian host before testing the public hostname." >&2
fi

View File

@ -34,8 +34,8 @@ upstream homepage_backend {
keepalive 8;
}
upstream authentik_backend {
server ${authentik_backend_host}:${authentik_backend_port};
upstream oidc_backend {
server ${oidc_backend_host}:${oidc_backend_port};
keepalive 8;
}
@ -78,7 +78,7 @@ server {
server {
listen 80;
server_name ${heimdall_server_name} ${homepage_server_name} ${authentik_server_name} ${jellyfin_server_name};
server_name ${heimdall_server_name} ${homepage_server_name} ${oidc_server_name} ${jellyfin_server_name};
location ^~ /.well-known/acme-challenge/ {
root /var/www/certbot;
@ -94,7 +94,7 @@ server {
server {
listen 443 ssl;
http2 on;
server_name ${authentik_server_name};
server_name ${oidc_server_name};
ssl_certificate /etc/nginx/certs/current.crt;
ssl_certificate_key /etc/nginx/certs/current.key;
@ -125,7 +125,7 @@ server {
limit_req zone=one burst=20 nodelay;
client_max_body_size 64m;
proxy_pass http://authentik_backend;
proxy_pass http://oidc_backend;
proxy_cache off;
proxy_no_cache 1;
proxy_cache_bypass 1;

View File

@ -113,14 +113,14 @@ variable "homepage_backend_port" {
default = 8083
}
variable "authentik_backend_host" {
variable "oidc_backend_host" {
type = string
default = ""
}
variable "authentik_backend_port" {
variable "oidc_backend_port" {
type = number
default = 9000
default = 5556
}
variable "jellyfin_backend_host" {

View File

@ -1,7 +1,6 @@
# Gitea SSO
Gitea SSO is now managed by Jeannie through the shared Dex IdP, not through
this directory's former Authentik OpenTofu stack.
Gitea SSO is managed by Jeannie through the shared Dex IdP.
`./jeannie sso-gitea apply` deploys Dex if needed, then configures the existing
Debian-hosted Gitea container with:

View File

@ -1,7 +1,6 @@
# Grafana SSO
Grafana SSO is now managed by Jeannie through the shared Dex IdP, not through
this directory's former Authentik OpenTofu stack.
Grafana SSO is managed by Jeannie through the shared Dex IdP.
Run from the Debian homelab server:

View File

@ -87,11 +87,6 @@ services:
install_dir: /data/homelab-heimdall
http_port: 8083
public_url: https://homepage.lab2025.duckdns.org/
authentik:
host: debian
install_dir: /data/homelab-authentik
http_port: 9000
public_url: https://auth.lab2025.duckdns.org/
dex:
host: debian
install_dir: /data/homelab-dex

View File

@ -1,54 +0,0 @@
# Authentik
Authentik is the homelab identity provider and SSO control plane.
It intentionally runs outside Kubernetes as a Debian-hosted Docker Compose
stack. That keeps login available while the Kubernetes cluster is rebuilt,
recreated, or broken.
## Placement decision
The Raspberry Pi 4 is useful as a lightweight always-on appliance, but this lab
already uses it for DNS, Unbound, Uptime Kuma, and node-exporter. Authentik is
stateful and will become a dependency for Grafana, Argo CD, Jellyfin, and other
apps, so the first standalone placement is the Debian host under `/data`.
The RPi can become a later failover target after restore drills prove the
PostgreSQL/media backup path.
## Deploy
Run from the Debian homelab server:
```bash
./jeannie deploy-authentik
./jeannie edge
```
After the standalone stack is healthy and edge points to it, remove the old
Kubernetes proof-of-concept release:
```bash
./jeannie platform
```
The deploy command reuses the existing SOPS-encrypted secret:
```text
apps/authentik/authentik.secret.yaml
```
It renders a local Compose `.env` file on the Debian host. Do not commit the
rendered `.env` file.
## Public URL
```text
https://auth.lab2025.duckdns.org/
```
First setup:
```text
https://auth.lab2025.duckdns.org/if/flow/initial-setup/
```

View File

@ -1,89 +0,0 @@
services:
postgresql:
image: ${AUTHENTIK_POSTGRES_IMAGE:-postgres:16-alpine}
container_name: ${AUTHENTIK_POSTGRES_CONTAINER_NAME:-homelab-authentik-postgres}
restart: unless-stopped
environment:
POSTGRES_DB: ${AUTHENTIK_POSTGRESQL__NAME:-authentik}
POSTGRES_USER: ${AUTHENTIK_POSTGRESQL__USER:-authentik}
POSTGRES_PASSWORD: ${AUTHENTIK_POSTGRESQL__PASSWORD}
healthcheck:
test:
- CMD-SHELL
- pg_isready -d "$${POSTGRES_DB}" -U "$${POSTGRES_USER}"
interval: 30s
timeout: 5s
retries: 5
start_period: 20s
volumes:
- ${AUTHENTIK_POSTGRES_DATA_DIR:-/data/homelab-authentik/postgresql}:/var/lib/postgresql/data
networks:
- authentik
redis:
image: ${AUTHENTIK_REDIS_IMAGE:-redis:7-alpine}
container_name: ${AUTHENTIK_REDIS_CONTAINER_NAME:-homelab-authentik-redis}
restart: unless-stopped
command:
- redis-server
- --save
- "60"
- "1"
- --loglevel
- warning
healthcheck:
test:
- CMD
- redis-cli
- ping
interval: 30s
timeout: 3s
retries: 5
start_period: 20s
volumes:
- ${AUTHENTIK_REDIS_DATA_DIR:-/data/homelab-authentik/redis}:/data
networks:
- authentik
server:
image: ${AUTHENTIK_IMAGE:-ghcr.io/goauthentik/server:2026.8.3}
container_name: ${AUTHENTIK_SERVER_CONTAINER_NAME:-homelab-authentik-server}
restart: unless-stopped
command: server
depends_on:
postgresql:
condition: service_healthy
redis:
condition: service_healthy
env_file:
- .env
ports:
- "${AUTHENTIK_BIND_IP:-0.0.0.0}:${AUTHENTIK_HTTP_PORT:-9000}:9000/tcp"
volumes:
- ${AUTHENTIK_MEDIA_DIR:-/data/homelab-authentik/media}:/media
- ${AUTHENTIK_TEMPLATES_DIR:-/data/homelab-authentik/templates}:/templates
networks:
- authentik
worker:
image: ${AUTHENTIK_IMAGE:-ghcr.io/goauthentik/server:2026.8.3}
container_name: ${AUTHENTIK_WORKER_CONTAINER_NAME:-homelab-authentik-worker}
restart: unless-stopped
command: worker
depends_on:
postgresql:
condition: service_healthy
redis:
condition: service_healthy
env_file:
- .env
volumes:
- ${AUTHENTIK_MEDIA_DIR:-/data/homelab-authentik/media}:/media
- ${AUTHENTIK_TEMPLATES_DIR:-/data/homelab-authentik/templates}:/templates
- /var/run/docker.sock:/var/run/docker.sock:ro
networks:
- authentik
networks:
authentik:
name: ${AUTHENTIK_NETWORK:-homelab-authentik}

View File

@ -54,7 +54,6 @@ Build And Bootstrap
deploy-gitea Deploy the Debian-hosted Gitea container.
deploy-heimdall Deploy the Debian-hosted Heimdall dashboard.
deploy-dex Deploy the Debian-hosted Dex SSO stack.
deploy-authentik Deploy the Debian-hosted Authentik SSO stack.
deploy-matrix Deploy the Matrix homeserver (Synapse + Element + Postgres).
deploy-omniroute Deploy the OmniRoute LLM routing gateway.
deploy-hermes Deploy the Hermes agent (git-install + venv + gateway service).
@ -106,7 +105,6 @@ Observability And GitOps
sso-grafana {plan|apply} Enable Grafana SSO through Dex.
sso-gitea {plan|apply} Enable Gitea SSO through Dex.
dex-secret {ensure|file} Generate/check SOPS-encrypted Dex bootstrap secrets.
authentik-secret {ensure|file} Generate/check SOPS-encrypted Authentik bootstrap secrets.
gitops-status Print focused Argo CD health and sync status.
platform Deploy platform stack only.
edge Deploy/check the OCI edge stack only.
@ -323,9 +321,6 @@ case "${1:-}" in
dex-secret)
dex_secret "${2:-ensure}"
;;
authentik-secret)
authentik_secret "${2:-ensure}"
;;
workers)
workers_manage "$@"
;;
@ -373,10 +368,6 @@ case "${1:-}" in
record_change_journal "deploy-dex" "$@"
deploy_dex
;;
deploy-authentik)
record_change_journal "deploy-authentik" "$@"
deploy_authentik
;;
deploy-matrix)
record_change_journal "deploy-matrix" "$@"
deploy_matrix

View File

@ -49,9 +49,6 @@ mapping = {
"services.heimdall.public_url": "LAB_HEIMDALL_PUBLIC_URL",
"services.homepage.http_port": "LAB_HOMEPAGE_HTTP_PORT",
"services.homepage.public_url": "LAB_HOMEPAGE_PUBLIC_URL",
"services.authentik.install_dir": "LAB_AUTHENTIK_INSTALL_DIR",
"services.authentik.http_port": "LAB_AUTHENTIK_HTTP_PORT",
"services.authentik.public_url": "LAB_AUTHENTIK_PUBLIC_URL",
"services.dex.install_dir": "LAB_DEX_INSTALL_DIR",
"services.dex.http_port": "LAB_DEX_HTTP_PORT",
"services.dex.telemetry_port": "LAB_DEX_TELEMETRY_PORT",
@ -192,8 +189,8 @@ export_homelab_inventory_tf_vars() {
export_if_unset TF_VAR_heimdall_backend_port "${LAB_HEIMDALL_HTTP_PORT:-}"
export_if_unset TF_VAR_homepage_backend_host "${LAB_HOMEPAGE_BACKEND_HOST:-${LAB_DEBIAN_TAILSCALE_IP:-}}"
export_if_unset TF_VAR_homepage_backend_port "${LAB_HOMEPAGE_HTTP_PORT:-}"
export_if_unset TF_VAR_authentik_backend_host "${LAB_DEX_BACKEND_HOST:-${LAB_DEBIAN_TAILSCALE_IP:-}}"
export_if_unset TF_VAR_authentik_backend_port "${LAB_DEX_HTTP_PORT:-}"
export_if_unset TF_VAR_oidc_backend_host "${LAB_DEX_BACKEND_HOST:-${LAB_DEBIAN_TAILSCALE_IP:-}}"
export_if_unset TF_VAR_oidc_backend_port "${LAB_DEX_HTTP_PORT:-}"
export_if_unset TF_VAR_grafana_oidc_url "${LAB_DEX_PUBLIC_URL:-}"
export_if_unset TF_VAR_grafana_public_url "https://grafana.${LAB_DOMAIN:-}"
export_if_unset TF_VAR_gitea_public_url "${LAB_GITEA_ROOT_URL:-}"

View File

@ -50,9 +50,6 @@ mapping = {
"services.heimdall.public_url": "LAB_HEIMDALL_PUBLIC_URL",
"services.homepage.http_port": "LAB_HOMEPAGE_HTTP_PORT",
"services.homepage.public_url": "LAB_HOMEPAGE_PUBLIC_URL",
"services.authentik.install_dir": "LAB_AUTHENTIK_INSTALL_DIR",
"services.authentik.http_port": "LAB_AUTHENTIK_HTTP_PORT",
"services.authentik.public_url": "LAB_AUTHENTIK_PUBLIC_URL",
"services.dex.install_dir": "LAB_DEX_INSTALL_DIR",
"services.dex.http_port": "LAB_DEX_HTTP_PORT",
"services.dex.telemetry_port": "LAB_DEX_TELEMETRY_PORT",
@ -193,8 +190,8 @@ export_homelab_inventory_tf_vars() {
export_if_unset TF_VAR_heimdall_backend_port "${LAB_HEIMDALL_HTTP_PORT:-}"
export_if_unset TF_VAR_homepage_backend_host "${LAB_HOMEPAGE_BACKEND_HOST:-${LAB_DEBIAN_TAILSCALE_IP:-}}"
export_if_unset TF_VAR_homepage_backend_port "${LAB_HOMEPAGE_HTTP_PORT:-}"
export_if_unset TF_VAR_authentik_backend_host "${LAB_DEX_BACKEND_HOST:-${LAB_DEBIAN_TAILSCALE_IP:-}}"
export_if_unset TF_VAR_authentik_backend_port "${LAB_DEX_HTTP_PORT:-}"
export_if_unset TF_VAR_oidc_backend_host "${LAB_DEX_BACKEND_HOST:-${LAB_DEBIAN_TAILSCALE_IP:-}}"
export_if_unset TF_VAR_oidc_backend_port "${LAB_DEX_HTTP_PORT:-}"
export_if_unset TF_VAR_grafana_oidc_url "${LAB_DEX_PUBLIC_URL:-}"
export_if_unset TF_VAR_grafana_public_url "https://grafana.${LAB_DOMAIN:-}"
export_if_unset TF_VAR_gitea_public_url "${LAB_GITEA_ROOT_URL:-}"
@ -749,6 +746,7 @@ ENV_EOF
configure_grafana_dex_secret() {
local namespace="${TF_VAR_grafana_namespace:-monitoring}"
local secret_name="${TF_VAR_grafana_oauth_secret_name:-grafana-dex-oauth}"
local legacy_secret_name="${LAB_GRAFANA_LEGACY_OAUTH_SECRET_NAME:-grafana-authentik-oauth}"
local dex_env
require_debian_server "sso-grafana"
@ -765,6 +763,10 @@ configure_grafana_dex_secret() {
--from-literal=GF_AUTH_GENERIC_OAUTH_CLIENT_SECRET="${DEX_GRAFANA_CLIENT_SECRET}" \
--dry-run=client -o yaml |
kubectl --kubeconfig "${KUBECONFIG_PATH}" apply -f -
if [[ "${legacy_secret_name}" != "${secret_name}" ]]; then
kubectl --kubeconfig "${KUBECONFIG_PATH}" -n "${namespace}" delete secret "${legacy_secret_name}" --ignore-not-found
fi
}
grafana_sso() {
@ -793,12 +795,14 @@ grafana_sso() {
configure_gitea_sso_source() {
local container_name="${LAB_GITEA_CONTAINER_NAME:-homelab-gitea}"
local source_name="${TF_VAR_gitea_auth_source_name:-${LAB_GITEA_DEX_SOURCE_NAME:-dex}}"
local legacy_source_name="${LAB_GITEA_LEGACY_AUTH_SOURCE_NAME:-authentik}"
local client_id="gitea"
local client_secret
local discovery_url
local public_url
local dex_env
local auth_id
local legacy_auth_id
local -a auth_base
dex_env="$(dex_secret_values)" || exit 1
@ -818,6 +822,12 @@ configure_gitea_sso_source() {
auth_base=(sudo docker exec -u git "${container_name}" gitea -c /data/gitea/conf/app.ini admin auth)
auth_id="$("${auth_base[@]}" list | awk -v name="${source_name}" 'NR > 1 && $2 == name { print $1; exit }')"
legacy_auth_id="$("${auth_base[@]}" list | awk -v name="${legacy_source_name}" 'NR > 1 && $2 == name { print $1; exit }')"
if [[ -n "${legacy_auth_id}" && "${legacy_source_name}" != "${source_name}" ]]; then
echo "Removing legacy Gitea auth source ${legacy_source_name} (id ${legacy_auth_id})..."
"${auth_base[@]}" delete --id "${legacy_auth_id}"
fi
if [[ -n "${auth_id}" ]]; then
echo "Updating existing Gitea Dex auth source ${source_name} (id ${auth_id})..."
@ -4351,152 +4361,6 @@ ENV_EOT
echo "Homepage is reachable at http://127.0.0.1:${homepage_http_port}/ and ${homepage_public_url%/}/."
}
deploy_authentik() {
local mode="${LAB_AUTHENTIK_DEPLOY:-true}"
local install_dir="${LAB_AUTHENTIK_INSTALL_DIR:-/data/homelab-authentik}"
local data_dir="${LAB_AUTHENTIK_DATA_DIR:-${install_dir}/data}"
local http_port="${LAB_AUTHENTIK_HTTP_PORT:-9000}"
local bind_ip="${LAB_AUTHENTIK_BIND_IP:-0.0.0.0}"
local public_url="${LAB_AUTHENTIK_PUBLIC_URL:-https://auth.${LAB_DOMAIN:-lab2025.duckdns.org}/}"
local image="${AUTHENTIK_IMAGE:-ghcr.io/goauthentik/server:2026.8.3}"
local postgres_image="${AUTHENTIK_POSTGRES_IMAGE:-postgres:16-alpine}"
local redis_image="${AUTHENTIK_REDIS_IMAGE:-redis:7-alpine}"
local network="${AUTHENTIK_NETWORK:-homelab-authentik}"
local install_docker="${LAB_AUTHENTIK_INSTALL_DOCKER:-false}"
local source_dir="${REPO_ROOT}/infra/authentik"
local secret_file
local key_file
local decrypted_text
local rendered_secret_env
local elapsed=0
local value_name
local value
require_debian_server "deploy-authentik"
if disabled_value "${mode}"; then
return 0
fi
for value_name in install_dir data_dir http_port bind_ip public_url image postgres_image redis_image network install_docker; do
value="${!value_name}"
if [[ "${value}" == *$'\n'* ]]; then
echo "${value_name} cannot contain a newline." >&2
exit 1
fi
done
if [[ ! -s "${source_dir}/docker-compose.yml" ]]; then
echo "Missing Authentik source files in ${source_dir}" >&2
exit 1
fi
ensure_authentik_secret_file
secret_file="$(authentik_secret_file)"
key_file="$(sops_age_key_file)"
if [[ -s "${key_file}" ]]; then
decrypted_text="$(SOPS_AGE_KEY_FILE="${key_file}" sops -d "${secret_file}")" || exit 1
else
decrypted_text="$(sops -d "${secret_file}")" || exit 1
fi
rendered_secret_env="$(SECRET_TEXT="${decrypted_text}" python3 - <<'PY'
import os
import sys
try:
import yaml
except Exception as exc:
print(f"PyYAML is required to parse the Authentik secret: {exc}", file=sys.stderr)
sys.exit(1)
document = yaml.safe_load(os.environ.get("SECRET_TEXT", "")) or {}
values = {}
for section in ("stringData", "data"):
raw = document.get(section) or {}
if isinstance(raw, dict):
values.update(raw)
required = [
"AUTHENTIK_SECRET_KEY",
"AUTHENTIK_POSTGRESQL__PASSWORD",
"AUTHENTIK_BOOTSTRAP_TOKEN",
"AUTHENTIK_BOOTSTRAP_EMAIL",
]
missing = [key for key in required if not values.get(key)]
if missing:
print(f"Missing Authentik secret keys: {', '.join(missing)}", file=sys.stderr)
sys.exit(1)
for key in required:
value = str(values[key])
if "\n" in value or "\r" in value:
print(f"Secret value for {key} cannot contain a newline", file=sys.stderr)
sys.exit(1)
print(f"{key}={value}")
PY
)" || exit 1
echo "Deploying standalone Authentik on the Debian host at ${install_dir}..."
ensure_local_docker_compose "AUTHENTIK" "${install_docker}"
repair_local_docker_iptables
sudo mkdir -p \
"${install_dir}" \
"${data_dir}/postgresql" \
"${data_dir}/redis" \
"${data_dir}/media" \
"${data_dir}/templates"
sudo cp "${source_dir}/docker-compose.yml" "${install_dir}/docker-compose.yml"
sudo tee "${install_dir}/.env" >/dev/null <<ENV_EOT
AUTHENTIK_IMAGE=${image}
AUTHENTIK_POSTGRES_IMAGE=${postgres_image}
AUTHENTIK_REDIS_IMAGE=${redis_image}
AUTHENTIK_SERVER_CONTAINER_NAME=${AUTHENTIK_SERVER_CONTAINER_NAME:-homelab-authentik-server}
AUTHENTIK_WORKER_CONTAINER_NAME=${AUTHENTIK_WORKER_CONTAINER_NAME:-homelab-authentik-worker}
AUTHENTIK_POSTGRES_CONTAINER_NAME=${AUTHENTIK_POSTGRES_CONTAINER_NAME:-homelab-authentik-postgres}
AUTHENTIK_REDIS_CONTAINER_NAME=${AUTHENTIK_REDIS_CONTAINER_NAME:-homelab-authentik-redis}
AUTHENTIK_HTTP_PORT=${http_port}
AUTHENTIK_BIND_IP=${bind_ip}
AUTHENTIK_PUBLIC_URL=${public_url%/}
AUTHENTIK_WEB__BASE_URL=${public_url%/}
AUTHENTIK_LISTEN__TRUSTED_PROXY_CIDRS=127.0.0.0/8,10.0.0.0/8,172.16.0.0/12,192.168.0.0/16,100.64.0.0/10,fe80::/10,::1/128
AUTHENTIK_ERROR_REPORTING__ENABLED=false
AUTHENTIK_POSTGRESQL__HOST=postgresql
AUTHENTIK_POSTGRESQL__NAME=authentik
AUTHENTIK_POSTGRESQL__USER=authentik
AUTHENTIK_REDIS__HOST=redis
AUTHENTIK_POSTGRES_DATA_DIR=${data_dir}/postgresql
AUTHENTIK_REDIS_DATA_DIR=${data_dir}/redis
AUTHENTIK_MEDIA_DIR=${data_dir}/media
AUTHENTIK_TEMPLATES_DIR=${data_dir}/templates
AUTHENTIK_NETWORK=${network}
TZ=America/Mexico_City
${rendered_secret_env}
ENV_EOT
sudo chmod 600 "${install_dir}/.env"
(
cd "${install_dir}"
sudo docker compose --env-file "${install_dir}/.env" pull
sudo docker compose --env-file "${install_dir}/.env" up -d --remove-orphans
sudo docker compose --env-file "${install_dir}/.env" ps
)
until curl -fsS --connect-timeout 5 "http://127.0.0.1:${http_port}/-/health/live/" >/dev/null; do
if ((elapsed >= 900)); then
echo "Timed out waiting for Authentik on http://127.0.0.1:${http_port}/-/health/live/" >&2
(cd "${install_dir}" && sudo docker compose --env-file "${install_dir}/.env" ps && sudo docker compose --env-file "${install_dir}/.env" logs --tail=160) >&2 || true
exit 1
fi
sleep 5
elapsed=$((elapsed + 5))
done
echo "Authentik is reachable at http://127.0.0.1:${http_port}/ and ${public_url%/}/."
}
deploy_matrix() {
local mode="${LAB_MATRIX_DEPLOY:-true}"
local install_dir="${LAB_MATRIX_INSTALL_DIR:-/home/jv/matrix-server}"

View File

@ -358,148 +358,3 @@ dex_secret() {
;;
esac
}
authentik_secret_file() {
printf '%s\n' "${HOMELAB_AUTHENTIK_SECRET_FILE:-${REPO_ROOT}/apps/authentik/authentik.secret.yaml}"
}
generate_authentik_secret_value() {
if command -v openssl >/dev/null 2>&1; then
openssl rand -base64 48 | tr -d '\n'
elif command -v python3 >/dev/null 2>&1; then
python3 - <<'PY'
import secrets
import string
alphabet = string.ascii_letters + string.digits + "-_"
print("".join(secrets.choice(alphabet) for _ in range(64)))
PY
else
echo "openssl or python3 is required to generate Authentik secrets." >&2
return 1
fi
}
ensure_authentik_secret_file() {
local secret_file
local secret_dir
local tmp_file
local secret_key
local postgres_password
local bootstrap_token
local bootstrap_email="${HOMELAB_AUTHENTIK_BOOTSTRAP_EMAIL:-admin@lab2025.duckdns.org}"
secret_file="$(authentik_secret_file)"
if [[ -s "${secret_file}" ]]; then
return 0
fi
ensure_sops_age_tools
secret_dir="$(dirname "${secret_file}")"
mkdir -p "${secret_dir}"
tmp_file="$(mktemp)"
secret_key="$(generate_authentik_secret_value)"
postgres_password="$(generate_authentik_secret_value)"
bootstrap_token="$(generate_authentik_secret_value)"
chmod 600 "${tmp_file}"
{
printf 'apiVersion: v1\n'
printf 'kind: Secret\n'
printf 'metadata:\n'
printf ' name: authentik-secrets\n'
printf ' namespace: authentik\n'
printf ' labels:\n'
printf ' app.kubernetes.io/name: authentik\n'
printf ' app.kubernetes.io/managed-by: jeannie\n'
printf 'type: Opaque\n'
printf 'stringData:\n'
printf ' AUTHENTIK_SECRET_KEY: "%s"\n' "${secret_key}"
printf ' AUTHENTIK_POSTGRESQL__PASSWORD: "%s"\n' "${postgres_password}"
printf ' AUTHENTIK_BOOTSTRAP_TOKEN: "%s"\n' "${bootstrap_token}"
printf ' AUTHENTIK_BOOTSTRAP_EMAIL: "%s"\n' "${bootstrap_email}"
printf ' postgres-password: "%s"\n' "${postgres_password}"
printf ' postgresql-password: "%s"\n' "${postgres_password}"
} >"${tmp_file}"
SOPS_AGE_KEY_FILE="$(sops_age_key_file)" sops \
--encrypt \
--input-type yaml \
--output-type yaml \
--filename-override "${secret_file}" \
"${tmp_file}" >"${secret_file}"
rm -f "${tmp_file}"
chmod 600 "${secret_file}"
echo "Created SOPS-encrypted Authentik secret at ${secret_file}."
echo "Commit this encrypted file after validating the deployment; it contains no plaintext secret."
}
ensure_authentik_secret() {
require_debian_server "authentik-secret"
ensure_authentik_secret_file >/dev/null
echo "Authentik bootstrap secret file is present."
}
authentik_bootstrap_api_token() {
local secret_file
local key_file
local decrypted_text
ensure_authentik_secret_file
secret_file="$(authentik_secret_file)"
key_file="$(sops_age_key_file)"
if [[ -s "${key_file}" ]]; then
decrypted_text="$(SOPS_AGE_KEY_FILE="${key_file}" sops -d "${secret_file}")" || return 1
else
decrypted_text="$(sops -d "${secret_file}")" || return 1
fi
SECRET_TEXT="${decrypted_text}" python3 - <<'PY'
import os
import sys
try:
import yaml
except Exception as exc:
print(f"PyYAML is required to parse the Authentik secret: {exc}", file=sys.stderr)
sys.exit(1)
document = yaml.safe_load(os.environ.get("SECRET_TEXT", "")) or {}
values = document.get("stringData") or document.get("data") or {}
token = str(values.get("AUTHENTIK_BOOTSTRAP_TOKEN", ""))
if not token or "\n" in token or "\r" in token:
print("AUTHENTIK_BOOTSTRAP_TOKEN is missing or invalid.", file=sys.stderr)
sys.exit(1)
print(token)
PY
}
authentik_secret() {
local action="${1:-ensure}"
require_debian_server "authentik-secret"
case "${action}" in
ensure)
ensure_authentik_secret_file
echo "Authentik bootstrap secret file is ready."
;;
apply)
echo "The Authentik Kubernetes secret apply step is deprecated; Authentik now deploys as a standalone Compose stack." >&2
ensure_authentik_secret_file
echo "Authentik bootstrap secret file is ready."
;;
file)
ensure_authentik_secret_file
authentik_secret_file
;;
*)
echo "Usage: ./jeannie authentik-secret {ensure|file}" >&2
exit 1
;;
esac
}