====== Runbook: Configurare TLS ======
**Durata:** ~15 minuti \\
**Ruolo:** Security-Admin \\
**Prerequisito:** Certificato (PFX o PEM+KEY)
Attivare HTTPS per il Data Gateway.
----
===== Workflow =====
flowchart TD
A[Start] --> B{Certificato disponibile?}
B -->|No| C[Ottenere certificato]
B -->|Si| D[Modificare appsettings.json]
C --> D
D --> E[Riavviare Gateway]
E --> F[Testare HTTPS]
F --> G{Riuscito?}
G -->|Si| H[Disattivare HTTP]
G -->|No| I[Controllare log]
H --> J[Finito]
style J fill:#e8f5e9
style I fill:#ffebee
----
===== 1. Ottenere certificato =====
**Opzione A: Let's Encrypt (gratuito)**
# Installare Certbot
sudo apt install certbot
# Richiedere certificato
sudo certbot certonly --standalone -d gateway.example.com
# Risultato:
# /etc/letsencrypt/live/gateway.example.com/fullchain.pem
# /etc/letsencrypt/live/gateway.example.com/privkey.pem
**Opzione B: Autofirmato (solo Test!)**
# Creare certificato autofirmato
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes \
-subj "/CN=gateway.example.com"
# Convertire in PFX
openssl pkcs12 -export -out gateway.pfx -inkey key.pem -in cert.pem -passout pass:changeit
**Opzione C: CA Interna**
-> Vedere [[it:int:pqcrypt:szenarien:operator:tagesgeschaeft:zertifikat-ausstellen|PQ Crypto: Emettere certificato]]
----
===== 2. Posizionare certificato =====
# Windows
mkdir %GATEWAY_ROOT%\certs
copy gateway.pfx %GATEWAY_ROOT%\certs\
# Linux
sudo mkdir -p /opt/data-gateway/certs
sudo cp cert.pem key.pem /opt/data-gateway/certs/
sudo chmod 600 /opt/data-gateway/certs/*
sudo chown datagateway:datagateway /opt/data-gateway/certs/*
----
===== 3. Configurare appsettings.json =====
**Con file PFX:**
{
"Kestrel": {
"Endpoints": {
"Https": {
"Url": "https://0.0.0.0:443",
"Certificate": {
"Path": "certs/gateway.pfx",
"Password": "changeit"
}
}
}
}
}
**Con file PEM:**
{
"Kestrel": {
"Endpoints": {
"Https": {
"Url": "https://0.0.0.0:443",
"Certificate": {
"Path": "certs/cert.pem",
"KeyPath": "certs/key.pem"
}
}
}
}
}
**Forzare versione TLS:**
{
"Kestrel": {
"Endpoints": {
"Https": {
"Url": "https://0.0.0.0:443",
"Certificate": {
"Path": "certs/gateway.pfx",
"Password": "changeit"
},
"SslProtocols": ["Tls12", "Tls13"]
}
}
}
}
----
===== 4. Riavviare Gateway =====
# Windows
Restart-Service -Name "DataGateway"
# Linux
sudo systemctl restart data-gateway
# Docker
docker restart gateway
----
===== 5. Testare HTTPS =====
# Test semplice
curl -k https://localhost/health
# Con verifica certificato
curl https://gateway.example.com/health
# Mostrare dettagli TLS
curl -v https://gateway.example.com/health 2>&1 | grep -E "SSL|TLS|subject|expire"
# Test OpenSSL
openssl s_client -connect gateway.example.com:443 -servername gateway.example.com
----
===== 6. Disattivare HTTP (opzionale) =====
Permettere solo HTTPS:
{
"Kestrel": {
"Endpoints": {
"Https": {
"Url": "https://0.0.0.0:443",
"Certificate": {
"Path": "certs/gateway.pfx",
"Password": "changeit"
}
}
}
}
}
Oppure Redirect HTTP->HTTPS:
// Program.cs
app.UseHttpsRedirection();
----
===== 7. Checklist =====
| # | Punto di verifica | v |
|---|-----------|---|
| 1 | Certificato valido (non scaduto) | ☐ |
| 2 | Certificato per hostname corretto | ☐ |
| 3 | Private Key protetta (chmod 600) | ☐ |
| 4 | HTTPS raggiungibile | ☐ |
| 5 | TLS 1.2+ attivo | ☐ |
| 6 | HTTP disattivato o Redirect | ☐ |
| 7 | Firewall porta 443 aperta | ☐ |
----
===== Troubleshooting =====
| Problema | Causa | Soluzione |
|---------|---------|--------|
| ''Unable to configure HTTPS'' | Percorso errato | Verificare percorso certificato |
| ''Password incorrect'' | Password PFX errata | Verificare password |
| ''Certificate expired'' | Certificato scaduto | Nuovo certificato |
| ''SSL_ERROR_RX_RECORD_TOO_LONG'' | HTTP invece di HTTPS | Verificare porta/protocollo |
| ''NET::ERR_CERT_COMMON_NAME_INVALID'' | CN/SAN errato | Certificato con nome corretto |
----
===== Test SSL Online =====
Per server raggiungibili pubblicamente:
* **SSL Labs:** [[https://www.ssllabs.com/ssltest/|ssllabs.com/ssltest]]
* **Qualys:** Puntare al grado A+
----
===== Runbook Correlati =====
* [[.:zertifikat-erneuern|Rinnovare certificato]] - Processo di renewal
* [[.:firewall-regeln|Regole Firewall]] - Aprire porta 443
* [[..:monitoring:alerting|Alerting]] - Monitoraggio certificati
----
<< [[.:start|<- Sicurezza]] | [[.:zertifikat-erneuern|-> Rinnovare certificato]] >>
----
//Wolfgang van der Stille @ EMSR DATA d.o.o. - Data Gateway Professional//
{{tag>operator runbook tls https certificato ssl}}