From 7b77815a8a20e215242d4ceb63c4d17f844b2961 Mon Sep 17 00:00:00 2001 From: Tom David--Broglio Date: Fri, 5 Jan 2024 12:43:44 +0100 Subject: [PATCH] =?UTF-8?q?unit=C3=A9=20systemd=20et=20amelioration=20gene?= =?UTF-8?q?rale=20de=20la=20doc?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HowtoKeycloak.md | 90 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 78 insertions(+), 12 deletions(-) diff --git a/HowtoKeycloak.md b/HowtoKeycloak.md index ebe9cba5..9268224a 100644 --- a/HowtoKeycloak.md +++ b/HowtoKeycloak.md @@ -16,12 +16,12 @@ Installer Keycloak sur son hote avec OpenJDK (openjdk-17 pour Keycloak 23) # apt install openjdk-17-jre ``` -Lister les releases +Lister les releases pour en choisir une ```{.bash} $ git ls-remote --tags https://github.com/keycloak/keycloak ... - 99774b3f7a776476e7f04e472e13e3915971a6fb refs/tags/21.1.2 + 99774b3f7a776476e7f04e472e13e3915971a6fb refs/tags/23.x.x ``` Récupérer et extraire le zip de la release souhaitée @@ -51,11 +51,44 @@ Se connecter à http://localhost:8080/ et créer un username et password admin Se connecter à http://localhost:8080/admin avec les identifiant admin -Pour Lancer en production, il va falloir plus de configuration... voir [configuration](#configuration) +Pour Lancer en production, il va falloir configurer d'autres elements, voirs [configuration](#configuration) + +### Unitée Systemd + +On peut wrapper keycloak dans une unitée systemd, adaptez `ExecStart` + +```{.ini} +# vim /etc/systemd/system/keycloak.service +[Unit] +Description=Keycloak server +After=network-online.target +Wants=network-online.target systemd-networkd-wait-online.service + +[Service] +ExecStart=/root/keycloak-23.0.3/bin/kc.sh start + +# Disable timeout logic and wait until process is stopped +TimeoutStopSec=0 + +# SIGTERM signal is used to stop the Java process +KillSignal=SIGTERM + +# Send the signal only to the JVM rather than its control group +KillMode=process + +# Java process is never killed +SendSIGKILL=no + +# When a JVM receives a SIGTERM signal it exits with code 143 +SuccessExitStatus=143 + +[Install] +WantedBy=multi-user.target +``` ## Configuration pour de la production -Configuration d'une instance/server en prodution... +Configuration d'une instance/server de prodution... On peut spécifier de la configuration via des envs, arguments, fichier de configuration et KeyStore java. Celle-ci sera prise en comte dans cette ordre precedence (des env pourrons surcharger la conf en dur par exemple) @@ -65,7 +98,9 @@ Ici pour simplifier, on configurera via l'instance via son fichier de configurat >*Remarque* : la configuration par envs et arguments est persisté par Quarkus -La documentation complète de la configuration d'une instance en production : +* La documentation complète de la configuration d'une instance en production : + +* Liste exhaustive des options de configuration : ### Base de données @@ -73,13 +108,15 @@ Keycloak en production a besoin d'un accès à une base de donnée lien : [documentation keycloak configuration bdd](https://www.keycloak.org/server/db) -Il faut créer une base de donnée (par défaut le schéma `keycloak`) et utilisateur associé pour Keycloak +Il faut créer une base de donnée `keycloak` et utilisateur associé pour Keycloak + +> Si on utilise un autre nom de base, il faut alors specifier `db-schema` dans la configuration * [HowtoPostgreSQL](/HowtoPostgreSQL.md#créer-un-utilisateur-et-une-base-de-données) * [HowtoMySQL](/HowtoMySQL.md#créer-une-base-de-données-et-un-utilisateur-associé) -#### Configuration via fichier configuration `keycloak.conf` +* Configuration via fichier configuration `keycloak.conf` ```{.ini} # The database vendor. @@ -94,20 +131,30 @@ db-url-host=127.0.0.1 On peut spécifier en plus si besoin `db-url-port` pour le port ou même `db-url` pour spécifier entièrement l'URL [jdbc](/Glossaire.md#odbcjdbc) -#### Configuration via arguments au démarrage +* Configuration via arguments au démarrage ```{.bash} bin/kc.sh start --db mariadb --db-url-host mymariadb --db-username evocloak --db-password change_me ``` -#### TLS +### Hostname - -Pour s'assurer de la securité sur une instance de production, on ne doit jamais exposer celle-ci en HTTP. Nous allons configurer celle-ci en HTTPS/TLS +En production, un utilisateur doit se connecter en utilisant le hostname à préciser dans la configuration : -Pour allons avoir besoin d'un certificat et de sa clef privé... voir [HowtoSSL](/HowtoSSL.md#générer-un-certificat-auto-signé) +```{.ini} +# Hostname for the Keycloak server. +hostname=test.example.org +``` + +### SSL/TLS + + + +On ne doit jamais exposer une instance de production en HTTP. Nous allons configurer celle-ci en HTTPS/TLS + +Pour cela, nous avons besoin d'un certificat et de sa clef privé pour le hostname choisi... voir [HowtoSSL](/HowtoSSL.md#générer-un-certificat-auto-signé) ou [HowtoLetsEncrypt](/HowtoLetsEncrypt.md#génération-du-certificat) par exemple... ```{.ini} # The file path to a server certificate or certificate chain in PEM format. @@ -117,8 +164,27 @@ https-certificate-file=/root/keycloak_certificat.crt https-certificate-key-file=/root/keycloak_private.key ``` +### Exemple de configuration + +Exemple de configuration avec + +WIP + +## Configuration avancée + +### Log et monitoring + +* Par défaut les logs ne sont pas persisté dans un fichier, on peut l'activer et indiquer un fichier (par défaut dans data/log/keycloak.log dans le dossier de keycloak) +``` +log=console,file +log-level=debug +log-file=/var/log/keycloak.log +``` + ### Haute disponibilité +WIP + keycloak est conçu pour fonctionner en haute disponibilité avec [infinispan](https://infinispan.org/) (In-Memory Distributed Data Store) TODO https://www.keycloak.org/server/configuration-production -> https://www.keycloak.org/server/caching