Authelia — портал входа с 2FA для сервисов за Traefik: один логин и TOTP вместо отдельной auth у каждого UI. Работает через middleware forwardAuth.
Ниже — минимальный набор: Authelia + Redis. Нужны рабочий Traefik и сеть traefik_network.
mkdir -p ~/authelia
cd ~/authelia
openssl rand -hex 64
openssl rand -hex 64
Первая строка — JWT_SECRET, вторая — SESSION_SECRET. Сохраните их.
configuration.ymltheme: auto
server:
address: 'tcp://0.0.0.0:9091'
log:
level: info
totp:
issuer: yourdomain
authentication_backend:
file:
path: /config/users_database.yml
password:
algorithm: argon2id
access_control:
default_policy: deny
rules:
- domain: 'auth.yourdomain'
policy: bypass
- domain: '*.yourdomain'
policy: two_factor
session:
name: authelia_session
secret: 'CHANGE_ME_SESSION'
expiration: 1h
inactivity: 15m
cookies:
- domain: 'yourdomain'
authelia_url: 'https://auth.yourdomain'
default_redirection_url: 'https://yourdomain'
regulation:
max_retries: 3
find_time: 2m
ban_time: 5m
storage:
local:
path: /config/db.sqlite3
notifier:
filesystem:
filename: /config/notification.txt
Для продакшена вместо filesystem notifier обычно ставят SMTP.
docker run --rm authelia/authelia:latest \
authelia crypto hash generate argon2 --password 'YourStrongPassword'
Создайте users_database.yml:
users:
admin:
disabled: false
displayname: Admin
password: '$argon2id$...' # вывод команды выше
email: admin@yourdomain
groups:
- admins
docker-compose.ymlservices:
redis:
image: redis:7-alpine
container_name: authelia-redis
restart: unless-stopped
command: redis-server --save 60 1
volumes:
- redis_data:/data
authelia:
image: authelia/authelia:latest
container_name: authelia
restart: unless-stopped
environment:
TZ: Europe/Moscow
volumes:
- ./configuration.yml:/config/configuration.yml:ro
- ./users_database.yml:/config/users_database.yml
- authelia_data:/config
depends_on:
- redis
labels:
- traefik.enable=true
- traefik.http.middlewares.authelia_https.redirectscheme.scheme=https
- traefik.http.routers.authelia.entrypoints=web
- traefik.http.routers.authelia.middlewares=authelia_https@docker
- traefik.http.routers.authelia.rule=Host(`auth.yourdomain`)
- traefik.http.routers.authelia_https.entrypoints=websecure
- traefik.http.routers.authelia_https.rule=Host(`auth.yourdomain`)
- traefik.http.routers.authelia_https.tls=true
- traefik.http.routers.authelia_https.tls.certresolver=le
- traefik.http.services.authelia.loadbalancer.server.port=9091
- traefik.http.middlewares.authelia.forwardauth.address=http://authelia:9091/api/authz/forward-auth
- traefik.http.middlewares.authelia.forwardauth.trustForwardHeader=true
- traefik.http.middlewares.authelia.forwardauth.authResponseHeaders=Remote-User,Remote-Groups,Remote-Name,Remote-Email
networks:
- traefik_network
volumes:
redis_data:
authelia_data:
networks:
traefik_network:
external: true
Секрет сессии задайте в configuration.yml (поле session.secret) — тем же значением, что сгенерировали.
На нужном роутере Traefik добавьте middleware:
- traefik.http.routers.myservice_https.middlewares=authelia@docker
docker compose up -d
Откройте https://auth.yourdomain, войдите, привяжите TOTP в приложении-аутентификаторе.
yourdomain).authelia_data и users_database.yml.Итог: единый вход с 2FA для панелей за Traefik.