ajout config proxy nginx

This commit is contained in:
Tom David--Broglio 2024-03-01 12:07:33 +01:00
parent 0c8dd49b30
commit a3d5aeed34

View file

@ -11,6 +11,7 @@
liens : [documentation officielle](https://www.keycloak.org/getting-started/getting-started-zip), [git de keycloak](https://github.com/keycloak/keycloak/releases)
Installer Keycloak sur son hote avec OpenJDK (openjdk-17 pour Keycloak 23)
> **Attention** on installe keycloak dans un utilisateur non root `keycloak` avec comme groupe `keycloak`
```{.bash}
# apt install openjdk-17-jre
@ -55,9 +56,10 @@ Pour Lancer en production, il va falloir configurer d'autres elements, voirs [co
### Unitée Systemd
On peut wrapper keycloak dans une unitée systemd, adaptez `ExecStart`
On peut wrapper keycloak dans une unitée systemd, adaptez `Environment=...` pour le nom et mod de passe de l'administrateur et `ExecStart` si besoin.
> **Attention** on ne crée pas une unitée utilisateur
```{.ini}
```{.bash}
# vim /etc/systemd/system/keycloak.service
[Unit]
Description=Keycloak server
@ -65,7 +67,11 @@ After=network-online.target
Wants=network-online.target systemd-networkd-wait-online.service
[Service]
ExecStart=/root/keycloak-23.0.3/bin/kc.sh start
User=keycloak
Group=keycloak
Environment="KEYCLOAK_ADMIN=evolix"
Environment="KEYCLOAK_ADMIN_PASSWORD=MOTDEPASSEADMIN"
ExecStart=/home/keycloak/keycloak-23.0.6/bin/kc.sh start
# Disable timeout logic and wait until process is stopped
TimeoutStopSec=0
@ -168,11 +174,11 @@ On ne doit jamais exposer une instance de production en HTTP.
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.
https-certificate-file=/root/keycloak_certificat.crt
# Chemin vers le certificat en format PEM
https-certificate-file=/home/keycloak/keycloak_certificat.crt
# The file path to a private key in PEM format.
https-certificate-key-file=/root/keycloak_private.key
# Chemin vers la clef privé en format PEM
https-certificate-key-file=/home/keycloak/keycloak_private.key
```
### Proxy inverse
@ -191,13 +197,79 @@ Documentation : <https://www.keycloak.org/server/reverseproxy>
The proxy forwards the HTTPS connection to Keycloak without terminating TLS. The secure connections between the server and clients are based on the keys and certificates used by the Keycloak server.
```{.ini}
proxy=reencrypt
hostname-url=https://sso.example.org
```
#### Exemple avec Nginx
On utilise Nginx avec keycloak en mode reencrypt, de cette maniere keycloak peut utiliser un certificat autosigné et Nginx fait la terminaison ssl d'un client. Cela nous permet d'utiliser letsencript :
```{.bash}
$ vim /etc/nginx/sites-available/keycloak.conf
server {
server_name sso.example.org;
listen 80;
include /etc/nginx/snippets/letsencrypt.conf;
location / {
return 301 https://$host$request_uri;
}
}
server {
server_name sso.example.org;
listen 443 ssl http2;
ssl_certificate /etc/letsencrypt/live/sso.evolix.eu/fullchain.pem ;
ssl_certificate_key /etc/letsencrypt/live/sso.evolix.eu/privkey.pem;
location / {
proxy_pass https://127.0.0.1:8443;
proxy_redirect off;
proxy_set_header Host $host;
# proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Port 443;
}
}
```
Voir [HowtoSSL](/HowtoSSL.md) et [HowtoNginx](/HowtoNginx.md). Il faut notamment que le port 80 soit accessible à tous.
### Exemple de configuration
Exemple de configuration avec
Exemple de configuration complete de `$keycloak_folder/conf/keycloak.conf`
WIP
```{.ini}
# Bdd
db=postgres
db-username=keycloak
db-password=A_CHANGER
db-url=127.0.0.1
# HTTPs
https-certificate-file=/home/keycloak/fullchain.pem
https-certificate-key-file=/home/keycloak/privatekey.key
# Proxy
proxy=reencrypt
# Port
https-port=8443
# Logs
log=console,file
log-level=info
log-file=/var/log/keycloak.log
# Observabilité et Monitoring
health-enabled=true
metrics-enabled=true
```
## Configuration avancée
@ -234,6 +306,7 @@ TODO https://www.keycloak.org/server/configuration-production -> https://www.key
## Administration
Lancer Keycloak en mode *dev*, pour tester Keycloak en http avec des valeurs par defaut ou en mode *prod*
> **Remarque** avec l'untiée systemd, utiliser des start, stop etc.
```{.bash}
$ cd $keycloak_folder
@ -287,9 +360,6 @@ TODO Connection au à OpenLDAP https://rob-ferguson.me/keycloak-flowable-and-ope
TODO **Identity providers**
## TODO Gestion via la cli
:logbook:
CLOCK: [2023-06-21 Wed 14:43:19]--[2023-06-21 Wed 15:05:04] => 00:21:45
:END:
[documentation keycloak](https://www.keycloak.org/docs/latest/server_admin/#admin-cli)