====== Runbook: Rinnovare certificato ====== **Durata:** ~10 minuti \\ **Ruolo:** Security-Admin \\ **Frequenza:** Ogni 90 giorni (Let's Encrypt) o annuale Rinnovo del certificato TLS per il Data Gateway. ---- ===== Workflow ===== flowchart TD A[Avviso scadenza] --> B{Tipo certificato?} B -->|Let's Encrypt| C[certbot renew] B -->|CA Interna| D[Richiedere nuovo certificato] B -->|Commerciale| E[Rinnovare presso fornitore] C --> F[Sostituire certificato] D --> F E --> F F --> G[Riavviare Gateway] G --> H[Testare HTTPS] H --> I{OK?} I -->|Si| J[Finito] I -->|No| K[Ripristinare vecchio certificato] style J fill:#e8f5e9 style K fill:#ffebee ---- ===== 1. Verificare scadenza ===== # Verificare certificato attuale openssl s_client -connect gateway.example.com:443 -servername gateway.example.com 2>/dev/null | \ openssl x509 -noout -dates # Giorni alla scadenza echo | openssl s_client -connect gateway.example.com:443 2>/dev/null | \ openssl x509 -noout -enddate | \ cut -d= -f2 | \ xargs -I {} bash -c 'echo "Giorni alla scadenza: $(( ($(date -d "{}" +%s) - $(date +%s)) / 86400 ))"' ---- ===== 2a. Rinnovare Let's Encrypt ===== # Automatico (se certbot configurato correttamente) sudo certbot renew # Con Pre/Post-Hook per Gateway sudo certbot renew \ --pre-hook "systemctl stop data-gateway" \ --post-hook "systemctl start data-gateway" # Dry run (senza rinnovo effettivo) sudo certbot renew --dry-run **Automazione via Cron:** # /etc/cron.d/certbot-gateway 0 3 * * * root certbot renew --quiet --post-hook "systemctl reload data-gateway" ---- ===== 2b. Rinnovare CA Interna ===== # Creare CSR openssl req -new -key gateway.key -out gateway.csr \ -subj "/CN=gateway.example.com/O=Example Corp" # Inviare CSR alla CA (es. via PQ Crypto) # -> Nuovo certificato: gateway-new.crt Vedere: [[it:int:pqcrypt:szenarien:operator:tagesgeschaeft:zertifikat-erneuern|PQ Crypto: Rinnovare certificato]] ---- ===== 2c. Certificato Commerciale ===== 1. Accedere presso il fornitore (DigiCert, GlobalSign, ecc.) 2. Richiedere rinnovo 3. Caricare CSR o rigenerare 4. Effettuare validazione 5. Scaricare nuovo certificato ---- ===== 3. Backup del vecchio certificato ===== # Creare backup cp /opt/data-gateway/certs/gateway.pfx /opt/data-gateway/certs/gateway.pfx.bak.$(date +%Y%m%d) # Oppure per PEM cp /opt/data-gateway/certs/cert.pem /opt/data-gateway/certs/cert.pem.bak.$(date +%Y%m%d) ---- ===== 4. Installare nuovo certificato ===== # Formato PEM sudo cp new-cert.pem /opt/data-gateway/certs/cert.pem sudo cp new-key.pem /opt/data-gateway/certs/key.pem sudo chmod 600 /opt/data-gateway/certs/*.pem # Formato PFX sudo cp new-gateway.pfx /opt/data-gateway/certs/gateway.pfx sudo chmod 600 /opt/data-gateway/certs/gateway.pfx ---- ===== 5. Riavviare Gateway ===== # Linux sudo systemctl restart data-gateway # Windows Restart-Service -Name "DataGateway" # Docker docker restart gateway # Kubernetes (Rolling Update) kubectl rollout restart deployment/data-gateway -n data-gateway ---- ===== 6. Verificare ===== # Nuovo certificato attivo? echo | openssl s_client -connect gateway.example.com:443 2>/dev/null | \ openssl x509 -noout -subject -dates # Health Check curl https://gateway.example.com/health # Test SSL completo openssl s_client -connect gateway.example.com:443 -servername gateway.example.com ---- ===== 7. Rollback (se necessario) ===== # Ripristinare backup sudo cp /opt/data-gateway/certs/gateway.pfx.bak.20241215 /opt/data-gateway/certs/gateway.pfx # Riavviare Gateway sudo systemctl restart data-gateway # Verificare curl https://gateway.example.com/health ---- ===== 8. Checklist ===== | # | Punto di verifica | v | |---|-----------|---| | 1 | Vecchio certificato salvato | ☐ | | 2 | Nuovo certificato valido | ☐ | | 3 | Hostname corrispondono | ☐ | | 4 | Certificato installato | ☐ | | 5 | Gateway riavviato | ☐ | | 6 | HTTPS funzionante | ☐ | | 7 | Monitoring notificato | ☐ | ---- ===== Troubleshooting ===== | Problema | Causa | Soluzione | |---------|---------|--------| | ''Certificate mismatch'' | Key non corrisponde | Rigenerare key | | ''Chain incomplete'' | Intermediate mancante | Aggiungere file chain | | ''Permission denied'' | Permessi errati | chmod 600 | | Gateway non si avvia | Password errata | Verificare appsettings.json | ---- ===== Monitoraggio Automatico ===== Alert Prometheus per scadenza certificato: - alert: GatewayCertExpiringSoon expr: | (probe_ssl_earliest_cert_expiry{job="gateway-tls"} - time()) / 86400 < 14 for: 1h labels: severity: warning annotations: summary: "Certificato Gateway in scadenza" description: "Il certificato scade tra {{ $value | humanize }} giorni." ---- ===== Runbook Correlati ===== * [[.:tls-einrichten|Configurare TLS]] - Configurazione iniziale * [[..:monitoring:alerting|Alerting]] - Monitoraggio scadenza * [[it:int:pqcrypt:szenarien:operator:tagesgeschaeft:zertifikat-erneuern|PQ Crypto: Rinnovare certificato]] ---- << [[.:tls-einrichten|<- Configurare TLS]] | [[.:firewall-regeln|-> Regole Firewall]] >> ---- //Wolfgang van der Stille @ EMSR DATA d.o.o. - Data Gateway Professional// {{tag>operator runbook certificato renewal tls}}