From 94a143623b8c10d657926bfea96d342c81e50eb1 Mon Sep 17 00:00:00 2001 From: karpenok Date: Wed, 11 Nov 2026 17:07:00 +0700 Subject: [PATCH] fix(auth): add email fallback scope for Grafana OAuth and set attribute paths --- .../monitoring/templates/compose.yaml.j2 | 4 ++++ .../templates/blueprints/grafana.yaml.j2 | 16 +++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ansible/roles/core-mon/monitoring/templates/compose.yaml.j2 b/ansible/roles/core-mon/monitoring/templates/compose.yaml.j2 index ca1d55d..50e0b41 100644 --- a/ansible/roles/core-mon/monitoring/templates/compose.yaml.j2 +++ b/ansible/roles/core-mon/monitoring/templates/compose.yaml.j2 @@ -66,6 +66,10 @@ services: - 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_LOGIN_ATTRIBUTE_PATH=preferred_username + - GF_AUTH_GENERIC_OAUTH_NAME_ATTRIBUTE_PATH=name + - GF_AUTH_GENERIC_OAUTH_EMAIL_ATTRIBUTE_PATH=email + - GF_AUTH_GENERIC_OAUTH_USE_PKCE=true - "GF_AUTH_GENERIC_OAUTH_ROLE_ATTRIBUTE_PATH=contains(groups[*], 'admins') && 'Admin' || 'Viewer'" - GF_AUTH_GENERIC_OAUTH_ALLOW_ASSIGN_GRAFANA_ADMIN=true volumes: diff --git a/ansible/roles/core-net/authentik/templates/blueprints/grafana.yaml.j2 b/ansible/roles/core-net/authentik/templates/blueprints/grafana.yaml.j2 index a97ade7..1eb9992 100644 --- a/ansible/roles/core-net/authentik/templates/blueprints/grafana.yaml.j2 +++ b/ansible/roles/core-net/authentik/templates/blueprints/grafana.yaml.j2 @@ -15,6 +15,20 @@ entries: identifiers: name: family + - model: authentik_providers_oauth2.scopemapping + id: scope-grafana-email + identifiers: + managed: homelab/providers/oauth2/scope-grafana-email + attrs: + name: "Grafana OAuth Mapping: OpenID 'email' with fallback" + scope_name: email + description: "Email scope with fallback for users without email" + expression: | + return { + "email": request.user.email or f"{request.user.username}@gunihome.ru", + "email_verified": True + } + - model: authentik_providers_oauth2.oauth2provider id: provider-grafana identifiers: @@ -31,7 +45,7 @@ entries: 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]] + - !KeyOf scope-grafana-email - !Find [authentik_providers_oauth2.scopemapping, [scope_name, profile]] - model: authentik_core.application