# Authentik Identity Provider

> Open source identity provider with SSO, MFA, and user management.

- Category: Security & Networking
- Difficulty: advanced
- Components: authentik-server, authentik-worker, postgresql, redis
- Tags: authentik, sso, identity, oauth, saml, ldap
- Source: https://docker.recipes/security/authentik-sso

## Overview

Authentik is a modern, open-source identity provider designed to centralize authentication and authorization across your entire infrastructure. Born from the need for a more flexible alternative to enterprise solutions like Active Directory or cloud-based identity providers, Authentik supports multiple authentication protocols including OIDC, SAML, OAuth2, and LDAP, making it compatible with virtually any application or service that needs user authentication.

This Docker stack combines Authentik's server and worker components with PostgreSQL for robust data persistence and Redis for high-performance session management and caching. The dual-container Authentik architecture separates the web interface and API (server) from background tasks like user synchronization and certificate management (worker), ensuring optimal performance and scalability. PostgreSQL provides ACID-compliant storage for user data, application configurations, and audit logs, while Redis handles real-time session storage and inter-component communication with sub-millisecond response times.

This configuration is ideal for organizations seeking enterprise-grade identity management without vendor lock-in, homelab enthusiasts wanting to secure their self-hosted applications, and development teams requiring flexible authentication flows. Authentik's flow-based authentication system allows you to customize login experiences, implement complex MFA requirements, and integrate with existing LDAP directories or external identity providers, making it significantly more versatile than simpler proxy-only solutions like Authelia.

## Features

- Multi-protocol authentication support (OIDC, SAML, OAuth2, LDAP) for maximum application compatibility
- Flow-based authentication system allowing custom login, registration, and recovery processes
- Built-in application proxy with header-based authentication for legacy applications
- Multi-factor authentication with TOTP, WebAuthn, and SMS support
- SCIM provisioning for automated user lifecycle management
- Comprehensive audit logging and user session management
- Customizable branding and theming for white-label deployments
- Policy engine for fine-grained access control and conditional authentication

## Use cases

- Homelab single sign-on for Plex, Nextcloud, Grafana, and other self-hosted services
- Small business identity management replacing Google Workspace or Azure AD dependency
- Development team authentication for internal tools, CI/CD systems, and staging environments
- Legacy application modernization using the built-in forward auth proxy
- Multi-tenant SaaS applications requiring custom authentication flows per customer
- Educational institutions needing flexible student and faculty authentication
- Compliance-focused organizations requiring detailed audit trails and MFA enforcement

## Prerequisites

- Minimum 1GB RAM (1.5GB+ recommended) for the full stack including PostgreSQL and Redis
- Ports 9000 and 9443 available for HTTP and HTTPS access to Authentik interface
- Valid domain name and SSL certificate for production deployment (required for OIDC/SAML)
- Basic understanding of identity protocols (OAuth2, SAML) for application integration
- PostgreSQL knowledge for backup strategies and performance tuning
- Network access planning for applications that will integrate with Authentik

## docker-compose.yml

```yaml
services:
  authentik-server:
    image: ghcr.io/goauthentik/server:latest
    command: server
    ports:
      - "9000:9000"
      - "9443:9443"
    environment:
      AUTHENTIK_SECRET_KEY: ${AUTHENTIK_SECRET_KEY}
      AUTHENTIK_REDIS__HOST: redis
      AUTHENTIK_POSTGRESQL__HOST: postgres
      AUTHENTIK_POSTGRESQL__USER: ${POSTGRES_USER}
      AUTHENTIK_POSTGRESQL__NAME: ${POSTGRES_DB}
      AUTHENTIK_POSTGRESQL__PASSWORD: ${POSTGRES_PASSWORD}
    volumes:
      - authentik_media:/media
      - authentik_templates:/templates
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_started
    networks:
      - authentik-net
    restart: unless-stopped

  authentik-worker:
    image: ghcr.io/goauthentik/server:latest
    command: worker
    environment:
      AUTHENTIK_SECRET_KEY: ${AUTHENTIK_SECRET_KEY}
      AUTHENTIK_REDIS__HOST: redis
      AUTHENTIK_POSTGRESQL__HOST: postgres
      AUTHENTIK_POSTGRESQL__USER: ${POSTGRES_USER}
      AUTHENTIK_POSTGRESQL__NAME: ${POSTGRES_DB}
      AUTHENTIK_POSTGRESQL__PASSWORD: ${POSTGRES_PASSWORD}
    volumes:
      - authentik_media:/media
      - authentik_templates:/templates
      - authentik_certs:/certs
    depends_on:
      - authentik-server
    networks:
      - authentik-net
    restart: unless-stopped

  postgres:
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: ${POSTGRES_USER}
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: ${POSTGRES_DB}
    volumes:
      - postgres_data:/var/lib/postgresql/data
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U ${POSTGRES_USER} -d ${POSTGRES_DB}"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - authentik-net
    restart: unless-stopped

  redis:
    image: redis:7-alpine
    volumes:
      - redis_data:/data
    networks:
      - authentik-net
    restart: unless-stopped

volumes:
  authentik_media:
  authentik_templates:
  authentik_certs:
  postgres_data:
  redis_data:

networks:
  authentik-net:
    driver: bridge
```

## .env

```bash
# PostgreSQL
POSTGRES_USER=authentik
POSTGRES_PASSWORD=secure_postgres_password
POSTGRES_DB=authentik

# Authentik
AUTHENTIK_SECRET_KEY=$(openssl rand -hex 50)
```

## Usage notes

- Authentik at http://localhost:9000
- Initial setup: docker compose run --rm authentik-server ak setup
- Supports OAuth2, SAML, LDAP
- Built-in application proxy

## Troubleshooting

- Authentik server fails to start with 'database connection failed': Ensure PostgreSQL is fully initialized by checking docker logs postgres container and waiting for 'database system is ready to accept connections'
- Worker container crashes with 'Redis connection refused': Verify Redis container is running and check network connectivity with docker network inspect authentik-net
- SAML applications show 'invalid signature' errors: Generate proper certificates using docker compose run --rm authentik-server ak create-admin-group and place in authentik_certs volume
- Memory exhaustion causing container restarts: PostgreSQL and Authentik each need 512MB minimum; increase Docker daemon memory limits or add swap
- Session loss after container restart: Verify Redis persistence is working by checking docker volume inspect authentik_redis_data shows proper mount point
- OIDC applications can't connect with 'invalid redirect URI': Ensure Authentik is accessible via HTTPS with valid certificate and configure application redirect URIs to match exactly

