feat(auth): deploy Authentik on CT 902 with Zero-Knowledge secret bootstrap and safe Traefik route
ansible-core-net / deploy (push) Successful in 2m39s
ansible-core-net / deploy (push) Successful in 2m39s
This commit is contained in:
1 parent
aad9733753
commit
10cf792e4e
7 files changed
+185
-2
No files matched your search
@@ -0,0 +1,6 @@
|
||||
---
|
||||
authentik_version: "2024.12.3"
|
||||
authentik_dir: "/opt/authentik"
|
||||
authentik_http_port: 9000
|
||||
authentik_secret_key: "{{ lookup('env', 'AUTHENTIK_SECRET_KEY') }}"
|
||||
authentik_postgres_password: "{{ lookup('env', 'AUTHENTIK_POSTGRES_PASSWORD') }}"
|
||||
@@ -0,0 +1,35 @@
|
||||
---
|
||||
- name: Создать каталоги для сервиса Authentik
|
||||
ansible.builtin.file:
|
||||
path: "{{ item }}"
|
||||
state: directory
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0750"
|
||||
loop:
|
||||
- "{{ authentik_dir }}"
|
||||
- "{{ authentik_dir }}/db"
|
||||
- "{{ authentik_dir }}/redis"
|
||||
- "{{ authentik_dir }}/media"
|
||||
- "{{ authentik_dir }}/custom-templates"
|
||||
|
||||
- name: Проверить наличие обязательных секретов Authentik
|
||||
ansible.builtin.assert:
|
||||
that:
|
||||
- authentik_secret_key is defined and authentik_secret_key | length > 0
|
||||
- authentik_postgres_password is defined and authentik_postgres_password | length > 0
|
||||
fail_msg: "Один или оба секрета Authentik (AUTHENTIK_SECRET_KEY, AUTHENTIK_POSTGRES_PASSWORD) не переданы через переменные окружения!"
|
||||
|
||||
- name: Установить compose.yaml для Authentik
|
||||
ansible.builtin.template:
|
||||
src: compose.yaml.j2
|
||||
dest: "{{ authentik_dir }}/compose.yaml"
|
||||
owner: root
|
||||
group: root
|
||||
mode: "0600"
|
||||
no_log: true
|
||||
|
||||
- name: Запустить сервисы Authentik через Docker Compose
|
||||
ansible.builtin.command: docker compose -f {{ authentik_dir }}/compose.yaml up -d --remove-orphans
|
||||
register: compose_up
|
||||
changed_when: "'Started' in compose_up.stderr or 'Created' in compose_up.stderr or 'Recreated' in compose_up.stderr or 'Pulled' in compose_up.stderr"
|
||||
@@ -0,0 +1,87 @@
|
||||
services:
|
||||
authentik-db:
|
||||
image: postgres:16-alpine
|
||||
container_name: authentik-db
|
||||
restart: unless-stopped
|
||||
environment:
|
||||
POSTGRES_PASSWORD: {{ authentik_postgres_password }}
|
||||
POSTGRES_USER: authentik
|
||||
POSTGRES_DB: authentik
|
||||
volumes:
|
||||
- {{ authentik_dir }}/db:/var/lib/postgresql/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "pg_isready -d authentik -U authentik"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
networks:
|
||||
- authentik-net
|
||||
|
||||
authentik-redis:
|
||||
image: redis:alpine
|
||||
container_name: authentik-redis
|
||||
restart: unless-stopped
|
||||
volumes:
|
||||
- {{ authentik_dir }}/redis:/data
|
||||
healthcheck:
|
||||
test: ["CMD-SHELL", "redis-cli ping | grep PONG"]
|
||||
interval: 5s
|
||||
timeout: 5s
|
||||
retries: 10
|
||||
networks:
|
||||
- authentik-net
|
||||
|
||||
authentik-server:
|
||||
image: ghcr.io/goauthentik/server:{{ authentik_version }}
|
||||
container_name: authentik-server
|
||||
restart: unless-stopped
|
||||
command: server
|
||||
environment:
|
||||
AUTHENTIK_REDIS__HOST: authentik-redis
|
||||
AUTHENTIK_POSTGRESQL__HOST: authentik-db
|
||||
AUTHENTIK_POSTGRESQL__USER: authentik
|
||||
AUTHENTIK_POSTGRESQL__NAME: authentik
|
||||
AUTHENTIK_POSTGRESQL__PASSWORD: {{ authentik_postgres_password }}
|
||||
AUTHENTIK_SECRET_KEY: {{ authentik_secret_key }}
|
||||
volumes:
|
||||
- {{ authentik_dir }}/media:/media
|
||||
- {{ authentik_dir }}/custom-templates:/templates
|
||||
ports:
|
||||
- "127.0.0.1:{{ authentik_http_port }}:9000"
|
||||
depends_on:
|
||||
authentik-db:
|
||||
condition: service_healthy
|
||||
authentik-redis:
|
||||
condition: service_healthy
|
||||
networks:
|
||||
- authentik-net
|
||||
|
||||
authentik-worker:
|
||||
image: ghcr.io/goauthentik/server:{{ authentik_version }}
|
||||
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__NAME: authentik
|
||||
AUTHENTIK_POSTGRESQL__PASSWORD: {{ authentik_postgres_password }}
|
||||
AUTHENTIK_SECRET_KEY: {{ authentik_secret_key }}
|
||||
user: root
|
||||
volumes:
|
||||
- /var/run/docker.sock:/var/run/docker.sock
|
||||
- {{ authentik_dir }}/media:/media
|
||||
- {{ authentik_dir }}/custom-templates:/templates
|
||||
depends_on:
|
||||
authentik-db:
|
||||
condition: service_healthy
|
||||
authentik-redis:
|
||||
condition: service_healthy
|
||||
networks:
|
||||
- authentik-net
|
||||
|
||||
networks:
|
||||
authentik-net:
|
||||
name: authentik-net
|
||||
driver: bridge
|
||||
@@ -0,0 +1,33 @@
|
||||
http:
|
||||
routers:
|
||||
authentik:
|
||||
rule: "Host(`auth.gunihome.ru`)"
|
||||
entryPoints:
|
||||
- websecure
|
||||
service: authentik
|
||||
tls:
|
||||
certResolver: letsencrypt
|
||||
|
||||
services:
|
||||
authentik:
|
||||
loadBalancer:
|
||||
servers:
|
||||
- url: "http://127.0.0.1:9000"
|
||||
|
||||
middlewares:
|
||||
authentik:
|
||||
forwardAuth:
|
||||
address: "http://127.0.0.1:9000/outpost.goauthentik.io/auth/traefik"
|
||||
trustForwardHeader: true
|
||||
authResponseHeaders:
|
||||
- "X-authentik-username"
|
||||
- "X-authentik-groups"
|
||||
- "X-authentik-email"
|
||||
- "X-authentik-name"
|
||||
- "X-authentik-uid"
|
||||
- "X-authentik-jwt"
|
||||
- "X-authentik-meta-jwks"
|
||||
- "X-authentik-meta-outpost"
|
||||
- "X-authentik-meta-provider"
|
||||
- "X-authentik-meta-app"
|
||||
- "X-authentik-meta-version"
|
||||
Reference in new issue
Block a user