Server - SSL certificate

16 Sep 26

'Your connection is not private'
sudo certbot certificates [confirms HTTPS certificate expired]
Problem: The original single certificate covered both simbed.duckdns.org and *.simbed.duckdns.org.
Automatic renewal failed because the DuckDNS API could only maintain one TXT challenge at a time, whereas the combined certificate required two DNS challenges.

Solution: Use two separate certificates:
Certificate: simbed.duckdns.org for *.simbed.duckdns.org domain
Certificate: simbed.duckdns.org-bare for simbed.duckdns.org domain

Both use the same DuckDNS authentication hook: ~/simbed/certbot-hooks/duckdns-auth.sh (The hook sends a certbot token to DuckDNS via its API, updating the _acme-challenge.me.duckdns.org TXT record. Let's Encrypt can check that TXT record. It's called a challenge because Let's Encrypt is challenging me to prove ownership of the domain. If it matches, Let's Encrypt will issue the certificate.)

Done manually, this could be done like:
export DUCKDNS_TOKEN="your-duckdns-token" [from https://www.duckdns.org/]
sudo certbot certonly \
  --manual \
  --preferred-challenges dns \
  --manual-auth-hook ~/certbot-hooks/duckdns-auth.sh \
  -d "*.simbed.duckdns.org"

sudo ngnix -t
sudo systemctl reload nginx

ping technical-diary.simbed.duckdns.org [should now 200]

It should all be automated now, however.
A root-owned environment file (with chmod 600 permissions) contains the DuckDNS token: /etc/letsencrypt/duckdns.env with DUCKDNS_TOKEN=...
A systemd drop-in for Certbot loads this environment file: 
/etc/systemd/system/certbot.service.d/override.conf
note we use this drop-in approach and don't directctly edit certbot.service (as future certbot updates would overwrite the edits if we did).
And view the complete service with the drop-in included by systemctl cat certbot.service

Nginx certificates

Wildcard sites use:

/etc/letsencrypt/live/me.duckdns.org/fullchain.pem
/etc/letsencrypt/live/me.duckdns.org/privkey.pem
The bare me.duckdns.org site uses:
/etc/letsencrypt/live/me.duckdns.org-bare/fullchain.pem
/etc/letsencrypt/live/me.duckdns.org-bare/privkey.pem
After changing the nginx configuration:

sudo nginx -t
sudo systemctl reload nginx

Automatic Renewal
Automatic renewal Certbot's existing systemd timer runs:
certbot renew
Both certificates are therefore included in the automatic renewal process. We confirmed the renewal configuration with:
sudo certbot renew --dry-run
and the dry run passed. Finally, this deploy hook was added so nginx automatically reloads after a successful renewal:
/etc/letsencrypt/renewal-hooks/deploy/reload-nginx.sh
containing:
#!/bin/bash
systemctl reload nginx
and made executable: Result: wildcard and bare-domain certificates are separate, both can renew automatically using the same DuckDNS hook, and nginx reloads automatically after renewal.