Page:
SSO-Authentik
No results
1
SSO-Authentik
pepper edited this page 2026-06-27 03:07:50 +00:00
🔐 SSO — Authentik
Toutes les authentifications passent par Authentik (auth.molok.fr).
Mécanismes en place
| Application | Mécanisme | Remarque |
|---|---|---|
| Grafana | OIDC natif | AUTO_LOGIN=true — redirige direct |
| Forgejo | OIDC natif | ENABLE_AUTO_REGISTRATION=true |
| Jellyfin | OIDC natif | via plugin jellyfin-plugin-sso |
| qBittorrent | Forward-auth | SWAG fait le gardien |
| Nextcloud | Login natif | pas encore câblé |
Pattern A — OIDC natif
Flux « Authorization Code ». L'application gère le dialogue OAuth2 directement.
1. Navigateur → app : GET app.molok.fr/
2. app → navigateur : 302 vers auth.molok.fr/application/o/authorize/
?client_id=…&redirect_uri=…&scope=openid email profile&state=…
3. navigateur → Authentik : page de login (si pas de session)
4. login OK → session créée dans Redis
5. Authentik → navigateur : 302 vers app/callback?code=XXX
6. [BACK-CHANNEL serveur↔serveur]
app → Authentik /o/token/ (code + client_secret) → access_token + id_token
app → Authentik /o/userinfo/ → { email, name, groups[] }
7. app crée sa session (cookie) → connecté
Endpoints Authentik :
| Endpoint | URL |
|---|---|
| Authorize | https://auth.molok.fr/application/o/authorize/ |
| Token | https://auth.molok.fr/application/o/token/ |
| Userinfo | https://auth.molok.fr/application/o/userinfo/ |
| End-session | https://auth.molok.fr/application/o/<slug>/end-session/ |
Grafana — mapping de rôle
contains(groups[*], 'grafana-admins') && 'GrafanaAdmin' || 'Viewer'
Forgejo — création de compte automatique
Variable ENABLE_AUTO_REGISTRATION=true : à la première connexion SSO, Forgejo crée le compte local avec username = preferred_username d'Authentik.
Pattern B — Forward-auth (qBittorrent)
qBittorrent n'a pas de SSO natif : SWAG interroge Authentik avant de proxifier.
1. Navigateur → SWAG : GET qbittorrent.molok.fr
2. SWAG → Authentik (sous-requête) : /outpost.goauthentik.io/auth/nginx
3a. 200 → SWAG proxifie (X-authentik-email, X-authentik-groups en en-tête)
3b. 401 → SWAG 302 vers .../start?rd=<url_encodée> → login → retour
Snippets nginx concernés :
./swag/conf/nginx/authentik-server.conf — expose l'outpost sans auth
./swag/conf/nginx/authentik-location.conf — auth_request + error_page 401
Déconnexion (single logout)
Grafana :
GF_AUTH_SIGNOUT_REDIRECT_URL=https://auth.molok.fr/application/o/<slug>/end-session/
→ se déconnecter de Grafana invalide aussi la session Authentik dans Redis.
Ajouter un nouveau fournisseur OIDC
- Dans Authentik : Applications → Créer → choisir "OAuth2/OIDC provider"
- Configurer
Redirect URIs, copierClient IDetClient Secret - Dans
docker-compose.yml: ajouter les variablesCLIENT_ID,CLIENT_SECRET, URL de l'issuer - Redémarrer le service :
sudo docker compose up -d <service>
Dépannage SSO
# Logs Authentik
sudo docker compose logs -f authentik-server
# Vérifier la session Redis
sudo docker exec -it redis redis-cli -a $(cat secrets/redis_password.txt) keys '*session*' | head -20
# Tester l'endpoint userinfo manuellement
curl -s -H "Authorization: Bearer <access_token>" https://auth.molok.fr/application/o/userinfo/