Чтобы настроить Traefik с traefik-forward-auth с помощью Docker Compose версии 2, выполните следующие действия:
Шаг 1. Создайте файл docker-compose.yml
Создайте файл с именем docker-compose.ymlи добавьте следующее содержимое:
version: '2'
services:
reverse-proxy:
image: traefik:v2.5
command:
- "--api.insecure=true"
- "--providers.docker=true"
- "--providers.docker.exposedbydefault=false"
- "--entrypoints.web.address=:80"
- "--entrypoints.websecure.address=:443"
- "--certificatesresolvers.myresolver.acme.tlschallenge=true"
- "--certificatesresolvers.myresolver.acme.email=your-email@example.com"
- "--certificatesresolvers.myresolver.acme.storage=/letsencrypt/acme.json"
ports:
- "80:80"
- "443:443"
volumes:
- "./letsencrypt:/letsencrypt"
- "/var/run/docker.sock:/var/run/docker.sock"
forward-auth:
image: containous/traefik-forward-auth:v2.1.1
command:
- "--config-file=/config/forward-auth.yml"
volumes:
- "./forward-auth.yml:/config/forward-auth.yml"
environment:
- "PROVIDERS_GOOGLE_CLIENT_ID=your-google-client-id"
- "PROVIDERS_GOOGLE_CLIENT_SECRET=your-google-client-secret"
restart: unless-stopped
Шаг 2. Создайте файл front-auth.yml
Создайте файл с именем forward-auth.ymlи добавьте следующее содержимое:
default_action: DENY
providers:
- name: "google"
enabled: true
type: "oidc"
config:
client_id: "${PROVIDERS_GOOGLE_CLIENT_ID}"
client_secret: "${PROVIDERS_GOOGLE_CLIENT_SECRET}"
redirect_url: "https://your-domain.com/_oauth"
scopes: "openid email profile"
prompt: "consent"
auth_url: "https://accounts.google.com/o/oauth2/v2/auth"
token_url: "https://www.googleapis.com/oauth2/v4/token"
userinfo_url: "https://www.googleapis.com/oauth2/v3/userinfo"
allowed_domains:
- "your-domain.com"
Обязательно замените your-email@example.comсвоим фактическим адресом электронной почты, а также your-google-client-idи your-google- client-secretс указанием вашего фактического идентификатора и секрета клиента Google OAuth.
Шаг 3. Запустите службы
Выполните следующую команду, чтобы запустить службы:
docker-compose up -d
Это запустит Traefik и traefik-forward-auth.
Теперь, когда вы получите доступ к своему домену, Traefik перенаправит вас на страницу входа в Google. После успешной аутентификации запрос будет перенаправлен в нужную серверную службу.