Keycloak SSO
Keycloak est le fournisseur d'authentification unique (SSO) OIDC. Tous les services exposés délèguent leur authentification à Keycloak.
Architecture
| Rôle | Valeur |
|---|---|
| VM | keycloak (192.168.1.32) |
| URL | https://keycloak.mounik.ovh |
| Base de données | PostgreSQL (même VM) |
| TLS | Désactivé (terminé par Traefik) |
Realm et clients
Realm homelab
# Créer le realm
/opt/keycloak/bin/kcadm.sh create realms -s realm=homelab -s enabled=true
# Créer l'utilisateur admin
/opt/keycloak/bin/kcadm.sh create users -r homelab \
-s username=mounik -s email=mounicou@gmail.com -s enabled=true
/opt/keycloak/bin/kcadm.sh set-password -r homelab \
--username mounik --new-password <password>
Clients OIDC
Chaque service exposé a un client OIDC dans Keycloak :
| Client | Service | Redirect URI |
|---|---|---|
gitlab |
GitLab CE | https://gitlab.mounik.ovh/* |
harbor |
Harbor Registry | https://harbor.mounik.ovh/* |
grafana |
Grafana | https://grafana.mounik.ovh/* |
defectdojo |
DefectDojo | https://defectdojo.mounik.ovh/* |
argocd |
ArgoCD | https://argocd.mounik.ovh/* |
/opt/keycloak/bin/kcadm.sh create clients -r homelab \
-s clientId=gitlab -s secret=<secret> \
-s redirectUris='["https://gitlab.mounik.ovh/*"]' \
-s standardFlowEnabled=true
Les secrets des clients sont stockés dans Vault :
vault kv put homelab/keycloak-clients gitlab-secret=... harbor-secret=...
Services authentifiés via Keycloak
| Service | Type d'intégration |
|---|---|
| GitLab | OIDC — gitlab.rb configure omniauth |
| Grafana | OIDC — grafana.ini section auth.generic_oauth |
| Harbor | OIDC — harbor.yml section auth_mode |
| DefectDojo | OIDC — Social App Django (Keycloak OpenID Connect) |
| ArgoCD | OIDC — argocd-cm ConfigMap |
Vérification
# Vérifier le realm
curl https://keycloak.mounik.ovh/realms/homelab/.well-known/openid-configuration
# Tester un login (devrait rediriger vers Keycloak)
curl -I https://gitlab.mounik.ovh
Pour aller plus loin
- Phase 4.3 — Déploiement Keycloak — installation et configuration
- Sécurité — Vue d'ensemble — architecture defense in depth
- Vault — Secrets et PKI — stockage des secrets clients