- Modifié
Pas mal le script.
Moi j'utilisais ça, mais pas avec acme.sh
:
f_check_certs() {
cd /etc/letsencrypt/live
for domain in `find * -type d`; do
FULLCHAINFILE=/etc/letsencrypt/live/${domain}/fullchain.pem
openssl x509 -checkend 864000 -noout -in "${FULLCHAINFILE}" &>/dev/null
if [ $? == 0 ]; then
f_log INF "Certificate for ${domain} is good for another 10 days!"
else
f_log INF "Time to renew ${domain}!"
f_log INF "Downloading cerbot image..."
docker pull certbot/certbot &>/dev/null
f_log INF "Stopping nginx..."
service nginx stop &>/dev/null
f_log INF "Renewing ${domain}..."
old_fingerprint=$(openssl x509 -noout -in "${FULLCHAINFILE}" -fingerprint -sha256 | cut -c 20- | sed s/://g | awk '{print tolower($0)}')
cd ${domain}
cp cert.pem old_cert.pem && cp chain.pem old_chain.pem && cp fullchain.pem old_fullchain.pem
docker run -ti --rm -p 80:80 -p 443:443 -v /etc/letsencrypt:/etc/letsencrypt certbot/certbot \
certonly --standalone --agree-tos -m wonderfall@targaryen.house \
--csr /etc/letsencrypt/live/${domain}/csr.der \
--cert-path /etc/letsencrypt/live/${domain}/cert.pem \
--chain-path /etc/letsencrypt/live/${domain}/chain.pem \
--fullchain-path /etc/letsencrypt/live/${domain}/fullchain.pem
new_fingerprint=$(openssl x509 -noout -in "${FULLCHAINFILE}" -fingerprint -sha256 | cut -c 20- | sed s/://g | awk '{print tolower($0)}')
f_log INF "Certificate renewed for ${domain}."
f_log INF "Starting nginx..."
service nginx start &>/dev/null
f_log INF "Updating TLSA records..."
sed -i "s/${old_fingerprint}/${new_fingerprint}/g" /home/docker/nsd/zones/db.${domain}
dns_update.sh ${domain}
f_log INF "Done!"
fi
done
}
domain=$1
f_log INF "Domain set to ${domain}."
old_serial=$(grep "Serial" /home/docker/nsd/zones/db.${domain} | grep -o '[0-9]\+')
new_serial=${old_serial} && let new_serial++
sed -i -e "s/${old_serial}/${new_serial}/g" /home/docker/nsd/zones/db.${domain}
f_log INF "Incremented serial."
f_log INF "Signing DNS zone..."
docker exec nsd signzone ${domain} &>/dev/null
f_log INF "Done."
C'est moins propre mais ça faisait le boulot. Si tu fais ton truc pars plutôt ce qu'a fait Hardware je pense. Perso faut je revois ça pour traefik et comment dump les certs de acme.json
d'abord...
Au passage, je ne suis pas fan du wildcard, pourquoi ? C'est bien si l'utilises sur un seul serveur, mais sinon c'est une mauvaise pratique que d'éparpiller des clés privées à d'autres serveurs dont la compromission de l'un peut mener à la compromission de l'ensemble du domaine. Tous les sous-domaines sont à risque quand tu fais un wildcard (SPOF). Je ne dis pas qu'il faut éviter, je dis juste qu'il faut être prudent...