| Les deux révisions précédentes Révision précédente Prochaine révision | Révision précédente |
| openssl:accueil [2025/06/13 22:40] – [Générer un certificat auto-signé] add link phsw | openssl:accueil [2025/12/07 20:09] (Version actuelle) – [Gérer sa propre PKI] add how to use certbot with smallstep phsw |
|---|
| * [[https://blog.idriss-code.fr/gestion-pratique-des-certificats-avec-openssl/|Gestion pratique des certificats avec OpenSSL]] | * [[https://blog.idriss-code.fr/gestion-pratique-des-certificats-avec-openssl/|Gestion pratique des certificats avec OpenSSL]] |
| |
| | |
| | ==== Ajouter un certificat au système ==== |
| | |
| | <code bash> |
| | sudo apt install libnss3-tools |
| | |
| | sudo cp homelab.crt /usr/local/share/ca-certificates/ |
| | sudo update-ca-certificates |
| | sudo chmod a+r /usr/local/share/ca-certificates/ |
| | </code> |
| | |
| | Pour que le certificat soit aussi reconnu dans Firefox et Thunderbird, il faut exécuter le script suivant ([[https://askubuntu.com/a/369858|source]]) : |
| | |
| | <code bash> |
| | sudo apt install libnss3-tools # pour certutil |
| | |
| | readonly certificateFile="/usr/local/share/ca-certificates/homelab.crt" |
| | readonly certificateName="Homelab" |
| | |
| | find ~/.mozilla* ~/.thunderbird -name "cert9.db" | while read -r certDB |
| | do |
| | certDir=$(dirname "${certDB}"); |
| | echo "install '${certificateName}' in ${certDir}" |
| | certutil -A -n "${certificateName}" -t "TCu,Cuw,Tuw" -i ${certificateFile} -d ${certDir} |
| | done |
| | </code> |
| |
| |
| * https://www.certwarden.com/, https://smallstep.com/docs/step-ca/getting-started/ | * https://www.certwarden.com/, https://smallstep.com/docs/step-ca/getting-started/ |
| * [[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]] |
| | |
| | |
| | === Avec Smallstep === |
| | |
| | * [[https://gyptazy.com/building-your-own-pki-with-step-ca-from-root-ca-to-proxmox-integration-with-acme/|Building Your Own PKI with Step-CA – From Root CA to Proxmox Integration with ACME]] |
| | * [[https://smallstep.com/blog/build-a-tiny-ca-with-raspberry-pi-yubikey/|Build a Tiny Certificate Authority For Your Homelab]] |
| | * [[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://www.networktechguy.com/smallsteps-step-ca-as-ca-with-acme-support/|Smallstep's step-ca as CA with ACME support]] |
| | |
| | <code bash> |
| | sudo curl -fsSL https://packages.smallstep.com/keys/apt/repo-signing-key.gpg -o /etc/apt/trusted.gpg.d/smallstep.asc && \ |
| | echo 'deb [signed-by=/etc/apt/trusted.gpg.d/smallstep.asc] https://packages.smallstep.com/stable/debian debs main' \ |
| | | sudo tee /etc/apt/sources.list.d/smallstep.list |
| | sudo apt update |
| | sudo apt install step-ca step-cli |
| | |
| | step ca init |
| | |
| | sudo step-ca $(step path)/config/ca.json |
| | |
| | step ca provisioner add acme --type ACME --x509-default-dur=$((30*24))h |
| | |
| | sudo useradd --user-group --system --home /etc/step-ca --shell /bin/false step |
| | sudo setcap CAP_NET_BIND_SERVICE=+eip $(which step-ca) |
| | sudo mv $(step path) /etc/step-ca |
| | # put password in /etc/step-ca/password.txt |
| | sudo chmod 400 /etc/step-ca/password.txt |
| | # edit and adapt paths in /etc/step-ca/config/defaults.json |
| | # edit and adapt paths in /etc/step-ca/config/ca.json |
| | sudo chown -R step:step /etc/step-ca |
| | # create the service in /etc/systemd/system/step-ca.service |
| | sudo systemctl daemon-reload |
| | sudo systemctl status step-ca |
| | sudo systemctl enable --now 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> |