Let’s Encrypt - Certbot

Siehe auch

  • XCA

Installation

# CentOS: EPEL repo needed
# Fedora Server: coming from the updates repo
yum -y install certbot

Dies installiert auch die standardmässig deaktivierten certbot-renew.service und certbot-renew.timer. Konfiguriert wird Certbot in /etc/sysconfig/certbot.

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

Problem:

Traceback (most recent call last):
  File "/usr/bin/certbot", line 5, in <module>
    from pkg_resources import load_entry_point
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 3011, in <module>
    parse_requirements(__requires__), Environment()
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 630, in resolve
    raise VersionConflict(dist,req) # XXX put more info here
pkg_resources.VersionConflict: (cryptography 1.7.2 (/usr/lib64/python2.7/site-packages), Requirement.parse('cryptography>=1.9'))

Lösung:

yum -y install python-pip; pip install --upgrade cryptography

Problem:

Traceback (most recent call last):
  File "/usr/bin/certbot", line 9, in <module>
    load_entry_point('certbot==0.29.1', 'console_scripts', 'certbot')()
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 378, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2566, in load_entry_point
    return ep.load()
  File "/usr/lib/python2.7/site-packages/pkg_resources.py", line 2260, in load
    entry = __import__(self.module_name, globals(),globals(), ['__name__'])
  File "/usr/lib/python2.7/site-packages/certbot/main.py", line 23, in <module>
    from certbot import client
  File "/usr/lib/python2.7/site-packages/certbot/client.py", line 16, in <module>
    from acme import client as acme_client
  File "/usr/lib/python2.7/site-packages/acme/client.py", line 40, in <module>
    urllib3.contrib.pyopenssl.inject_into_urllib3()
AttributeError: 'module' object has no attribute 'pyopenssl'

Lösung:

yum -y install python-pip; pip install requests==2.6.0

Built on 2024-04-18