Let's Encrypt mit DNS-Validierung – Kurzanleitung

Veröffentlichung 3. Juli 2018 @ 16:58
Letzte Änderung 14. April 2021 @ 13:01

Überblick

  • Webserver muss für Zertifikatsaktualisierung nicht angehalten werden
  • Wildcard-Zertifikate sind möglich
  • (Voll-)Zugriff auf DNS-Server ist erforderlich

Voraussetzungen

Netzwerk

  • Domain / Zone example.com
  • (Beispiel-)Host www.example.com
  • IP-Adressse x.x.x.x

Software

  • Bind 9.10.3 #named -v
  • dns-rfc2136-Plugin 0.25.1 #pip3 freeze | grep certbot-dns-rfc2136
  • Let’s Encrypt 0.25.0 #certbot –version
  • Ubuntu Server 16.04.04 LTS #lsb_release -a

Ordner und Dateien

  • Installation /etc/letsencrypt, /var/lib/letsencrypt
  • Konfiguration /etc/letsencrypt/cli.ini, /etc/letsencrypt/renewal/*.conf
  • Log /var/log/letsencrypt/letsencrypt.log
  • logrotate /etc/logrotate.d/cert.bot
  • systemd /lib/systemd/system/certbot.service, /lib/systemd/system/certbot.timer
  • Zertifikate und Schlüssel /etc/letsencrypt/live/example.com/*.pem

Let’s Encrypt und dns-rfc2136-Plugin installieren

Basissystem installieren

apt install software-properties-common
add-apt-repository ppa:certbot/certbot
apt update
apt install certbot

Plugin dns-rfc2136 installieren

apt install python3-pip
pip3 install certbot-dns-rfc2136
#certbot plugins

Bind anpassen

TSIG-Schlüsselpaar erzeugen

dnssec-keygen -a HMAC-SHA512 -b 512 -K /etc/bind -n HOST -r /dev/urandom certbot.key

Privaten TSIG-Schlüssel auslesen

...
Key: ***
...

Konfiguration der Zone example.com ergänzen / ersetzen

key "certbot.key" {
algorithm hmac-sha512;
secret "***";
};
zone "example.com" {
allow-transfer {
any; #für Secondary Nameserver
};
file "/var/lib/bind/db.example.com";
update-policy {
grant certbot.key name _acme-challenge.example.com. txt;
grant certbot.key name _acme-challenge.www.example.com. txt;
};
type master;
};

Bind neustarten und Status abfragen

systemctl restart bind9
journalctl --unit bind9.service
systemctl status bind9.service

Let’s-Encrypt-Konfiguration anpassen

Konfigurationsdatei für dns-rfc2136-Plugin anlegen

mkdir --mode=0700 /etc/letsencrypt/dns-rfc2136
dns_rfc2136_server = x.x.x.x #DNS-Server
dns_rfc2136_port = 53 #DNS-Port
dns_rfc2136_name = certbot.key #TSIG-Schlüsselname
dns_rfc2136_secret = *** #Privater TSIG-Schlüssel
dns_rfc2136_algorithm = HMAC-SHA512 #TSIG-Schlüsselagorithmus
chmod 0600 /etc/letsencrypt/dns-rfc2136/dns-rfc2136.ini

(Haupt-)Konfigurationsdatei anpassen

...
agree-tos
authenticator = dns-rfc2136
dns-rfc2136-credentials = /etc/letsencrypt/dns-rfc2136/dns-rfc2136.ini
email = webmaster@example.com
preferred-challenges = dns-01
rsa-key-size = 4096
server = https://acme-v02.api.letsencrypt.org/directory #ACME v2 API für Wildcard-Zertifikate erforderlich

Zertifikate generieren

certbot certonly --config /etc/letsencrypt/cli.ini --domain *.example.com --domain example.com
certbot certonly --config /etc/letsencrypt/cli.ini --domain www.example.com
#certbot certificates
#openssl x509 -in /etc/letsencrypt/live/example.com/cert.pem -noout -text

Certbot-Status abfragen

journalctl --unit certbot.service
systemctl status certbot.timer

[Optional] Automatische Zertifikatsaktualisierung anpassen

(Original-)systemd-Timer-Datei

[Unit]
Description=Run certbot twice daily
[Timer]
OnCalendar=*-*-* 00,12:00:00
RandomizedDelaySec=43200
Persistent=true
[Install]
WantedBy=timers.target

(Original-)systemd-Service-Datei

[Unit]
Description=Certbot
Documentation=file:///usr/share/doc/python-certbot-doc/html/index.html
Documentation=https://letsencrypt.readthedocs.io/en/latest/
[Service]
Type=oneshot
ExecStart=/usr/bin/certbot -q renew

[Optional] Zertifikate widerrufen und Zertifikatsdateien löschen

certbot revoke --cert-path /etc/letsencrypt/live/example.com/cert.pem
certbot revoke --cert-path /etc/letsencrypt/live/www.example.com/cert.pem
#certbot delete --cert-name example.com
#certbot delete --cert-name www.example.com

Quellen

https://certbot-dns-rfc2136.readthedocs.io/en/latest/
https://ftp.isc.org/isc/bind9/cur/9.10/doc/arm/
https://letsencrypt.readthedocs.io/en/latest/
http://manpages.ubuntu.com/manpages/xenial/man8/dnssec-keygen.8.html
https://pypi.org/project/certbot-dns-rfc2136/#description