# Authentik Identity Provider

> Authentik for SSO, MFA, and identity management.

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

## Overview

Authentik is an open-source identity provider that serves as a comprehensive authentication and authorization platform for modern applications. Originally developed to address the complexity and cost limitations of traditional IAM solutions, Authentik focuses on flexibility and ease of deployment while supporting multiple authentication protocols including OIDC, SAML, OAuth2, and LDAP. It features a unique flow-based authentication system that allows administrators to create custom login experiences and implement sophisticated security policies. This deployment creates a complete identity management infrastructure using four specialized containers: authentik-db runs a PostgreSQL 15 database for storing user data and configuration, authentik-redis provides session storage and caching, authentik-server handles the web interface and API endpoints, and authentik-worker processes background tasks like user synchronization and email notifications. The architecture separates concerns effectively, with the server component managing user-facing operations while the worker handles intensive background processes. This configuration is ideal for organizations seeking a self-hosted alternative to cloud identity providers like Auth0 or Okta, particularly those requiring GDPR compliance, custom branding, or integration with existing LDAP directories. The stack provides enterprise-grade features including multi-factor authentication with TOTP and WebAuthn, SCIM provisioning for automated user management, and comprehensive audit logging for compliance requirements.

## Features

- Multi-protocol authentication support (OIDC, SAML 2.0, OAuth2, LDAP) for universal application compatibility
- Flow-based authentication engine allowing custom login sequences and conditional security policies
- Built-in application proxy for protecting legacy applications without native SSO support
- WebAuthn and TOTP multi-factor authentication with passwordless login capabilities
- SCIM 2.0 provisioning for automated user lifecycle management across connected applications
- Customizable branding and theming with white-label support for customer-facing deployments
- Real-time audit logging and session management with detailed security event tracking
- LDAP outpost functionality for synchronizing with Active Directory and other directory services

## Use cases

- Homelab SSO implementation for self-hosted services like Nextcloud, Grafana, and media servers
- Small to medium business identity management replacing expensive SaaS solutions
- Development team authentication for internal tools, CI/CD pipelines, and staging environments
- Educational institutions managing student and faculty access across multiple platforms
- Compliance-focused organizations requiring on-premises identity data storage
- Multi-tenant SaaS platforms needing white-label authentication for customer portals
- Legacy application modernization using the built-in proxy for SSO integration

## Prerequisites

- Minimum 2GB RAM and 2 CPU cores for production workloads with moderate user base
- Available ports 9000 (HTTP) and 9443 (HTTPS) for Authentik web interface access
- Valid SSL certificates for production deployments to ensure secure authentication flows
- Basic understanding of OAuth2/OIDC concepts for application integration configuration
- SMTP server credentials for user registration, password reset, and notification emails
- Domain name with proper DNS configuration for production SSO functionality

## docker-compose.yml

```yaml
services:
  authentik-db:
    image: postgres:15-alpine
    container_name: authentik-db
    restart: unless-stopped
    environment:
      - POSTGRES_USER=authentik
      - POSTGRES_PASSWORD=${DB_PASSWORD}
      - POSTGRES_DB=authentik
    volumes:
      - authentik_db_data:/var/lib/postgresql/data

  authentik-redis:
    image: redis:7-alpine
    container_name: authentik-redis
    restart: unless-stopped

  authentik-server:
    image: ghcr.io/goauthentik/server:latest
    container_name: authentik-server
    restart: unless-stopped
    command: server
    ports:
      - "${AUTHENTIK_PORT:-9000}:9000"
      - "${AUTHENTIK_SSL_PORT:-9443}:9443"
    environment:
      - AUTHENTIK_REDIS__HOST=authentik-redis
      - AUTHENTIK_POSTGRESQL__HOST=authentik-db
      - AUTHENTIK_POSTGRESQL__USER=authentik
      - AUTHENTIK_POSTGRESQL__PASSWORD=${DB_PASSWORD}
      - AUTHENTIK_SECRET_KEY=${SECRET_KEY}
    volumes:
      - authentik_media:/media
    depends_on:
      - authentik-db
      - authentik-redis

  authentik-worker:
    image: ghcr.io/goauthentik/server:latest
    container_name: authentik-worker
    restart: unless-stopped
    command: worker
    environment:
      - AUTHENTIK_REDIS__HOST=authentik-redis
      - AUTHENTIK_POSTGRESQL__HOST=authentik-db
      - AUTHENTIK_POSTGRESQL__USER=authentik
      - AUTHENTIK_POSTGRESQL__PASSWORD=${DB_PASSWORD}
      - AUTHENTIK_SECRET_KEY=${SECRET_KEY}
    volumes:
      - authentik_media:/media
    depends_on:
      - authentik-db
      - authentik-redis

volumes:
  authentik_db_data:
  authentik_media:
```

## .env

```bash
# Authentik
AUTHENTIK_PORT=9000
AUTHENTIK_SSL_PORT=9443
DB_PASSWORD=authentik_password
SECRET_KEY=your-very-secret-key
```

## Usage notes

- Authentik at http://localhost:9000
- Initial setup at /if/flow/initial-setup/
- Configure OAuth2/OIDC apps
- Built-in MFA support

## Troubleshooting

- authentik-server fails to start with database connection errors: Verify DB_PASSWORD environment variable matches between authentik-db and authentik-server containers
- Initial setup page shows 'Redis connection failed': Ensure authentik-redis container is running and check Docker network connectivity between services
- Applications can't connect to OIDC endpoint: Confirm authentik-server port 9000 is accessible and configure proper redirect URIs in application settings
- Background tasks not processing (user sync, emails): Check authentik-worker container logs and verify it shares the same SECRET_KEY as authentik-server
- PostgreSQL data corruption after container restart: Ensure authentik_db_data volume has proper permissions and sufficient disk space for database operations
- WebAuthn authentication fails in browsers: Configure proper HTTPS with valid certificates as WebAuthn requires secure contexts for biometric authentication

