| Les deux révisions précédentes Révision précédente | |
| openssl:accueil [2025/12/06 22:39] – add how to add a certificate to the system phsw | openssl:accueil [2025/12/07 20:09] (Version actuelle) – [Gérer sa propre PKI] add how to use certbot with smallstep phsw |
|---|
| * [[https://github.com/FiloSottile/mkcert|mkcert]] | * [[https://github.com/FiloSottile/mkcert|mkcert]] |
| * [[https://support.tools/create-certificate-authority-homelab/|Create Your Own Certificate Authority (CA) for Homelab Environment]] | * [[https://support.tools/create-certificate-authority-homelab/|Create Your Own Certificate Authority (CA) for Homelab Environment]] |
| * | |
| |
| === Avec Smallstep === | === Avec Smallstep === |
| * [[https://www.reddit.com/r/homelab/comments/azxwql/setup_an_internal_homelab_pki_and_get_valid_https/|Setup an internal homelab PKI and get valid HTTPS certificates using step]] | * [[https://www.reddit.com/r/homelab/comments/azxwql/setup_an_internal_homelab_pki_and_get_valid_https/|Setup an internal homelab PKI and get valid HTTPS certificates using step]] |
| * [[https://smallstep.com/docs/step-ca/certificate-authority-server-production/#running-step-ca-as-a-daemon]] | * [[https://smallstep.com/docs/step-ca/certificate-authority-server-production/#running-step-ca-as-a-daemon]] |
| | * [[https://www.networktechguy.com/smallsteps-step-ca-as-ca-with-acme-support/|Smallstep's step-ca as CA with ACME support]] |
| |
| <code bash> | <code bash> |
| sudo systemctl enable --now step-ca | sudo systemctl enable --now step-ca |
| sudo journalctl --follow --unit=step-ca | sudo journalctl --follow --unit=step-ca |
| | </code> |
| | |
| | |
| | === Utiliser Certbot pour récupérer un certificat === |
| | |
| | * [[https://smallstep.com/docs/tutorials/acme-protocol-acme-clients/|Configure popular ACME clients to use a private CA with the ACME protocol]] |
| | * [[https://wizardsoftheweb.pro/certbot-hook-api/|The certbot Hook API]] |
| | * [[https://university.itametis.com/fr/articles/informatique/security/ssl/015_adding_hooks_before_after_certificate_renewal|Ajouter des hooks avant/après le renouvellement d'un certificat Let's Encrypt]] |
| | * [[https://gist.github.com/kaczmar2/e1b5eb635c1a1e792faf36508c5698ee|Pi-hole v6: Creating Your Own Self-Signed SSL Certificates]] |
| | |
| | Ici, on utilise Certbot pour automatiser la récupération d'un certificat pour l'interface web de PiHole : |
| | <code bash> |
| | sudo apt install certbot |
| | |
| | sudo certbot certonly -n --standalone -d pihole.homelab --server https://ca.homelab/acme/acme/directory |
| | |
| | sudo cat /etc/letsencrypt/live/pihole.homelab/privkey.pem /etc/letsencrypt/live/pihole.homelab/fullchain.pem | sudo tee /etc/pihole/tls.pem |
| | sudo service pihole-FTL restart |
| | </code> |
| | |
| | Après la commande, Certbot va automatiquement créer un timer Systemd pour deux fois par jour renouveler les certificats. Pour que le certificat renouvelé soit pris en compte par PiHole, créer le script ''/etc/letsencrypt/renewal-hooks/deploy/pihole'' (lui donner l'autorisation en exécution) : |
| | <code bash> |
| | #!/bin/sh -eu |
| | |
| | found=0 |
| | for domain in $RENEWED_DOMAINS |
| | do |
| | if [ "$domain" = "pihole.homelab" ] |
| | then |
| | found=1 |
| | fi |
| | done |
| | if [ "$found" = "0" ] |
| | then |
| | exit 0 |
| | fi |
| | |
| | cp /etc/pihole/tls.pem /etc/pihole/tls.pem.old |
| | cat /etc/letsencrypt/live/pihole.homelab/privkey.pem /etc/letsencrypt/live/pihole.homelab/fullchain.pem > /etc/pihole/tls.pem |
| | |
| | service pihole-FTL restart |
| | </code> |
| | |
| | Un bug dans la version 4.0.0 de Certbot considère que ''renew_before_expiry'' vaut toujours 30 jours. Si les certificats ont une durée de validité de 30 jours, cela signifie qu'ils sont renouvelés à chaque fois. Pour contourner le bug, il faut préciser la durée de renouvellement dans ''/etc/letsencrypt/renewal/domain.conf'' : |
| | <code> |
| | renew_before_expiry = 10 days |
| </code> | </code> |