# Authentik Identity Provider

> Authentik open-source identity provider with SSO, MFA, and user management.

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

## Overview

Authentik is a modern, open-source identity provider that consolidates authentication, authorization, and user management into a single platform. Born from the need for a more flexible alternative to traditional identity solutions, Authentik supports multiple authentication protocols including OIDC, OAuth2, SAML, and LDAP, while providing advanced features like flow-based authentication, WebAuthn support, and application proxying. Its architecture emphasizes customization and developer-friendly configuration over rigid enterprise constraints.

This stack combines Authentik's server and worker components with PostgreSQL for robust data persistence and Redis for session management and caching. The server component handles web requests, user authentication flows, and the administration interface, while the worker processes background tasks like user provisioning, email notifications, and SCIM synchronization. PostgreSQL stores user data, application configurations, and audit logs with full ACID compliance, while Redis manages active sessions, caches frequently accessed data, and handles real-time features like WebSocket connections for the admin interface.

This configuration targets organizations seeking comprehensive identity management without vendor lock-in or enterprise licensing costs. Development teams building multiple applications benefit from centralized SSO, while system administrators gain detailed user lifecycle management and compliance reporting. The stack particularly excels in environments requiring custom authentication flows, such as multi-tenant SaaS applications, developer platforms with complex permission models, or organizations integrating legacy systems with modern OAuth-based applications.

## Features

- Multi-protocol authentication support including OIDC, OAuth2, SAML 2.0, and LDAP outbound authentication
- Flow-based authentication system allowing custom multi-step verification processes and conditional logic
- Built-in application proxy with automatic header injection for applications lacking native SSO support
- WebAuthn and TOTP multi-factor authentication with conditional MFA based on user context
- SCIM 2.0 provisioning for automated user lifecycle management across connected applications
- Customizable branding and theming with support for per-application visual identity
- Advanced user and group management with hierarchical permissions and custom attributes
- Comprehensive audit logging with detailed authentication events and administrative actions

## Use cases

- Centralizing authentication for multiple internal applications and services in development teams
- Implementing SSO for legacy applications that lack modern authentication through the application proxy
- Building multi-tenant SaaS platforms requiring customer-specific authentication flows and branding
- Securing homelab environments with professional-grade authentication and MFA capabilities
- Replacing expensive enterprise identity solutions while maintaining compliance and audit requirements
- Integrating disparate systems through standardized OIDC/SAML protocols with custom attribute mapping
- Providing self-service user management portals for organizations with distributed administration needs

## Prerequisites

- Minimum 1.5GB RAM available (512MB for Authentik server, 256MB for PostgreSQL, 128MB for Redis, plus worker overhead)
- Ports 9000 and 9443 available for HTTP and HTTPS access to the Authentik interface
- Domain name or static IP address for consistent callback URL configuration in OAuth applications
- Understanding of OAuth2/OIDC concepts including client credentials, scopes, and redirect URIs
- Docker socket access if using Authentik's Docker integration features for automatic service discovery
- Valid SSL certificates if exposing Authentik publicly for production SSO implementations

## docker-compose.yml

```yaml
services:
  authentik-server:
    image: ghcr.io/goauthentik/server:2024.1
    container_name: authentik-server
    command: server
    environment:
      - AUTHENTIK_REDIS__HOST=redis
      - AUTHENTIK_POSTGRESQL__HOST=postgres
      - AUTHENTIK_POSTGRESQL__USER=${POSTGRES_USER}
      - AUTHENTIK_POSTGRESQL__PASSWORD=${POSTGRES_PASSWORD}
      - AUTHENTIK_POSTGRESQL__NAME=authentik
      - AUTHENTIK_SECRET_KEY=${AUTHENTIK_SECRET_KEY}
    volumes:
      - authentik_media:/media
      - authentik_templates:/templates
    ports:
      - "9000:9000"
      - "9443:9443"
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    networks:
      - authentik-network

  authentik-worker:
    image: ghcr.io/goauthentik/server:2024.1
    container_name: authentik-worker
    command: worker
    environment:
      - AUTHENTIK_REDIS__HOST=redis
      - AUTHENTIK_POSTGRESQL__HOST=postgres
      - AUTHENTIK_POSTGRESQL__USER=${POSTGRES_USER}
      - AUTHENTIK_POSTGRESQL__PASSWORD=${POSTGRES_PASSWORD}
      - AUTHENTIK_POSTGRESQL__NAME=authentik
      - AUTHENTIK_SECRET_KEY=${AUTHENTIK_SECRET_KEY}
    volumes:
      - authentik_media:/media
      - authentik_templates:/templates
      - /var/run/docker.sock:/var/run/docker.sock
    depends_on:
      postgres:
        condition: service_healthy
      redis:
        condition: service_healthy
    networks:
      - authentik-network

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

  redis:
    image: redis:7-alpine
    container_name: authentik-redis
    command: --save 60 1 --loglevel warning
    volumes:
      - redis_data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 10s
      timeout: 5s
      retries: 5
    networks:
      - authentik-network

volumes:
  authentik_media:
  authentik_templates:
  postgres_data:
  redis_data:

networks:
  authentik-network:
    driver: bridge
```

## .env

```bash
# Authentik
POSTGRES_USER=authentik
POSTGRES_PASSWORD=authentik_password
AUTHENTIK_SECRET_KEY=your-secret-key-at-least-50-chars
```

## Usage notes

- Admin interface at http://localhost:9000/if/flow/initial-setup/
- Set up initial admin user on first visit
- Supports OIDC, OAuth2, SAML, LDAP
- Built-in MFA support
- Application proxy for SSO

## Troubleshooting

- Authentik server fails to start with 'database connection failed': Ensure PostgreSQL container is fully initialized before Authentik starts, check database credentials in environment variables
- OAuth applications show 'invalid_client' errors: Verify the client ID and secret match exactly in both Authentik provider configuration and the consuming application
- Users cannot complete authentication flows: Check Redis connectivity as session data may be lost, restart Redis container and clear browser cookies
- SAML assertions fail validation: Ensure clock synchronization between Authentik and service provider, check certificate validity and metadata exchange
- Background tasks not processing (password resets, emails): Authentik worker container may be failing, check worker logs for Celery connection issues to Redis
- Performance degradation with many users: Increase PostgreSQL shared_buffers and Redis maxmemory settings, consider connection pooling for high-traffic scenarios

