Certbot

Bemerkung

Die Linuxfabrik setzt als ACME-Client standardmässig acme.sh ein (siehe acme.sh). certbot wird nur in Ausnahmefällen verwendet. Eine Einordnung zwischen den Clients sowie die ACME-Grundlagen stehen in ACME und Let’s Encrypt.

Installation

Auf RHEL-basierten Systemen liegt certbot im EPEL. Auf Fedora Server kommt es aus dem Standard-Repository. Debian und Ubuntu liefern das Paket direkt im Main-Repo mit.

# RHEL 8+: enable EPEL, then install
dnf --assumeyes install epel-release
dnf --assumeyes install certbot

Das Paket bringt einen systemd-Timer certbot-renew.timer mit, der standardmässig deaktiviert ist. Aktiviert wird er per systemctl enable --now certbot-renew.timer. Konfiguration des Renewal-Laufs findet in /etc/sysconfig/certbot statt.

Verwendung

Übersicht über alle Zertifikate anzeigen:

certbot certificates

Würde ein Renewal funktionieren?

certbot renew --dry-run

Zertifikat löschen:

# this is interactive:
certbot revoke --cert-path /etc/letsencrypt/live/xy.domain.com/cert.pem

# after that, one of those this might be useful:
httpd -t
haproxy -c -V -f /etc/haproxy/haproxy.cfg

Certbot mit Apache

Zertifikat ausstellen

Methode 1: Stoppt den Webserver.

yum -y install python3-certbot-apache
certbot --apache \
    --rsa-key-size 4096 --email webmaster@linuxfabrik.ch --agree-tos --renew-by-default \
    --domains linuxfabrik.ch,www.linuxfabrik.ch

Methode 2: Die von uns favorisierte Variante. Diese stoppt den Webserver nicht, benötigt aber auf dem Webserver oder Reverse Proxy einen konfigurierten http-vHost inkl. DocumentRoot (also für Port 80, ohne Redirects).

Domain-Name aktivieren:

/etc/httpd/sites-enabled/000-letsencrypt.conf
<VirtualHost *:80>
  ServerName linuxfabrik.ch
  ServerAlias www.linuxfabrik.ch
  DocumentRoot /var/www/html/letsencrypt
</VirtualHost>
systemctl reload httpd

certbot certonly --webroot \
    --rsa-key-size 4096 --email webmaster@linuxfabrik.ch --agree-tos --renew-by-default \
    --webroot-path /var/www/html/letsencrypt \
    --domains linuxfabrik.ch,www.linuxfabrik.ch

Danach „ServerName“ und „ServerAlias“ im letsencrypt-vhost deaktivieren, und Renewal-Datei anpassen:

/etc/letsencrypt/renewal/…conf
# Options used in the renewal process
[renewalparams]
account = ...
authenticator = apache
installer = apache
rsa_key_size = ...
server = ...
Wöchentliches Zertifikats-Renewal (ohne Systemd-Timer):
17 01 * * sun /usr/bin/certbot renew --quiet --post-hook "/usr/bin/systemctl reload httpd"

Certbot mit HAProxy

Zertifikat ausstellen

Stoppt HAproxy auf jeden Fall:

systemctl stop haproxy
certbot certonly --standalone \
    --rsa-key-size 4096 --email webmaster@linuxfabrik.ch --agree-tos --renew-by-default \
    --domains linuxfabrik.ch,www.linuxfabrik.ch
systemctl start haproxy
cd /etc/letsencrypt/live/linuxfabrik.ch
cat fullchain.pem privkey.pem > linuxfabrik.ch.pem

Anschliessend Renewal-Datei anpassen:

/etc/letsencrypt/renewal/…conf
# Options used in the renewal process
[renewalparams]
account = ...
authenticator = standalone
rsa_key_size = ...
server = ...
pre_hook = /usr/bin/systemctl stop haproxy; sleep 2;
post_hook = /usr/bin/systemctl start haproxy
Wöchentliches Zertifikats-Renewal (ohne Systemd-Timer):
17 01 * * sun /usr/bin/certbot renew --quiet; cd /etc/letsencrypt/live/linuxfabrik.ch; cat fullchain.pem privkey.pem > linuxfabrik.ch.pem; systemctl reload haproxy

Certbot mit Nginx

Zertifikat ausstellen

Stoppt den Webserver nicht, benötigt aber auf dem Webserver/Reverse Proxy einen konfigurierten http-vHost inkl. root (also für Port 80):

...location ^~ /.well-known/acme-challenge/ {
    default_type „text/plain“;
    root /var/www/html;
    allow all;
}

# Redirect all insecure http:// requests to https://
location / {
    return 301 https://$host$request_uri;
}...

Anschliessend Renewal-Datei anpassen:

/etc/letsencrypt/renewal/…conf
# Options used in the renewal process
[renewalparams]
account = ...
authenticator = webroot
installer = None
webroot_path = /var/www/html
[[webroot_map]]
example.com = /var/www/html

Troubleshooting

Siehe ACME und Let’s Encrypt, Abschnitt Troubleshooting. Dort sind die typischen ACME-Fehler unabhängig vom Client-Tool beschrieben (Rate-Limit, fehlgeschlagene Authorization, Port-80-Erreichbarkeit, nicht eingezogener Reload).