Grafana
Backendy: - data IoT senzorů (BigClown): influxdb - servery a infrastruktura:
Authentication - Authelia SSO Integration
Status: ✅ WORKING - Complete OIDC authentication with existing user preservation Last Updated: 2025-10-09
Overview
Grafana je nakonfigurována s duální autentizací poskytující nejlepší z obou světů:
- Authelia ForwardAuth: Síťově-based access control s automatickým bypass pro interní síť
- Native OIDC Integration: Přímá integrace s Authelia jako OpenID Connect identity provider
Configuration
OIDC Client (Authelia Side)
Configuration: See Authelia OAuth2/OIDC Provider documentation for complete OIDC setup details.
Grafana Client: Pre-configured in Authelia with client ID grafana and proper security settings.
Grafana OAuth Configuration
V /mnt/nfs/mifs01/kube/grafana-config/grafana.ini:
[auth]
# Critical fix for legacy user compatibility
oauth_allow_insecure_email_lookup = true
[auth.generic_oauth]
enabled = true
name = Authelia
client_id = grafana
client_secret = /0n5QzDVrZRiTLyQarffy54PG+VH2r6CfxkxWzUL+lI=
scopes = openid profile email groups
# Authelia OIDC Endpoints
auth_url = https://auth.mixi.cz/api/oidc/authorization
token_url = https://auth.mixi.cz/api/oidc/token
api_url = https://auth.mixi.cz/api/oidc/userinfo
# User Management
allowed_domains = mixi.cz
allow_sign_up = true
auto_login = false
# User Attribute Mapping (Critical!)
login_attribute_path = email # Uses email because Authelia LDAP: username_attribute: mail
groups_attribute_path = groups
name_attribute_path = name
email_attribute_path = email
# Security
use_pkce = true
Critical Configuration Elements
1. Email-Based User Matching
Key Setting: oauth_allow_insecure_email_lookup = true
- Purpose: Umožňuje Grafana najít existující uživatele podle email adresy při OIDC autentizaci
- Problem Solved: Bez tohoto nastavení Grafana selhává s "user sync failed" / "user not found" chybami
- Reference: GitHub Issue #111139
2. Login Attribute Path
Key Setting: login_attribute_path = email
- Důvod: Authelia LDAP konfigurace používá
username_attribute: mail - Result: OIDC poskytuje email jako primární identifikátor uživatele
- Important: Nesmí být
preferred_username- způsobilo by "user not found" chyby
3. Client Secret Synchronization
- Grafana: Plaintext secret
/0n5QzDVrZRiTLyQarffy54PG+VH2r6CfxkxWzUL+lI= - Authelia: Bcrypt hash
$2b$12$N8R.Trjz/Nms7TlgUXZLiuOEWoWJZQZv2DGgPeQxxGimc0odRLk.a - Requirement: Hash musí být vygenerován z exact same plaintext secret
Testing and Verification
# Watch Grafana logs for OIDC authentication
kubectl logs -n default -f $(kubectl get pods -n default -l app.kubernetes.io/name=grafana -o name) | grep -i "oauth\|oidc\|sync"
# Check Authelia logs
kubectl logs -n authelia -f -l app=authelia | grep -i "grafana\|oidc"
Troubleshooting
Common Issues and Solutions
- "User sync failed" / "user not found"
- Solution: Ensure
oauth_allow_insecure_email_lookup = truev[auth]sekci -
Restart:
kubectl rollout restart deployment/grafana -n default -
"Client authentication failed"
- Check: Client secret synchronization mezi Grafana (plaintext) a Authelia (bcrypt hash)
- Verify: Secrets jsou vygenerovány ze same plaintext value
References
- Authelia Documentation: Authelia - Complete SSO setup and configuration
- Traefik Integration: Traefik - ForwardAuth middleware configuration
- Grafana OAuth Docs: Official Documentation
- GitHub Issues: Grafana OAuth Issues
Dashboardy
IoT
Infra
How-to
Přejmenování názvů v legendě
Standardně grafana ukazuje názvy v "ukecaném" formátu, např. temperature.mean { id: climate-monitor:0 }. Pokud je chci zkrátit na samotné ID senzoru, lze to udělat:
(by perplexity.ai, see full thread):
- Edit your panel.
- Go to the "Transform" tab.
- Add the "Rename by regex" transform.
- Set the "Match" pattern to extract the sensor ID. For your case, use: temperature\.mean \{ id: ([^ }]+) \}
- Set the "Replace" string to: $1
This will change the legend from temperature.mean { id: climate-monitor:0 } to just climate-monitor:0.