Authentik SSO Server Installation
Authentik SSO Server Installation – Self-Hosted Identity Provider
Was ist Authentik?
Authentik ist ein modernen, Open-Source Identity Provider (IdP), der als Alternative zu Keycloak dient. Authentik zeichnet sich durch eine intuitive Benutzeroberfläche, einfachere Konfiguration und schnellere Deployment aus. Es unterstützt OAuth2, OIDC, SAML und weitere Authentifizierungsprotokolle.
Vorteile gegenüber Keycloak
- Modernes UI/UX Design
- Einfachere erste Einrichtung
- Weniger Speicherbedarf
- Schnelleres Deployment
- Gutes Dashboard und Monitoring
- Flexibles Policy Engine System
- Built-in Logging und Audit Trail
Voraussetzungen
- Ubuntu 20.04 oder neuer
- Docker und Docker Compose
- PostgreSQL für die Datenbank
- Redis für Caching
- Nginx als Reverse Proxy (optional, aber empfohlen)
- Eine Domain (z.B. auth.example.com)
- Mindestens 2GB RAM
Installation mit Docker Compose
Schritt 1: Verzeichnis und Dateien erstellen
mkdir -p /opt/authentik cd /opt/authentik mkdir -p geoip
Schritt 2: Secret Key generieren
openssl rand -base64 32 > SECRET_KEY.txt chmod 600 SECRET_KEY.txt
Schritt 3: .env-Datei erstellen
cat > .env << 'EOF' AUTHENTIK_SECRET_KEY=$(cat SECRET_KEY.txt) AUTHENTIK_POSTGRESQL__PASSWORD=auth-postgres-password AUTHENTIK_REDIS__PASSWORD=auth-redis-password AUTHENTIK_POSTGRESQL__HOST=postgres AUTHENTIK_POSTGRESQL__NAME=authentik AUTHENTIK_POSTGRESQL__USER=authentik AUTHENTIK_REDIS__HOST=redis AUTHENTIK_REDIS__DB=0 AUTHENTIK_LOG_LEVEL=info AUTHENTIK_ERROR_REPORTING__ENABLED=false EOF chmod 600 .env
Schritt 4: docker-compose.yml erstellen
cat > docker-compose.yml << 'EOF'
version: '3.4'
services:
postgres:
image: postgres:15-alpine
container_name: authentik-postgres
restart: always
environment:
POSTGRES_PASSWORD: ${AUTHENTIK_POSTGRESQL__PASSWORD}
POSTGRES_USER: ${AUTHENTIK_POSTGRESQL__USER}
POSTGRES_DB: ${AUTHENTIK_POSTGRESQL__NAME}
volumes:
- postgres_data:/var/lib/postgresql/data
networks:
- authentik-net
redis:
image: redis:7-alpine
container_name: authentik-redis
restart: always
command: redis-server --requirepass ${AUTHENTIK_REDIS__PASSWORD}
volumes:
- redis_data:/data
networks:
- authentik-net
server:
image: ghcr.io/goauthentik/server:latest
container_name: authentik-server
restart: always
command: server
environment:
AUTHENTIK_REDIS__HOST: ${AUTHENTIK_REDIS__HOST}
AUTHENTIK_REDIS__DB: ${AUTHENTIK_REDIS__DB}
AUTHENTIK_POSTGRESQL__HOST: ${AUTHENTIK_POSTGRESQL__HOST}
AUTHENTIK_POSTGRESQL__NAME: ${AUTHENTIK_POSTGRESQL__NAME}
AUTHENTIK_POSTGRESQL__USER: ${AUTHENTIK_POSTGRESQL__USER}
AUTHENTIK_POSTGRESQL__PASSWORD: ${AUTHENTIK_POSTGRESQL__PASSWORD}
AUTHENTIK_SECRET_KEY: ${AUTHENTIK_SECRET_KEY}
AUTHENTIK_LOG_LEVEL: ${AUTHENTIK_LOG_LEVEL}
AUTHENTIK_ERROR_REPORTING__ENABLED: ${AUTHENTIK_ERROR_REPORTING__ENABLED}
ports:
- "9000:9000"
- "9443:9443"
depends_on:
- postgres
- redis
volumes:
- ./geoip:/geoip
- media:/media
networks:
- authentik-net
worker:
image: ghcr.io/goauthentik/server:latest
container_name: authentik-worker
restart: always
command: worker
environment:
AUTHENTIK_REDIS__HOST: ${AUTHENTIK_REDIS__HOST}
AUTHENTIK_REDIS__DB: ${AUTHENTIK_REDIS__DB}
AUTHENTIK_POSTGRESQL__HOST: ${AUTHENTIK_POSTGRESQL__HOST}
AUTHENTIK_POSTGRESQL__NAME: ${AUTHENTIK_POSTGRESQL__NAME}
AUTHENTIK_POSTGRESQL__USER: ${AUTHENTIK_POSTGRESQL__USER}
AUTHENTIK_POSTGRESQL__PASSWORD: ${AUTHENTIK_POSTGRESQL__PASSWORD}
AUTHENTIK_SECRET_KEY: ${AUTHENTIK_SECRET_KEY}
AUTHENTIK_LOG_LEVEL: ${AUTHENTIK_LOG_LEVEL}
AUTHENTIK_ERROR_REPORTING__ENABLED: ${AUTHENTIK_ERROR_REPORTING__ENABLED}
depends_on:
- postgres
- redis
networks:
- authentik-net
volumes:
postgres_data:
redis_data:
media:
networks:
authentik-net:
driver: bridge
EOF
Nginx Reverse Proxy Konfiguration
Nginx-Konfiguration erstellen
cat > /etc/nginx/sites-available/authentik << 'EOF'
upstream authentik {
server 127.0.0.1:9000;
}
server {
listen 80;
server_name auth.example.com;
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
server_name auth.example.com;
ssl_certificate /etc/letsencrypt/live/auth.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/auth.example.com/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
client_max_body_size 10M;
location / {
proxy_pass https://authentik;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_ssl_verify off;
proxy_http_version 1.1;
proxy_set_header Connection "";
}
location /outpost.goauthentik.io {
proxy_pass https://authentik;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_ssl_verify off;
}
}
EOF
Nginx aktivieren
sudo ln -s /etc/nginx/sites-available/authentik /etc/nginx/sites-enabled/ sudo nginx -t sudo systemctl restart nginx # SSL-Zertifikat mit Let's Encrypt sudo apt-get install certbot python3-certbot-nginx sudo certbot certonly --nginx -d auth.example.com
Authentik starten
cd /opt/authentik docker-compose up -d
Überprüfen Sie die Logs:
docker-compose logs -f server
Initiales Setup und Admin-Zugang
Authentik Interface aufrufen
Öffnen Sie: https://auth.example.com/if/flow/initial-setup/
Hier erstellen Sie den ersten Admin-Benutzer:
- Benutzername: admin
- E-Mail: admin@example.com
- Passwort: (starkes Passwort)
Nach Setup – Admin Konsole aufrufen
https://auth.example.com/admin
Application erstellen (OAuth2/OIDC)
Schritt 1: Provider erstellen
- Im Admin-Panel: Applications → Providers
- "Create" → "OAuth2/OpenID Connect (OpenID Connect)" wählen
- Name: z.B. "meine-app-provider"
- Client type: Standard
- Redirect URIs: https://myapp.example.com/oauth2/callback
Schritt 2: Application erstellen
- Applications → Applications
- "Create" klicken
- Name: Meine Anwendung
- Slug: meine-app
- Provider: Den gerade erstellten Provider auswählen
Provider-Detailinformationen
Nach Erstellen finden Sie im Provider:
- Client ID: Kopieren Sie diese für Ihre Anwendung
- Client Secret: Auch dies speichern Sie sicher
- Token Endpoint: https://auth.example.com/application/o/token/
- Authorization Endpoint: https://auth.example.com/application/o/authorize/
- Userinfo Endpoint: https://auth.example.com/application/o/userinfo/
Outpost erstellen (für App-Integration)
Proxy-Outpost (für Forward Auth)
- Infrastructure → Outposts
- "Create" → "Proxy"
- Name: proxy-outpost
- Applications: Die erstellte Application auswählen
- Generate token (wird für Docker-Deployment benötigt)
Mit einem Outpost können Sie sich vor beliebigen Apps authentifizieren, ohne dass diese Authentik kennen müssen.
Test mit curl
OAuth2 Token abrufen
curl -X POST "https://auth.example.com/application/o/token/" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "grant_type=client_credentials" \ -d "client_id=YOUR_CLIENT_ID" \ -d "client_secret=YOUR_CLIENT_SECRET" \ -k
Benutzerinformationen abrufen
curl -X GET "https://auth.example.com/application/o/userinfo/" \ -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \ -k
Benutzer und Gruppen verwalten
Benutzer erstellen
- Admin Panel → Directory → Users
- "Create" klicken
- Username: z.B. max.mustermann
- Name: Max Mustermann
- E-Mail: max@example.com
- Passwort setzen oder Benutzer selbst setzen lassen
Gruppen erstellen
- Directory → Groups
- "Create" klicken
- Name: z.B. "admins"
- Benutzer zur Gruppe hinzufügen
Policies und Zugriffskontrolle
Policy erstellen
Authentik hat ein flexibles Policy-System. Sie können damit kontrollieren, wer auf was zugreifen darf.
- Admin Panel → Policies
- "Create" → Policy Type wählen (z.B. "Expression Policy")
- Name: z.B. "allow-admins-only"
- Code beispiel:
return request.user.groups.filter(g => g.name == 'admins').exists()
Policy auf Application anwenden
- Applications → Policy Bindings
- Application und Policy wählen
- Order setzen (niedrigere Zahlen = höhere Priorität)
Authentik vs. Keycloak – Vergleich
| Merkmal | Authentik | Keycloak |
|---|---|---|
| Setup-Zeit | 10-15 Minuten | 20-30 Minuten |
| UI Qualität | Modernes Design, sehr intuitiv | Funktional, weniger intuitiv |
| Memory-Footprint | Niedriger (~300-500MB) | Höher (~1-2GB) |
| Protokoll-Support | OAuth2, OIDC, SAML, LDAP | OAuth2, OIDC, SAML, LDAP, mehr |
| Skalierbarkeit | Gut für kleine bis mittlere Umgebungen | Sehr gut auch für große Umgebungen |
| Dokumentation | Gut und kontinuierlich verbessert | Sehr umfangreich |
Häufige Aufgaben
Passwort zurücksetzen
Admin Panel → Directory → Users → Benutzer auswählen → Passwort setzen
User exportieren
Directory → Users → Mehr Optionen → Export
Audit-Logs anschauen
Admin Panel → System → Audit Log
Backup und Update
Datenbank-Backup
docker-compose exec postgres pg_dump -U authentik authentik > backup.sql
Vollständiges Backup
tar -czf authentik-backup-$(date +%Y%m%d).tar.gz /opt/authentik/
Update durchführen
cd /opt/authentik docker-compose pull docker-compose down docker-compose up -d