====== Integrazione ACME ====== **Complessità:** Media \\ **Durata:** 1-2 ore di configurazione \\ **Prerequisito:** Accesso DNS/HTTP Challenge Integrazione del protocollo ACME (RFC 8555) per il rinnovo automatico dei certificati con supporto Post-Quantum. ---- ===== Architettura ===== sequenceDiagram participant Client as Client ACME participant CA as CA ACME participant DNS as Server DNS/HTTP participant App as Applicazione Client->>CA: 1. Creazione account Client->>CA: 2. Creazione ordine (CSR) CA->>Client: 3. Challenge (DNS-01/HTTP-01) Client->>DNS: 4. Completamento challenge CA->>DNS: 5. Validazione challenge CA->>Client: 6. Emissione certificato Client->>App: 7. Distribuzione certificato Client->>App: 8. Ricarica servizio ---- ===== Installazione Certbot ===== # Debian/Ubuntu apt update && apt install certbot python3-certbot-nginx # RHEL/CentOS dnf install certbot python3-certbot-nginx # Con plugin DNS (Cloudflare) apt install python3-certbot-dns-cloudflare ---- ===== HTTP-01 Challenge ===== **Per server web raggiungibili pubblicamente:** # Nginx certbot --nginx -d example.com -d www.example.com # Apache certbot --apache -d example.com -d www.example.com # Standalone (porta 80 libera) certbot certonly --standalone -d example.com # Webroot (server esistente) certbot certonly --webroot -w /var/www/html -d example.com **Cron per rinnovo automatico:** # Attivato automaticamente con l'installazione di certbot # Verifica manuale: systemctl status certbot.timer # Test manuale certbot renew --dry-run ---- ===== DNS-01 Challenge ===== **Per server interni o wildcard:** ==== Cloudflare ==== # /etc/letsencrypt/cloudflare.ini dns_cloudflare_api_token = YOUR_API_TOKEN chmod 600 /etc/letsencrypt/cloudflare.ini certbot certonly \ --dns-cloudflare \ --dns-cloudflare-credentials /etc/letsencrypt/cloudflare.ini \ -d example.com \ -d "*.example.com" ==== Route53 (AWS) ==== # Credenziali AWS in ~/.aws/credentials certbot certonly \ --dns-route53 \ -d example.com \ -d "*.example.com" ==== Azure DNS ==== # Con plugin certbot-dns-azure pip install certbot-dns-azure certbot certonly \ --authenticator dns-azure \ --dns-azure-credentials /etc/letsencrypt/azure.ini \ -d example.com ---- ===== Hook di distribuzione ===== Gli hook vengono eseguiti dopo un rinnovo riuscito. ==== Ricarica Nginx ==== # /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh #!/bin/bash systemctl reload nginx echo "$(date): Nginx ricaricato" >> /var/log/certbot-deploy.log chmod +x /etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh ==== Ricarica Apache ==== # /etc/letsencrypt/renewal-hooks/deploy/reload-apache.sh #!/bin/bash systemctl reload apache2 ==== Container Docker ==== # /etc/letsencrypt/renewal-hooks/deploy/docker-reload.sh #!/bin/bash docker exec nginx nginx -s reload # oppure docker-compose restart nginx ==== Notifica ==== # /etc/letsencrypt/renewal-hooks/post/notify.sh #!/bin/bash DOMAINS=$(echo $RENEWED_DOMAINS | tr ' ' '\n') echo "Rinnovato: $DOMAINS" | mail -s "Certificato rinnovato" admin@example.com ---- ===== CA ACME privata (Step-CA) ===== Per PKI interna con supporto ACME: # Installazione Step-CA wget https://github.com/smallstep/certificates/releases/download/v0.25.0/step-ca_0.25.0_amd64.deb dpkg -i step-ca_0.25.0_amd64.deb # Inizializzazione CA step ca init --name="Internal CA" --dns=ca.internal.example.com --address=:443 **Aggiunta provisioner ACME:** step ca provisioner add acme --type ACME **Certbot con CA privata:** certbot certonly \ --server https://ca.internal.example.com/acme/acme/directory \ --standalone \ -d internal-server.example.com ---- ===== Nota Post-Quantum ===== **Stato 2024:** Il protocollo ACME e Let's Encrypt non supportano ancora firme PQ. **Strategia ibrida:** # 1. Certificato ACME per handshake TLS (ECDSA) certbot certonly --nginx -d example.com # 2. Certificato PQ aggiuntivo per modalità ibrida # (in parallelo tramite PKI propria con WvdS) // C#: Creazione certificato ibrido in parallelo using var ecdsa = ECDsa.Create(ECCurve.NamedCurves.nistP384); var request = new CertificateRequest( "CN=example.com", ecdsa, HashAlgorithmName.SHA384); // Con estensione PQ per client pronti per il futuro var cert = request.CreateSelfSigned( DateTimeOffset.UtcNow, DateTimeOffset.UtcNow.AddDays(90), CryptoMode.Hybrid); ---- ===== Monitoraggio ===== # Log Certbot tail -f /var/log/letsencrypt/letsencrypt.log # Verifica scadenza certificato certbot certificates # Prometheus Exporter (cert-exporter) # Monitora tutti i certificati per la scadenza ---- ===== Risoluzione problemi ===== | Problema | Causa | Soluzione | |----------|-------|-----------| | ''Challenge failed'' | Porta 80/443 bloccata | Verificare firewall | | ''DNS propagation'' | Cache DNS | Attendere (fino a 60 min) o ridurre TTL | | ''Rate limit exceeded'' | Troppe richieste | Usare server staging | | ''unauthorized'' | Validazione dominio fallita | Verificare record DNS | # Server staging per test (nessun limite di rate) certbot certonly --staging --nginx -d test.example.com # Modalità debug certbot certonly --nginx -d example.com --debug ---- ===== Checklist ===== | # | Punto di verifica | ✓ | |---|-------------------|---| | 1 | DNS/HTTP Challenge configurato | ☐ | | 2 | Certbot installato e testato | ☐ | | 3 | Rinnovo automatico attivato (Timer) | ☐ | | 4 | Hook di distribuzione configurato | ☐ | | 5 | Monitoraggio configurato | ☐ | | 6 | Notifica in caso di errore | ☐ | ---- ===== Documentazione correlata ===== * [[.:scheduled-renewal|Rinnovo schedulato]] – Alternativa senza ACME * [[..:monitoring:ablauf-monitoring|Monitoraggio scadenze]] – Sorveglianza certificati * [[it:int:pqcrypt:szenarien:tls:start|TLS/mTLS]] – Configurazione server ---- << [[.:start|← Automazione]] | [[.:cicd-code-signing|→ Code-Signing CI/CD]] >> ---- //Wolfgang van der Stille @ EMSR DATA d.o.o. - Post-Quantum Cryptography Professional// {{tag>acme letsencrypt certbot automazione operator}}