ssl certificate¶
About¶
Every service that terminates TLS needs the cert.crt / cert.key pair. There are two ways to get it:
Command |
Certificate |
When to use |
|---|---|---|
|
self-signed, 365 days |
first start and experiments. Browsers show a certificate warning |
|
free certificate from Let’s Encrypt (ACME) |
production. Valid for 3 months, renew it automatically, see section 4 |
1. Generate a self-signed certificate¶
cd bind-docker/office
make openssl
nginx/certs/cert.crt and nginx/certs/cert.key, with CN=$DOMAIN and a validity of 365 daysmake runs this target as well, so the first make creates the pair when it is missingNote that only nginx gets a certificate this way. bindsmtp and bindimap read their pair from smtp/certs and imap/certs, and without a certificate bindimap does not start. Those directories are filled by section 2, so use the self-signed certificate for HTTPS only, or install a free certificate as described next.
2. Get a free Let’s Encrypt certificate¶
make cert
make cert is make generate copymake generate calls the /acme/create interface over HTTP, and the issued pair is written into the BIND_CERT_DIR of bindinbox, which is bind-mounted from bindinbox/certsmake copy then installs the pair into every TLS service, see section 3Requirements:
DOMAINresolves to the public IP address of the server and port 80 is reachable from the internet, which is how the HTTP-01 challenge is answeredthe containers are running, because the command goes through nginx on port 80 to the application
3. Which service uses which certificate¶
make copy (sh bin/cert-distribute.sh) copies the pair from bindinbox/certs (bindmeet/certs for the standalone meeting deployment) into the services that terminate TLS:
Directory |
Service |
|---|---|
|
nginx: HTTPS on 443 and the MQTT TLS port |
|
bindsmtp: SMTP submission with STARTTLS |
|
bindimap: IMAPS |
Run it on its own after replacing the certificate by hand:
make copy
4. Automatic renewal¶
make cron # install the renewal job, replaces an existing one
make uncron # remove it
sh bin/cert-cron.sh show # print the installed job
make renew once a day and appends the output to logs/cert-renew.logmake renew (sh bin/cert-renew.sh) is idempotent: it inspects the certificate nginx currently serves with openssl x509 -checkend and exits immediately when more than CERT_RENEW_DAYS days are left/acme/renew interface, install the new pair and reload the servicesAfter a renewal the services pick up the new pair like this:
Service |
What happens |
|---|---|
nginx |
|
bindsmtp, bindimap |
|
To renew even when the certificate is still valid, for example after changing DOMAIN:
CERT_FORCE_RENEW=1 sh bin/cert-renew.sh
make cron, and that user needs passwordless access to the Docker daemon, be in the docker group or run make cron as root, otherwise the job cannot reach the containerscd <deployment directory> && make renew from a systemd timer or another schedulerVariable |
Default |
Description |
|---|---|---|
|
|
renew when fewer days than this are left |
|
|
crontab schedule that |
|
unset |
when set, renew without checking the remaining days; pass it on the command line, it is not read from .env |