Une application déclare au plan ses chemins_publics (préfixes comme /realms/chezlepro/ et /resources/) : le web frontal ne relaie qu'eux et répond 404 au reste. Keycloak publie ainsi ses realms sous auth.chezlepro.ca, jamais sa console d'administration. Sans le champ, le rendu est identique à l'ancien. Configuration vérifiée par le nginx du frontal ; le plan refuse un préfixe mal formé, une liste vide, des chemins sans exposition. Schéma du plan régénéré. Assisted-by: Claude Code Signed-off-by: Daniel Allaire <allaire.dan@chezlepro.ca>
135 lines
4.4 KiB
Django/Jinja
135 lines
4.4 KiB
Django/Jinja
{% macro relais(expo, tls) %}
|
|
{% if expo.chemins_publics | default([]) | length > 0 %}
|
|
# SEULS CES PREFIXES SONT PUBLICS (`chemins_publics`, D-127) : le reste repond 404. Keycloak
|
|
# publie ainsi ses realms, jamais sa console d'administration.
|
|
{% for chemin in expo.chemins_publics %}
|
|
location ^~ {{ chemin }} {
|
|
{{ proxy(expo, tls) }}
|
|
}
|
|
{% endfor %}
|
|
location / {
|
|
return 404;
|
|
}
|
|
{% else %}
|
|
location / {
|
|
{{ proxy(expo, tls) }}
|
|
}
|
|
{% endif %}
|
|
{% endmacro %}
|
|
{% macro proxy(expo, tls) %}
|
|
proxy_pass {{ 'https' if tls else 'http' }}://{{ hostvars[expo.hote].ansible_host }}:{{ expo.port }};
|
|
{% if tls %}
|
|
proxy_ssl_verify on;
|
|
proxy_ssl_trusted_certificate /etc/ssl/certs/ca-certificates.crt;
|
|
proxy_ssl_name {{ expo.hote }}.{{ domaine_interne }};
|
|
proxy_ssl_server_name on;
|
|
{% endif %}
|
|
proxy_set_header Host $host;
|
|
proxy_set_header X-Real-IP $remote_addr;
|
|
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
proxy_set_header X-Forwarded-Proto $scheme;
|
|
{%- endmacro %}
|
|
{% macro defi() %}
|
|
# Le defi HTTP-01 de Let's Encrypt : servi ici, jamais relaye ni redirige.
|
|
location ^~ /.well-known/acme-challenge/ {
|
|
root {{ serveur_web_frontal_acme_racine }};
|
|
default_type text/plain;
|
|
try_files $uri =404;
|
|
}
|
|
{% endmacro %}
|
|
# Gere par Set-OPS (role serveur_web_frontal). Ne pas editer a la main.
|
|
#
|
|
# LE SERVEUR PAR DEFAUT REFUSE TOUT NOM INCONNU (meme regle que l'edge) : sans lui, nginx
|
|
# confie un nom inconnu au premier vhost, et un balayage de l'adresse publique recevrait un
|
|
# service qu'il n'a pas nomme.
|
|
#
|
|
# LA PAGE 404 DU LOCATAIRE, s'il en declare une (`serveur_web_frontal_page_404`) : le nom
|
|
# inconnu recoit cette page, statut 404 — il n'obtient toujours aucun service. Sinon, 444.
|
|
server {
|
|
listen 80 default_server;
|
|
listen [::]:80 default_server;
|
|
server_name _;
|
|
{% if serveur_web_frontal_page_404 | length > 0 %}
|
|
root {{ serveur_web_frontal_racine_404 }};
|
|
error_page 404 /404.html;
|
|
location = /404.html {
|
|
internal;
|
|
add_header Content-Security-Policy "{{ serveur_web_frontal_page_404_csp | trim }}" always;
|
|
add_header X-Content-Type-Options "nosniff" always;
|
|
}
|
|
location / {
|
|
return 404;
|
|
}
|
|
{% else %}
|
|
return 444;
|
|
{% endif %}
|
|
}
|
|
{% set certifies = serveur_web_frontal_certifies | default([]) %}
|
|
{% if certifies | length > 0 %}
|
|
|
|
# LE MEME REFUS EN HTTPS : un nom inconnu n'obtient pas meme une poignee de main TLS. Aucun
|
|
# certificat n'est presente ; nginx >= 1.19.4. Pose seulement quand un nom est servi en TLS.
|
|
server {
|
|
listen 443 ssl default_server;
|
|
listen [::]:443 ssl default_server;
|
|
server_name _;
|
|
ssl_reject_handshake on;
|
|
}
|
|
{% endif %}
|
|
{% for expo in serveur_web_frontal_expositions | default([]) %}
|
|
{% if expo.hote in hostvars and hostvars[expo.hote].ansible_host is defined and expo.port %}
|
|
{% set tls = (expo.port | int) in serveur_web_frontal_ports_tls %}
|
|
{% set certifie = expo.fqdn in certifies %}
|
|
|
|
# {{ expo.fqdn }} -> {{ expo.hote }}:{{ expo.port }} ({{ expo.application }})
|
|
{% if certifie %}
|
|
# Certificat Let's Encrypt present : le clair renvoie vers HTTPS, sauf le defi.
|
|
server {
|
|
listen 80;
|
|
listen [::]:80;
|
|
server_name {{ expo.fqdn }};
|
|
{{ defi() }}
|
|
location / {
|
|
return 301 https://$host$request_uri;
|
|
}
|
|
}
|
|
|
|
server {
|
|
listen 443 ssl;
|
|
listen [::]:443 ssl;
|
|
http2 on;
|
|
server_name {{ expo.fqdn }};
|
|
|
|
ssl_certificate /etc/letsencrypt/live/{{ expo.fqdn }}/fullchain.pem;
|
|
ssl_certificate_key /etc/letsencrypt/live/{{ expo.fqdn }}/privkey.pem;
|
|
ssl_protocols TLSv1.2 TLSv1.3;
|
|
ssl_session_cache shared:setops_frontal:10m;
|
|
ssl_session_timeout 1d;
|
|
ssl_session_tickets off;
|
|
{% if serveur_web_frontal_hsts | length > 0 %}
|
|
add_header Strict-Transport-Security "{{ serveur_web_frontal_hsts }}" always;
|
|
{% endif %}
|
|
|
|
modsecurity on;
|
|
modsecurity_rules_file {{ serveur_web_frontal_waf_dir }}/main.conf;
|
|
{{ relais(expo, tls) }}}
|
|
{% else %}
|
|
{% if serveur_web_frontal_acme_actif | bool %}
|
|
# En clair en attendant son certificat Let's Encrypt.
|
|
{% else %}
|
|
# En clair : Let's Encrypt n'est pas active pour ce locataire.
|
|
{% endif %}
|
|
server {
|
|
listen 80;
|
|
listen [::]:80;
|
|
server_name {{ expo.fqdn }};
|
|
|
|
modsecurity on;
|
|
modsecurity_rules_file {{ serveur_web_frontal_waf_dir }}/main.conf;
|
|
{% if serveur_web_frontal_acme_actif | bool %}
|
|
{{ defi() }}
|
|
{% endif %}
|
|
{{ relais(expo, tls) }}}
|
|
{% endif %}
|
|
{% endif %}
|
|
{% endfor %}
|