LetsEncrypt

De Breizh-Entropy
Révision datée du 16 février 2021 à 20:20 par Guest (discussion | contributions) (màj noms de fichiers)
Aller à la navigation Aller à la recherche

Mise en place de certificats httpS Let's Encrypt sur un environnent multi-domaines, avec validation DNS (pour faciliter l'interaction avec Apache + pas d'interruption de service + possibilité de wildcard) et renouvellement automatique.

# Dépendances
apt install dnsutils  #	nsupdate

# Utilisateur dédié
apt install ssl-cert
useradd acme -g ssl-cert -m -s /bin/bash -r
su - acme
git clone https://github.com/acmesh-official/acme.sh
cd acme.sh/
./acme.sh --install --nocron


# Stockage
mkdir -m 710 /etc/acme
chown acme:ssl-cert /etc/acme/

# Lien avec bind
# https://github.com/acmesh-official/acme.sh/wiki/dnsapi#7-use-nsupdate-to-automatically-issue-cert
touch /etc/bind/acme.key
chown acme:bind /etc/bind/acme.key
chmod 640 /etc/bind/acme.key
b=$(dnssec-keygen -a hmac-sha512 -b 512 -n USER -K /tmp foo)
cat > /etc/bind/acme.key <<EOF
key "acme" {
    algorithm hmac-sha512;
    secret "$(awk '/^Key/{print $2}' /tmp/$b.private)";
};
EOF
rm -f /tmp/$b.{private,key}

# Conf bind
include "/etc/bind/acme.key";
zone "breizh-entropy.org" {
        type master;
        file "/etc/bind/master/breizh-entropy.org.db";
        allow-update { key "acme"; };
        ...
};
# Attention: prévoir un Negative TTL bas (60s) dans la zone car des
# entrées TXT _acme-challenge.xxx sont créées/supprimées rapidement

# AppArmor si besoin
echo '/etc/bind/master/** rw,' > /etc/apparmor.d/local/usr.sbin.named

# Lien avec apache
cat <<EOF > /etc/sudoers.d/acme
acme    ALL = NOPASSWD: /usr/sbin/service apache2 force-reload
EOF

# Conf apache
SSLEngine on
SSLCertificateFile /etc/acme/multi-domain.cer
SSLCertificateKeyFile /etc/acme/multi-domain.key
SSLCertificateChainFile /etc/acme/fullchain.cer


# Installation initiale
rm -rf ~/.acme.sh/
NSUPDATE_SERVER="breizh-entropy.org" NSUPDATE_KEY="/etc/bind/acme.key" \
  acme.sh \
  --issue --dns dns_nsupdate -d breizh-entropy.org -d '.breizh-entropy.org' -d jardin-entropique.eu.org -d www.jardin-entropique.eu.org --debug \
  --staging
acme.sh --install-cert -d breizh-entropy.org \
  --cert-file /etc/acme/multi-domain.cer --key-file /etc/acme/multi-domain.key --fullchain-file /etc/acme/fullchain.cer \
  --reloadcmd "sudo service apache2 force-reload"
# Note: paramètres sauvés dans ~/.acme.sh/breizh-entropy.org/breizh-entropy.org.conf
# (y compris reloadcmd en base64)

# --dnssleep 60 peut être nécessaire (20s par défaut)

# Puis sans --staging.

# Test cron
~/.acme.sh/acme.sh --cron --staging

# Cron (renouvellement tous les mois par défaut)
cat <<EOF > /etc/cron.d/acme
MAIL=root
36 0 * * *      acme    /home/acme/.acme.sh/acme.sh --cron > /dev/null
EOF

# Maintenance
https://github.com/acmesh-official/acme.sh/#14-how-to-upgrade-acmesh

Créé initialement pendant Ateliers2020/LetsEncryptDNS