Configuration HTTPS
Ce guide explique comment configurer HTTPS pour sécuriser PCH-SIG en production.
Pourquoi HTTPS ?
- Chiffrement : Les données sont chiffrées en transit
- Authentification : Vérifie l'identité du serveur
- Intégrité : Protège contre les modifications
- Conformité : Requis pour les données sensibles
Architecture
Avec reverse proxy
┌─────────────────┐ ┌─────────────────┐ ┌─────────────────┐
│ Client │────▶│ Nginx HTTPS │────▶│ Application │
│ (Browser) │ │ (Terminaison) │ │ (HTTP local) │
│ │ │ :443 │ │ :3000, :8000 │
└─────────────────┘ └─────────────────┘ └─────────────────┘
Le reverse proxy Nginx gère le HTTPS et transmet les requêtes en HTTP aux conteneurs internes.
Obtenir un certificat
Certificat Let's Encrypt (recommandé)
# Installer Certbot
apt-get install certbot
# Générer le certificat
certbot certonly --standalone -d pch-sig.example.com
# Les certificats sont dans :
# /etc/letsencrypt/live/pch-sig.example.com/fullchain.pem
# /etc/letsencrypt/live/pch-sig.example.com/privkey.pem
Certificat auto-signé (développement)
# Créer le répertoire
mkdir -p deploy/certs
# Générer le certificat
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout deploy/certs/server.key \
-out deploy/certs/server.crt \
-subj "/CN=localhost"
Certificat d'entreprise
Contactez votre équipe sécurité pour obtenir un certificat signé par une autorité interne.
Configuration Nginx
Fichier de configuration HTTPS
Fichier : deploy/nginx-conf/https.conf
# Redirection HTTP vers HTTPS
server {
listen 80;
server_name pch-sig.example.com;
return 301 https://$server_name$request_uri;
}
# Configuration HTTPS
server {
listen 443 ssl http2;
server_name pch-sig.example.com;
# Certificats
ssl_certificate /etc/nginx/certs/fullchain.pem;
ssl_certificate_key /etc/nginx/certs/privkey.pem;
# Configuration SSL moderne
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers off;
# HSTS
add_header Strict-Transport-Security "max-age=63072000" always;
# OCSP Stapling
ssl_stapling on;
ssl_stapling_verify on;
# Session SSL
ssl_session_timeout 1d;
ssl_session_cache shared:SSL:50m;
ssl_session_tickets off;
# Racine du site
root /usr/share/nginx/html;
index index.html;
# Compression
gzip on;
gzip_types text/plain text/css application/json application/javascript;
# Frontend SPA
location / {
try_files $uri $uri/ /index.html;
}
# Proxy API
location /api {
proxy_pass http://pch_nginx_backend:80;
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 https;
}
# Headers de sécurité
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
}
Docker Compose
Configuration avec HTTPS
# docker-compose.https.yml
version: '3.8'
services:
frontend:
image: nginx:alpine
ports:
- "80:80"
- "443:443"
volumes:
- ./frontend/build:/usr/share/nginx/html:ro
- ./nginx-conf/https.conf:/etc/nginx/conf.d/default.conf:ro
- ./certs:/etc/nginx/certs:ro
depends_on:
- backend
Démarrer avec HTTPS
docker compose -f docker-compose.yml -f docker-compose.https.yml up -d
Renouvellement automatique
Script de renouvellement
#!/bin/bash
# renew-certs.sh
# Renouveler
certbot renew --quiet
# Copier les certificats
cp /etc/letsencrypt/live/pch-sig.example.com/fullchain.pem /path/to/deploy/certs/
cp /etc/letsencrypt/live/pch-sig.example.com/privkey.pem /path/to/deploy/certs/
# Recharger Nginx
docker exec pch_frontend nginx -s reload
Cron job
# Ajouter au crontab
0 0 1 * * /path/to/renew-certs.sh
Configuration backend
Trusted proxies
Fichier : backend/config/packages/framework.yaml
framework:
trusted_proxies: '%env(TRUSTED_PROXIES)%'
trusted_headers: ['x-forwarded-for', 'x-forwarded-host', 'x-forwarded-proto']
Variable d'environnement
# .env
TRUSTED_PROXIES=127.0.0.1,REMOTE_ADDR,172.0.0.0/8
Test de la configuration
Vérifier le certificat
# Avec openssl
openssl s_client -connect pch-sig.example.com:443 -servername pch-sig.example.com
# Avec curl
curl -v https://pch-sig.example.com/
Test SSL Labs
Utilisez SSL Labs Server Test pour vérifier la configuration.
Vérifications locales
# Vérifier les ports
netstat -tlnp | grep -E "(80|443)"
# Tester la redirection
curl -I http://pch-sig.example.com
# Doit retourner 301 vers HTTPS
Content Security Policy
Configuration CSP
add_header Content-Security-Policy "
default-src 'self';
script-src 'self' 'unsafe-inline';
style-src 'self' 'unsafe-inline';
img-src 'self' data: https:;
font-src 'self';
connect-src 'self' https://api.example.com;
frame-ancestors 'none';
" always;
Dépannage
Erreur de certificat
# Vérifier le certificat
openssl x509 -in /path/to/cert.pem -text -noout
# Vérifier la chaîne
openssl verify -CAfile /path/to/ca.pem /path/to/cert.pem
Mixed content
Assurez-vous que toutes les ressources sont chargées en HTTPS :
# Forcer HTTPS pour tous les contenus
add_header Content-Security-Policy "upgrade-insecure-requests" always;
Erreur de proxy
# Vérifier les headers
curl -I https://pch-sig.example.com/api/health
# Les headers doivent inclure :
# X-Forwarded-Proto: https
Environnement Windows Server
Configuration PowerShell
# Importer un certificat PFX
$cert = Import-PfxCertificate -FilePath "C:\pch-sig\certs\server.pfx" `
-CertStoreLocation "Cert:\LocalMachine\My" `
-Password (ConvertTo-SecureString -String "password" -AsPlainText -Force)
# Lier au port 443
netsh http add sslcert ipport=0.0.0.0:443 certhash=$cert.Thumbprint appid='{00000000-0000-0000-0000-000000000000}'
Proxy HTTPS vers Docker
# Redirection HTTPS locale vers Docker
netsh interface portproxy add v4tov4 listenport=443 listenaddress=0.0.0.0 connectport=443 connectaddress=192.168.99.100
Checklist production
- Certificat valide et signé par une CA reconnue
- Renouvellement automatique configuré
- HSTS activé
- TLS 1.2+ uniquement
- Ciphers sécurisés
- OCSP Stapling activé
- Headers de sécurité configurés
- Redirection HTTP vers HTTPS
- Test SSL Labs grade A ou A+