Certificates
Get a Let's Encrypt certificate for Flaq Connect or Flaq Relay with certbot, and a deploy hook that hands each renewal to the container and restarts it.
Flaq Connect and Flaq Relay each serve their own certificate, from a certificate authority, for their host name. A reverse proxy can't stand in front of their UDP side, where servers and apps check the certificate, so the container reads it from its certs/ directory. Certbot gets one from Let's Encrypt, and a small hook copies it where the container reads it and restarts the container at every renewal.
The Messaging Server doesn't need this: with your own domain the reverse proxy holds its certificate, and at home the apps check the server's own key instead.
For a Connect#
The examples use connect.example.com as the host name and /opt/flaq-connect as the directory you made for it. Change both to yours.
1. Save the hook#
Save this as /etc/letsencrypt/renewal-hooks/deploy/flaq-connect.sh:
#!/bin/sh
# Hands a renewed certificate to Flaq Connect, which runs as uid 1000.
set -e
case "$RENEWED_LINEAGE" in */connect.example.com) ;; *) exit 0 ;; esac
dir=/opt/flaq-connect/certs
install -m 0644 -o 1000 "$RENEWED_LINEAGE/fullchain.pem" "$dir/fullchain.pem"
install -m 0600 -o 1000 "$RENEWED_LINEAGE/privkey.pem" "$dir/privkey.pem"
docker restart flaq-connect 2>/dev/null || true
It acts only on the certificate for your host name, copies the chain and the key into certs/ owned by uid 1000, which the container runs as, and restarts the container.
2. Get the certificate#
With TCP port 80 open and nothing else listening on it:
sudo chmod +x /etc/letsencrypt/renewal-hooks/deploy/flaq-connect.sh
sudo certbot certonly --standalone -d connect.example.com \
--deploy-hook /etc/letsencrypt/renewal-hooks/deploy/flaq-connect.sh
3. Check renewal#
Certbot's timer renews the certificate before it expires and runs the hook each time. This checks that renewing works:
sudo certbot renew --dry-run
For a relay#
The same steps, with connect replaced by relay throughout, and /opt/flaq-connect replaced by the directory you made for the relay. The hook then lives at /etc/letsencrypt/renewal-hooks/deploy/flaq-relay.sh, matches your relay's host name, such as relay.example.com, and restarts flaq-relay.
Behind a reverse proxy#
A Connect whose HTTPS side runs behind a reverse proxy still needs the certificate in certs/: give it the same certificate the proxy got, and again after each renewal. The servers and apps check it on the UDP side, where the proxy isn't in between. See Run a Connect.
Wildcard certificates for handles#
On a Connect, the handles of servers listed by name, such as @ana@anas-place.connect.example.com, work only with a wildcard DNS record and a certificate that also covers *.<host>: Connect answers for each name at <name>.<host>. A wildcard certificate from Let's Encrypt needs a DNS challenge rather than the standalone one above, so you need API access to your DNS, or renew it by hand.
If the container stops at start
A Connect or a relay that stops with "reading /certs/…" can't find the certificate files, or uid 1000 can't read them. Run the hook again, or
sudo chown 1000 certs/*.pemin the part's directory.