feat(auth): integrate Grafana and Ntfy with Authentik SSO
ansible-core-mon / deploy (push) Successful in 24s
ansible-core-net / deploy (push) Successful in 39s
ansible-core-secrets / deploy (push) Successful in 12s
ansible-opnsense / deploy (push) Successful in 3s
ansible-rus-central / deploy (push) Successful in 36s
ansible-core-mon / deploy (push) Successful in 24s
ansible-core-net / deploy (push) Successful in 39s
ansible-core-secrets / deploy (push) Successful in 12s
ansible-opnsense / deploy (push) Successful in 3s
ansible-rus-central / deploy (push) Successful in 36s
This commit is contained in:
1 parent
3670bb6033
commit
811d65526b
9 files changed
+174
-6
No files matched your search
@@ -58,9 +58,19 @@ case "$machine" in
|
|||||||
--silent
|
--silent
|
||||||
unset GEN_SECRET_KEY GEN_PG_PASS
|
unset GEN_SECRET_KEY GEN_PG_PASS
|
||||||
fi
|
fi
|
||||||
|
if ! infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/services/authentik" --format=dotenv-export --silent 2>/dev/null | grep -q 'GRAFANA_OAUTH_CLIENT_SECRET'; then
|
||||||
|
infisical secrets-manager folders create authentik --path /services --env prod --projectId "${INFISICAL_PROJECT_ID}" --domain "${INFISICAL_DOMAIN}" --token "${TOKEN}" --silent 2>/dev/null || true
|
||||||
|
GEN_OAUTH_SECRET=$(openssl rand -base64 48 | tr -dc 'a-zA-Z0-9' | head -c 48)
|
||||||
|
infisical secrets set --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/services/authentik" \
|
||||||
|
"GRAFANA_OAUTH_CLIENT_SECRET=${GEN_OAUTH_SECRET}" \
|
||||||
|
--silent
|
||||||
|
unset GEN_OAUTH_SECRET
|
||||||
|
fi
|
||||||
eval "$(infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/services/authentik" --format=dotenv-export --silent)"
|
eval "$(infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/services/authentik" --format=dotenv-export --silent)"
|
||||||
export AUTHENTIK_SECRET_KEY="${AUTHENTIK_SECRET_KEY:-}"
|
export AUTHENTIK_SECRET_KEY="${AUTHENTIK_SECRET_KEY:-}"
|
||||||
export AUTHENTIK_POSTGRES_PASSWORD="${AUTHENTIK_POSTGRES_PASSWORD:-}"
|
export AUTHENTIK_POSTGRES_PASSWORD="${AUTHENTIK_POSTGRES_PASSWORD:-}"
|
||||||
|
export GRAFANA_OAUTH_CLIENT_SECRET="${GRAFANA_OAUTH_CLIENT_SECRET:-}"
|
||||||
|
extra+=(-e "grafana_oauth_client_secret=${GRAFANA_OAUTH_CLIENT_SECRET:-}")
|
||||||
;;
|
;;
|
||||||
core-secrets)
|
core-secrets)
|
||||||
eval "$(infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/services/infisical" --format=dotenv-export --silent)"
|
eval "$(infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/services/infisical" --format=dotenv-export --silent)"
|
||||||
@@ -78,9 +88,20 @@ case "$machine" in
|
|||||||
--silent
|
--silent
|
||||||
unset GEN_GRAFANA_PASS
|
unset GEN_GRAFANA_PASS
|
||||||
fi
|
fi
|
||||||
|
if ! infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/services/authentik" --format=dotenv-export --silent 2>/dev/null | grep -q 'GRAFANA_OAUTH_CLIENT_SECRET'; then
|
||||||
|
infisical secrets-manager folders create authentik --path /services --env prod --projectId "${INFISICAL_PROJECT_ID}" --domain "${INFISICAL_DOMAIN}" --token "${TOKEN}" --silent 2>/dev/null || true
|
||||||
|
GEN_OAUTH_SECRET=$(openssl rand -base64 48 | tr -dc 'a-zA-Z0-9' | head -c 48)
|
||||||
|
infisical secrets set --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/services/authentik" \
|
||||||
|
"GRAFANA_OAUTH_CLIENT_SECRET=${GEN_OAUTH_SECRET}" \
|
||||||
|
--silent
|
||||||
|
unset GEN_OAUTH_SECRET
|
||||||
|
fi
|
||||||
eval "$(infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/services/monitoring" --format=dotenv-export --silent)"
|
eval "$(infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/services/monitoring" --format=dotenv-export --silent)"
|
||||||
|
eval "$(infisical export --domain="${INFISICAL_DOMAIN}" --token="${TOKEN}" --env=prod --projectId="${INFISICAL_PROJECT_ID}" --path="/services/authentik" --format=dotenv-export --silent)"
|
||||||
export GRAFANA_ADMIN_USER="${GRAFANA_ADMIN_USER:-admin}"
|
export GRAFANA_ADMIN_USER="${GRAFANA_ADMIN_USER:-admin}"
|
||||||
export GRAFANA_ADMIN_PASSWORD="${GRAFANA_ADMIN_PASSWORD:-}"
|
export GRAFANA_ADMIN_PASSWORD="${GRAFANA_ADMIN_PASSWORD:-}"
|
||||||
|
export GRAFANA_OAUTH_CLIENT_SECRET="${GRAFANA_OAUTH_CLIENT_SECRET:-}"
|
||||||
|
extra+=(-e "grafana_oauth_client_secret=${GRAFANA_OAUTH_CLIENT_SECRET:-}")
|
||||||
;;
|
;;
|
||||||
rus-central)
|
rus-central)
|
||||||
input_email="${INPUT_LETSENCRYPT_EMAIL:-}"
|
input_email="${INPUT_LETSENCRYPT_EMAIL:-}"
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ prometheus_retention: "30d"
|
|||||||
grafana_admin_user: "{{ lookup('ansible.builtin.env', 'GRAFANA_ADMIN_USER', default='admin') }}"
|
grafana_admin_user: "{{ lookup('ansible.builtin.env', 'GRAFANA_ADMIN_USER', default='admin') }}"
|
||||||
grafana_admin_password: "{{ lookup('ansible.builtin.env', 'GRAFANA_ADMIN_PASSWORD', default='') }}"
|
grafana_admin_password: "{{ lookup('ansible.builtin.env', 'GRAFANA_ADMIN_PASSWORD', default='') }}"
|
||||||
grafana_root_url: "https://graf.gunihome.ru"
|
grafana_root_url: "https://graf.gunihome.ru"
|
||||||
|
grafana_oauth_client_secret: "{{ lookup('ansible.builtin.env', 'GRAFANA_OAUTH_CLIENT_SECRET', default='') }}"
|
||||||
|
|
||||||
ntfy_base_url: "https://ntfy.gunihome.ru"
|
ntfy_base_url: "https://ntfy.gunihome.ru"
|
||||||
ntfy_default_topic: "homelab-alerts"
|
ntfy_default_topic: "homelab-alerts"
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
---
|
---
|
||||||
|
- name: Проверить наличие секрета Grafana OAuth
|
||||||
|
ansible.builtin.assert:
|
||||||
|
that:
|
||||||
|
- grafana_oauth_client_secret is defined and grafana_oauth_client_secret | length > 0
|
||||||
|
fail_msg: "Секрет GRAFANA_OAUTH_CLIENT_SECRET не передан!"
|
||||||
|
|
||||||
- name: Создать базовые каталоги мониторинга
|
- name: Создать базовые каталоги мониторинга
|
||||||
ansible.builtin.file:
|
ansible.builtin.file:
|
||||||
path: "{{ item.path }}"
|
path: "{{ item.path }}"
|
||||||
|
|||||||
@@ -57,6 +57,17 @@ services:
|
|||||||
- GF_SECURITY_ADMIN_PASSWORD={{ grafana_admin_password }}
|
- GF_SECURITY_ADMIN_PASSWORD={{ grafana_admin_password }}
|
||||||
- GF_USERS_ALLOW_SIGN_UP=false
|
- GF_USERS_ALLOW_SIGN_UP=false
|
||||||
- GF_SERVER_ROOT_URL={{ grafana_root_url }}
|
- GF_SERVER_ROOT_URL={{ grafana_root_url }}
|
||||||
|
- GF_AUTH_GENERIC_OAUTH_ENABLED=true
|
||||||
|
- GF_AUTH_GENERIC_OAUTH_NAME=Authentik
|
||||||
|
- GF_AUTH_GENERIC_OAUTH_CLIENT_ID=grafana
|
||||||
|
- GF_AUTH_GENERIC_OAUTH_CLIENT_SECRET={{ grafana_oauth_client_secret }}
|
||||||
|
- GF_AUTH_GENERIC_OAUTH_SCOPES=openid email profile
|
||||||
|
- GF_AUTH_GENERIC_OAUTH_AUTH_URL=https://auth.gunihome.ru/application/o/authorize/
|
||||||
|
- GF_AUTH_GENERIC_OAUTH_TOKEN_URL=https://auth.gunihome.ru/application/o/token/
|
||||||
|
- GF_AUTH_GENERIC_OAUTH_API_URL=https://auth.gunihome.ru/application/o/userinfo/
|
||||||
|
- GF_AUTH_GENERIC_OAUTH_ALLOW_SIGN_UP=true
|
||||||
|
- "GF_AUTH_GENERIC_OAUTH_ROLE_ATTRIBUTE_PATH=contains(groups[*], 'admins') && 'Admin' || 'Viewer'"
|
||||||
|
- GF_AUTH_GENERIC_OAUTH_ALLOW_ASSIGN_GRAFANA_ADMIN=true
|
||||||
volumes:
|
volumes:
|
||||||
- ./grafana_data:/var/lib/grafana
|
- ./grafana_data:/var/lib/grafana
|
||||||
- ./grafana/provisioning:/etc/grafana/provisioning:ro
|
- ./grafana/provisioning:/etc/grafana/provisioning:ro
|
||||||
|
|||||||
@@ -4,4 +4,5 @@ authentik_dir: "/opt/authentik"
|
|||||||
authentik_http_port: 9000
|
authentik_http_port: 9000
|
||||||
authentik_secret_key: "{{ lookup('env', 'AUTHENTIK_SECRET_KEY') }}"
|
authentik_secret_key: "{{ lookup('env', 'AUTHENTIK_SECRET_KEY') }}"
|
||||||
authentik_postgres_password: "{{ lookup('env', 'AUTHENTIK_POSTGRES_PASSWORD') }}"
|
authentik_postgres_password: "{{ lookup('env', 'AUTHENTIK_POSTGRES_PASSWORD') }}"
|
||||||
|
grafana_oauth_client_secret: "{{ lookup('env', 'GRAFANA_OAUTH_CLIENT_SECRET') }}"
|
||||||
|
|
||||||
@@ -3,13 +3,18 @@ version: 1
|
|||||||
metadata:
|
metadata:
|
||||||
name: traefik-dashboard
|
name: traefik-dashboard
|
||||||
labels:
|
labels:
|
||||||
blueprints.goauthentik.io/description: "Панель Traefik только для группы admins"
|
blueprints.goauthentik.io/description: "Панель Traefik и Ntfy Forward-auth"
|
||||||
entries:
|
entries:
|
||||||
- model: authentik_core.group
|
- model: authentik_core.group
|
||||||
id: group-admins
|
id: group-admins
|
||||||
identifiers:
|
identifiers:
|
||||||
name: admins
|
name: admins
|
||||||
|
|
||||||
|
- model: authentik_core.group
|
||||||
|
id: group-family
|
||||||
|
identifiers:
|
||||||
|
name: family
|
||||||
|
|
||||||
- model: authentik_providers_proxy.proxyprovider
|
- model: authentik_providers_proxy.proxyprovider
|
||||||
id: provider-traefik-dashboard
|
id: provider-traefik-dashboard
|
||||||
identifiers:
|
identifiers:
|
||||||
@@ -37,6 +42,41 @@ entries:
|
|||||||
attrs:
|
attrs:
|
||||||
group: !KeyOf group-admins
|
group: !KeyOf group-admins
|
||||||
|
|
||||||
|
- model: authentik_providers_proxy.proxyprovider
|
||||||
|
id: provider-ntfy
|
||||||
|
identifiers:
|
||||||
|
name: ntfy
|
||||||
|
attrs:
|
||||||
|
mode: forward_single
|
||||||
|
external_host: https://ntfy.gunihome.ru
|
||||||
|
intercept_header_auth: true
|
||||||
|
authorization_flow: !Find [authentik_flows.flow, [slug, default-provider-authorization-implicit-consent]]
|
||||||
|
invalidation_flow: !Find [authentik_flows.flow, [slug, default-provider-invalidation-flow]]
|
||||||
|
|
||||||
|
- model: authentik_core.application
|
||||||
|
id: app-ntfy
|
||||||
|
identifiers:
|
||||||
|
slug: ntfy
|
||||||
|
attrs:
|
||||||
|
name: Ntfy
|
||||||
|
meta_launch_url: https://ntfy.gunihome.ru
|
||||||
|
policy_engine_mode: any
|
||||||
|
provider: !KeyOf provider-ntfy
|
||||||
|
|
||||||
|
- model: authentik_policies.policybinding
|
||||||
|
identifiers:
|
||||||
|
order: 0
|
||||||
|
target: !KeyOf app-ntfy
|
||||||
|
attrs:
|
||||||
|
group: !KeyOf group-admins
|
||||||
|
|
||||||
|
- model: authentik_policies.policybinding
|
||||||
|
identifiers:
|
||||||
|
order: 1
|
||||||
|
target: !KeyOf app-ntfy
|
||||||
|
attrs:
|
||||||
|
group: !KeyOf group-family
|
||||||
|
|
||||||
# providers ниже — полный список embedded outpost.
|
# providers ниже — полный список embedded outpost.
|
||||||
# Новый proxy-провайдер добавляется в этот файл, а не только в интерфейсе.
|
# Новый proxy-провайдер добавляется в этот файл, а не только в интерфейсе.
|
||||||
- model: authentik_outposts.outpost
|
- model: authentik_outposts.outpost
|
||||||
@@ -49,4 +89,4 @@ entries:
|
|||||||
authentik_host: https://auth.gunihome.ru
|
authentik_host: https://auth.gunihome.ru
|
||||||
providers:
|
providers:
|
||||||
- !KeyOf provider-traefik-dashboard
|
- !KeyOf provider-traefik-dashboard
|
||||||
|
- !KeyOf provider-ntfy
|
||||||
@@ -19,7 +19,8 @@
|
|||||||
that:
|
that:
|
||||||
- authentik_secret_key is defined and authentik_secret_key | length > 0
|
- authentik_secret_key is defined and authentik_secret_key | length > 0
|
||||||
- authentik_postgres_password is defined and authentik_postgres_password | length > 0
|
- authentik_postgres_password is defined and authentik_postgres_password | length > 0
|
||||||
fail_msg: "Один или оба секрета Authentik (AUTHENTIK_SECRET_KEY, AUTHENTIK_POSTGRES_PASSWORD) не переданы через переменные окружения!"
|
- grafana_oauth_client_secret is defined and grafana_oauth_client_secret | length > 0
|
||||||
|
fail_msg: "Один или несколько секретов Authentik (AUTHENTIK_SECRET_KEY, AUTHENTIK_POSTGRES_PASSWORD, GRAFANA_OAUTH_CLIENT_SECRET) не переданы!"
|
||||||
|
|
||||||
- name: Установить compose.yaml для Authentik
|
- name: Установить compose.yaml для Authentik
|
||||||
ansible.builtin.template:
|
ansible.builtin.template:
|
||||||
@@ -30,7 +31,7 @@
|
|||||||
mode: "0600"
|
mode: "0600"
|
||||||
no_log: true
|
no_log: true
|
||||||
|
|
||||||
- name: Синхронизировать blueprints Authentik
|
- name: Синхронизировать статические blueprints Authentik
|
||||||
ansible.builtin.copy:
|
ansible.builtin.copy:
|
||||||
src: blueprints/
|
src: blueprints/
|
||||||
dest: "{{ authentik_dir }}/blueprints/"
|
dest: "{{ authentik_dir }}/blueprints/"
|
||||||
@@ -39,6 +40,16 @@
|
|||||||
mode: "0644"
|
mode: "0644"
|
||||||
register: authentik_blueprint
|
register: authentik_blueprint
|
||||||
|
|
||||||
|
- name: Установить шаблонные blueprints Authentik
|
||||||
|
ansible.builtin.template:
|
||||||
|
src: blueprints/grafana.yaml.j2
|
||||||
|
dest: "{{ authentik_dir }}/blueprints/grafana.yaml"
|
||||||
|
owner: root
|
||||||
|
group: root
|
||||||
|
mode: "0644"
|
||||||
|
register: authentik_blueprint_grafana
|
||||||
|
no_log: true
|
||||||
|
|
||||||
- name: Запустить сервисы Authentik через Docker Compose
|
- name: Запустить сервисы Authentik через Docker Compose
|
||||||
ansible.builtin.command: docker compose -f {{ authentik_dir }}/compose.yaml up -d --remove-orphans
|
ansible.builtin.command: docker compose -f {{ authentik_dir }}/compose.yaml up -d --remove-orphans
|
||||||
register: compose_up
|
register: compose_up
|
||||||
@@ -46,7 +57,15 @@
|
|||||||
|
|
||||||
- name: Перезапустить воркер Authentik при обновлении blueprints
|
- name: Перезапустить воркер Authentik при обновлении blueprints
|
||||||
ansible.builtin.command: docker compose -f {{ authentik_dir }}/compose.yaml restart authentik-worker
|
ansible.builtin.command: docker compose -f {{ authentik_dir }}/compose.yaml restart authentik-worker
|
||||||
when: authentik_blueprint.changed and not compose_up.changed
|
when: (authentik_blueprint.changed or authentik_blueprint_grafana.changed) and not compose_up.changed
|
||||||
|
|
||||||
|
- name: Применить blueprints Authentik в authentik-server
|
||||||
|
ansible.builtin.command: >
|
||||||
|
docker compose -f {{ authentik_dir }}/compose.yaml exec -T authentik-server
|
||||||
|
ak apply_blueprint /blueprints/custom/traefik-dashboard.yaml /blueprints/custom/grafana.yaml
|
||||||
|
when: authentik_blueprint.changed or authentik_blueprint_grafana.changed or compose_up.changed
|
||||||
|
register: apply_blueprints_cmd
|
||||||
|
changed_when: true
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,59 @@
|
|||||||
|
# yaml-language-server: $schema=https://goauthentik.io/blueprints/schema.json
|
||||||
|
version: 1
|
||||||
|
metadata:
|
||||||
|
name: grafana-sso
|
||||||
|
labels:
|
||||||
|
blueprints.goauthentik.io/description: "Grafana OAuth2 Provider"
|
||||||
|
entries:
|
||||||
|
- model: authentik_core.group
|
||||||
|
id: group-admins
|
||||||
|
identifiers:
|
||||||
|
name: admins
|
||||||
|
|
||||||
|
- model: authentik_core.group
|
||||||
|
id: group-family
|
||||||
|
identifiers:
|
||||||
|
name: family
|
||||||
|
|
||||||
|
- model: authentik_providers_oauth2.oauth2provider
|
||||||
|
id: provider-grafana
|
||||||
|
identifiers:
|
||||||
|
name: grafana
|
||||||
|
attrs:
|
||||||
|
client_type: confidential
|
||||||
|
client_id: grafana
|
||||||
|
client_secret: {{ grafana_oauth_client_secret | to_json }}
|
||||||
|
redirect_uris:
|
||||||
|
- matching_mode: strict
|
||||||
|
url: https://graf.gunihome.ru/login/generic_oauth
|
||||||
|
authorization_flow: !Find [authentik_flows.flow, [slug, default-provider-authorization-implicit-consent]]
|
||||||
|
invalidation_flow: !Find [authentik_flows.flow, [slug, default-provider-invalidation-flow]]
|
||||||
|
signing_key: !Find [authentik_crypto.certificatekeypair, [name, "authentik Self-signed Certificate"]]
|
||||||
|
property_mappings:
|
||||||
|
- !Find [authentik_providers_oauth2.scopemapping, [scope_name, openid]]
|
||||||
|
- !Find [authentik_providers_oauth2.scopemapping, [scope_name, email]]
|
||||||
|
- !Find [authentik_providers_oauth2.scopemapping, [scope_name, profile]]
|
||||||
|
|
||||||
|
- model: authentik_core.application
|
||||||
|
id: app-grafana
|
||||||
|
identifiers:
|
||||||
|
slug: grafana
|
||||||
|
attrs:
|
||||||
|
name: Grafana
|
||||||
|
meta_launch_url: https://graf.gunihome.ru
|
||||||
|
policy_engine_mode: any
|
||||||
|
provider: !KeyOf provider-grafana
|
||||||
|
|
||||||
|
- model: authentik_policies.policybinding
|
||||||
|
identifiers:
|
||||||
|
order: 0
|
||||||
|
target: !KeyOf app-grafana
|
||||||
|
attrs:
|
||||||
|
group: !KeyOf group-admins
|
||||||
|
|
||||||
|
- model: authentik_policies.policybinding
|
||||||
|
identifiers:
|
||||||
|
order: 1
|
||||||
|
target: !KeyOf app-grafana
|
||||||
|
attrs:
|
||||||
|
group: !KeyOf group-family
|
||||||
@@ -5,6 +5,17 @@ http:
|
|||||||
entryPoints:
|
entryPoints:
|
||||||
- websecure
|
- websecure
|
||||||
service: ntfy
|
service: ntfy
|
||||||
|
middlewares:
|
||||||
|
- authentik@file
|
||||||
|
tls:
|
||||||
|
certResolver: letsencrypt
|
||||||
|
|
||||||
|
ntfy-outpost:
|
||||||
|
rule: "Host(`ntfy.gunihome.ru`) && PathPrefix(`/outpost.goauthentik.io/`)"
|
||||||
|
entryPoints:
|
||||||
|
- websecure
|
||||||
|
service: authentik@file
|
||||||
|
priority: 100
|
||||||
tls:
|
tls:
|
||||||
certResolver: letsencrypt
|
certResolver: letsencrypt
|
||||||
|
|
||||||
@@ -13,4 +24,3 @@ http:
|
|||||||
loadBalancer:
|
loadBalancer:
|
||||||
servers:
|
servers:
|
||||||
- url: "http://192.168.1.108:80"
|
- url: "http://192.168.1.108:80"
|
||||||
|
|
||||||
Reference in new issue
Block a user