passe le portail en HTTPS sur syllabuslab.fr, avec en-têtes de sécurité et CSP

Certificat Let's Encrypt obtenu et renouvelé par certbot (authentificateur
nginx), expiration surveillée par Prometheus. TLS selon Mozilla v6.0
intermediate, HSTS, CSP stricte avec nonce sur l'application et adaptée
sur la vitrine, xterm.js servi par le portail. Page de statut prévue sur
status.syllabuslab.fr, administration de Grafana et Kuma par tunnel seul.

Corrige aussi une faille XSS dans la page de classe, la page /cours en
erreur depuis l'étape 8, et NodeSource relancé à chaque déploiement.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Adam Belkacemi 2026-10-09 10:39:50 +02:00
parent aa004c0736
commit 618cd7efbe
30 changed files with 987 additions and 24 deletions

View file

@ -1,8 +1,5 @@
server {
listen 80;
listen [::]:80;
server_name _;
# Géré par Ansible (rôle portail) — ne pas modifier à la main.
{% macro bloc_portail() %}
root {{ portail_dossier_app }}/public;
index index.php;
@ -36,4 +33,95 @@ server {
access_log /var/log/nginx/portail-access.log;
error_log /var/log/nginx/portail-error.log;
{% endmacro %}
{% if portail_https_actif %}
# HTTP : tout part en HTTPS. Les noms connus gardent leur nom ; une requête
# sur l'IP ou un nom inconnu est envoyée vers le domaine principal.
server {
listen 80;
listen [::]:80;
server_name {{ portail_domaine }} {{ portail_domaines_alias | join(' ') }}{% if portail_statut_actif %} {{ portail_domaine_statut }}{% endif %};
server_tokens off;
# Dans une location (pas au niveau server) : la location exacte que
# certbot ajoute pour le défi ACME au renouvellement reste prioritaire.
location / {
return 301 https://$host$request_uri;
}
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name _;
server_tokens off;
location / {
return 301 https://{{ portail_domaine }}$request_uri;
}
}
# www → domaine principal (une seule adresse canonique).
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name {{ portail_domaines_alias | join(' ') }};
server_tokens off;
include snippets/syllabus-tls.conf;
include snippets/syllabus-entetes.conf;
return 301 https://{{ portail_domaine }}$request_uri;
}
server {
listen 443 ssl http2 default_server;
listen [::]:443 ssl http2 default_server;
server_name {{ portail_domaine }};
server_tokens off;
include snippets/syllabus-tls.conf;
include snippets/syllabus-entetes.conf;
{{ bloc_portail() }}
}
{% if portail_statut_actif %}
# Page de statut publique d'Uptime Kuma, et RIEN d'autre : l'administration
# (tableau de bord, /socket.io, /metrics…) reste accessible par tunnel SSH
# uniquement. Chemins relevés dans server/routers/status-page-router.js.
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name {{ portail_domaine_statut }};
server_tokens off;
include snippets/syllabus-tls.conf;
include snippets/syllabus-entetes.conf;
location = / {
return 302 /status/{{ portail_statut_slug }};
}
location ~ ^/(status/[a-z0-9-]+$|api/status-page/|assets/|upload/|icon\.svg$|favicon\.ico$|apple-touch-icon[a-z0-9-]*\.png$|robots\.txt$) {
limit_except GET HEAD {
deny all;
}
proxy_pass http://127.0.0.1:{{ portail_port_uptime_kuma }};
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Forwarded-Proto https;
}
location / {
return 404;
}
access_log /var/log/nginx/statut-access.log;
error_log /var/log/nginx/statut-error.log;
}
{% endif %}
{% else %}
# Avant le premier certificat : HTTP seul, avec les noms du domaine pour que
# certbot (authentificateur nginx) trouve le bon bloc.
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name {{ portail_domaine }} {{ portail_domaines_alias | join(' ') }} _;
server_tokens off;
{{ bloc_portail() }}
}
{% endif %}

View file

@ -0,0 +1,10 @@
# Géré par Ansible (rôle portail). En-têtes communs à tous les sites HTTPS.
# La Content-Security-Policy du portail est posée par Laravel
# (App\Http\Middleware\PolitiqueSecuriteContenu) : elle dépend de la page.
# Attention : un add_header dans un bloc location masque ceux du server.
add_header Strict-Transport-Security "max-age=63072000; includeSubDomains" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "DENY" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Permissions-Policy "camera=(), microphone=(), geolocation=(), payment=()" always;
add_header Cross-Origin-Opener-Policy "same-origin" always;

View file

@ -0,0 +1,14 @@
#!/bin/sh
# Géré par Ansible (rôle portail). Publie la date d'expiration du certificat
# HTTPS pour Prometheus (collecteur textfile de node_exporter) : alerte
# CertificatExpireBientot si le renouvellement automatique échoue.
set -eu
CERT=/etc/letsencrypt/live/{{ portail_domaine }}/fullchain.pem
DOSSIER=/var/lib/node_exporter/textfile
FIN=$(date -d "$(openssl x509 -enddate -noout -in "$CERT" | cut -d= -f2)" +%s)
cat > "$DOSSIER/certificat.prom.tmp" <<METRIQUE
# HELP syllabus_certificat_expiration_timestamp Date d'expiration du certificat HTTPS (secondes Unix).
# TYPE syllabus_certificat_expiration_timestamp gauge
syllabus_certificat_expiration_timestamp{domaine="{{ portail_domaine }}"} $FIN
METRIQUE
mv "$DOSSIER/certificat.prom.tmp" "$DOSSIER/certificat.prom"

View file

@ -0,0 +1,14 @@
# Géré par Ansible (rôle portail). Mozilla SSL Configuration Guidelines v6.0,
# profil « intermediate » (vieux postes et Chromebooks compris), adapté :
# - pas de X25519MLKEM768 (OpenSSL 3.5 requis, Debian 12 a la 3.0) ;
# - pas d'OCSP stapling (Let's Encrypt ne fournit plus d'OCSP depuis 2025) ;
# - suites ECDHE uniquement : aucun paramètre Diffie-Hellman à générer.
ssl_certificate /etc/letsencrypt/live/{{ portail_domaine }}/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/{{ portail_domaine }}/privkey.pem;
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ecdh_curve X25519:prime256v1:secp384r1;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305;
ssl_prefer_server_ciphers off;
ssl_session_timeout 1d;
ssl_session_cache shared:SyllabusTLS:10m;
ssl_session_tickets off;