# Authelia

> SSO portal with multi-factor authentication.

- Category: Security & Networking
- Difficulty: advanced
- Components: authelia, redis
- Tags: authelia, sso, 2fa, authentication
- Source: https://docker.recipes/security/authelia

## Overview

Authelia is an open-source authentication and authorization server that provides single sign-on (SSO), multi-factor authentication (MFA), and access control for modern web applications. Originally developed to address the security challenges of self-hosted services and microservice architectures, Authelia acts as a forward authentication provider that integrates with reverse proxies like Traefik, nginx, and HAProxy to protect applications without requiring code changes to existing services.

This stack combines Authelia with Redis to create a high-performance authentication infrastructure. Redis serves as the session store and cache for Authelia, providing sub-millisecond response times for authentication checks and session management. The pairing ensures that authentication decisions are lightning-fast while maintaining security through features like brute-force protection, session invalidation, and real-time policy enforcement across multiple applications.

This configuration is ideal for organizations running multiple internal applications, homelab enthusiasts securing self-hosted services, and development teams needing centralized authentication for microservices. The Redis backend enables Authelia to scale horizontally and provides the reliability needed for production authentication workflows, making it suitable for everything from small team setups to enterprise-grade deployments with thousands of users.

## Features

- Multi-factor authentication support including TOTP, WebAuthn (passwordless), Duo Push, and mobile push notifications
- Fine-grained access control policies with support for domain-based, path-based, and user/group-based rules
- Forward authentication integration with popular reverse proxies without application code modifications
- Redis-backed session management providing sub-millisecond authentication checks and horizontal scaling capability
- LDAP/Active Directory integration for enterprise user directories and group-based access controls
- Comprehensive audit logging and security event tracking for compliance and monitoring requirements
- Password reset workflows with secure token generation and email-based verification
- Brute-force protection with Redis-based rate limiting and automatic account lockout mechanisms

## Use cases

- Protecting multiple self-hosted applications (Nextcloud, Grafana, Sonarr) with centralized SSO and MFA
- Securing microservices architecture with per-service access policies and user authentication
- Enterprise internal application gateway requiring LDAP integration and compliance logging
- Development team authentication for staging environments and internal tools
- Homelab security layer for personal cloud services and media management applications
- Multi-tenant SaaS application authentication with per-tenant access controls
- Remote access security for internal company resources and admin panels

## Prerequisites

- Minimum 512MB RAM for Redis session storage and 1GB for Authelia application server
- Domain names or subdomains for services requiring authentication protection
- Reverse proxy (Traefik, nginx, HAProxy) configured for forward authentication integration
- SMTP server credentials for password reset emails and security notifications
- SSL/TLS certificates for secure authentication flows and session cookie protection
- Understanding of YAML configuration for Authelia's complex policy and user management rules

## docker-compose.yml

```yaml
services:
  authelia:
    image: authelia/authelia:latest
    container_name: authelia
    restart: unless-stopped
    environment:
      TZ: UTC
    volumes:
      - ./authelia:/config
    ports:
      - "9091:9091"
    depends_on:
      - redis

  redis:
    image: redis:7-alpine
    container_name: authelia-redis
    restart: unless-stopped
    volumes:
      - authelia_redis:/data

volumes:
  authelia_redis:
```

## .env

```bash
# Configure authelia/configuration.yml
# See docs.authelia.com for setup
```

## Usage notes

- Docs: https://www.authelia.com/docs/
- Portal at http://localhost:9091
- Create configuration.yml in ./authelia folder before starting
- Configure reverse proxy (Traefik/nginx) for forward auth
- Supports TOTP, Duo, WebAuthn for 2FA
- Access rules defined in configuration.yml by domain/resource

## Troubleshooting

- Authentication loops or redirects: Verify reverse proxy forward auth configuration matches Authelia's expected headers and endpoints
- Redis connection failures: Check Redis container health and ensure Authelia configuration.yml points to correct Redis hostname and port
- TOTP codes not working: Confirm system time synchronization between Authelia container and client devices using NTP
- Access denied despite correct credentials: Review access control rules in configuration.yml for proper domain/path matching and user group assignments
- Session timeouts too aggressive: Adjust Redis session expiration and Authelia's session configuration for appropriate timeout values
- Email notifications not sending: Verify SMTP configuration in Authelia settings and check container logs for authentication errors with mail server

