Here are a my settings for dovecot and sendmail as a reference. I read up on that topic and all of the answers and blog posts are actually wrong or miss the background.
dovecot (dovecot.conf
):
ssl_cert = </etc/letsencrypt/live/CERTNAME/fullchain.pem
ssl_key = </etc/letsencrypt/live/CERTNAME/privkey.pem
sendmail (sendmail.mc
):
define(`CERT_DIR', `/etc/letsencrypt/live/CERTNAME')
define(`confCACERT_PATH', `CERT_DIR')
define(`confCACERT', `CERT_DIR/fullchain.pem')
define(`confSERVER_CERT', `CERT_DIR/cert.pem')
define(`confSERVER_KEY', `CERT_DIR/privkey.pem')
define(`confCLIENT_CERT', `CERT_DIR/cert.pem')
define(`confCLIENT_KEY', `CERT_DIR/privkey.pem')
define(`confDONT_BLAME_SENDMAIL',`groupreadablekeyfile')dnl
sendmail does not like the key with permission 644, thus it starts up, but it does not accept TLS connections.
To solve this problem, one has to set the permission of the private key as follows:
chmod 640 /etc/letsencrypt/live/CERTNAME/privkey.pem
As for confCACERT
: this parameter is supposed to hold the CA bundle, but most systems do not have a recent version that does include the CA and intermediary certs of Letsencrypt. There are several option to solve this problem:
- download a newer ca-bundle (curl has usually very recent ones, mozilla is also a good source)
- add the letsencrypt root and intermediate certs to your bundle manually
- use a workaround (other would call it a hack) and use the
fullchain.pem
, since it includes all necessary certs
The confCLIENT_*
parameters are not really needed but don’t hurt either. Letsencrypt does not provide client certs so setting up a “local” CA that allows people to use client certs to authenticate against sendmail is pretty much useless.
Sendmail also likes to complain about certs that are group readable. Either change the permission of the certifcates to 600
, or use the confDONT_BLAME_SENDMAIL
directive.
In any case, the renewal of certs will change the permission back to 644
and sendmail will stop working again. Two options are available:
- ask EFF to change the certbot script to set the correct permission for the private key
- use a
--renew-hook
to do the work
Here’s my renew hook script:
#!/bin/bash
set -e
RESTART=0
LOG="/var/log/letsencrypt/renewal.log"
if [ -e $LOG ]; then
mv $LOG $LOG.save
fi
for domain in $RENEWED_DOMAINS; do
case $domain in
CERTNAME_THAT_YOU_USE_FOR_DOVECOT_AND_SENDMAIL)
RESTART=1
DT=`date +"%Y-%M-%d %H:%M:%S %z"`
echo "$DT [ Certificate ] $domain" >>$LOG
DT=`date +"%Y-%M-%d %H:%M:%S %z"`
echo "$DT [ Restart ] dovecot, sendmail" >>$LOG
# it's the main cert -> set correct permissions, restart dovecot and sendmail
chmod 640 "$RENEWED_LINEAGE/privkey.pem"
systemctl restart dovecot
systemctl restart sendmail
;;
*)
RESTART=1
DT=`date +"%Y-%M-%d %H:%M:%S %z"`
echo "$DT [ Certificate ] $domain" >>$LOG
;;
esac
done
if [ "$RESTART" == "1" ]; then
DT=`date +"%Y-%M-%d %H:%M:%S %z"`
echo "$DT [ Restart ] httpd" >>$LOG
/usr/local/apache/bin/apachectl -k graceful
fi
Ok, I think that’s it. Cheers. Have fun!!!