diff --git a/README.md b/README.md index 955a64c..01b4321 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ docker-postfix ============== +Modified from catatnight/postfix to add virtualhost support + run postfix with smtp authentication (sasldb) in a docker container. TLS and OpenDKIM support are optional. @@ -11,7 +13,7 @@ TLS and OpenDKIM support are optional. 1. Build image ```bash - $ sudo docker pull catatnight/postfix + $ sudo docker pull benxo/postfix ``` ## Usage @@ -19,31 +21,47 @@ TLS and OpenDKIM support are optional. ```bash $ sudo docker run -p 25:25 \ - -e maildomain=mail.example.com -e smtp_user=user:pwd \ - --name postfix -d catatnight/postfix + -e mailhostname=mail.example.com -e maildomain=example.com -e smtp_user=user:pwd \ + --name postfix -d benxo/postfix # Set multiple user credentials: -e smtp_user=user1:pwd1,user2:pwd2,...,userN:pwdN ``` 2. Enable OpenDKIM: save your domain key ```.private``` in ```/path/to/domainkeys``` ```bash $ sudo docker run -p 25:25 \ - -e maildomain=mail.example.com -e smtp_user=user:pwd \ + -e mailhostname=mail.example.com -e maildomain=example.com -e smtp_user=user:pwd \ -v /path/to/domainkeys:/etc/opendkim/domainkeys \ - --name postfix -d catatnight/postfix + --name postfix -d benxo/postfix ``` 3. Enable TLS(587): save your SSL certificates ```.key``` and ```.crt``` to ```/path/to/certs``` ```bash $ sudo docker run -p 587:587 \ - -e maildomain=mail.example.com -e smtp_user=user:pwd \ + -e mailhostname=mail.example.com -e maildomain=example.com -e smtp_user=user:pwd \ -v /path/to/certs:/etc/postfix/certs \ - --name postfix -d catatnight/postfix + --name postfix -d benxo/postfix ``` +4. Full example (where you have symlinked certs from letsencrypt into /etc/postfix/certs): + + ``` bash + docker run -p 25:25 -p 587:587 \ + -e mailhostname=mail.example.com -e maildomain=example.com -e smtp_user=user:pwd \ + -e virtual_domains="mail.example.com test.example.com etc.example.com" \ + -v /path/to/domainkeys:/etc/opendkim/domainkeys \ + -v /etc/postfix/virtual:/etc/postfix/virtual \ + -v /etc/letsencrypt/live:/etc/letsencrypt/live \ + -v /etc/letsencrypt/archive:/etc/letsencrypt/archive \ + -v /etc/postfix/certs:/etc/postfix/certs \ + --name postfix -d benxo/postfix + ``` + + ## Note + Login credential should be set to (`username@mail.example.com`, `password`) in Smtp Client + You can assign the port of MTA on the host machine to one other than 25 ([postfix how-to](http://www.postfix.org/MULTI_INSTANCE_README.html)) + Read the reference below to find out how to generate domain keys and add public key to the domain's DNS records ++ If you want a persistent queue between restarts, you will need to extract an empty spool from /var/spool/postfix inside the container, preserving IDs and permissions! One is provided in postfix-spool.tgz ## Reference + [Postfix SASL Howto](http://www.postfix.org/SASL_README.html) diff --git a/assets/install.sh b/assets/install.sh index 0b2aaff..71d4370 100755 --- a/assets/install.sh +++ b/assets/install.sh @@ -26,18 +26,55 @@ service postfix start tail -f /var/log/mail.log EOF chmod +x /opt/postfix.sh -postconf -e myhostname=$maildomain + +if [[ -z "$mailhostname" ]]; then + mailhostname=$maildomain +fi + +postconf -e myhostname=$mailhostname postconf -F '*/*/chroot = n' +# set up some email security as per https://ssl-tools.net/mailservers/ and +# https://serverfault.com/questions/670348/how-to-force-a-own-set-of-ciphers-in-postfix-2-11#670359 and +# https://blog.tinned-software.net/harden-the-ssl-configuration-of-your-mailserver/ + +postconf -e tls_ssl_options=NO_COMPRESSION + +postconf -e smtp_use_tls=yes +postconf -e smtp_tls_security_level=may +postconf -e "smtp_tls_protocols = !SSLv2, !SSLv3" +postconf -e "smtp_tls_mandatory_protocols = !SSLv2, !SSLv3" +postconf -e "smtp_tls_exclude_ciphers = DES-CBC3-SHA, EDH-RSA-DES-CBC3-SHA, RC2, RC4, aNULL" +postconf -e smtp_tls_loglevel=1 + +postconf -e smtpd_tls_security_level=may +# postconf -e smtpd_tls_auth_only=yes +postconf -e "smtpd_tls_protocols = !SSLv2, !SSLv3" +postconf -e "smtpd_tls_mandatory_protocols = !SSLv2, !SSLv3" +postconf -e smtpd_tls_ciphers=high +postconf -e smtpd_tls_mandatory_ciphers=high +postconf -e "smtpd_tls_exclude_ciphers = DES-CBC3-SHA, EDH-RSA-DES-CBC3-SHA, RC2, RC4, aNULL" +postconf -e smtpd_tls_eecdh_grade=ultra + +# include 172.16/12 for docker +postconf -e "mynetworks=127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128 172.16.0.0/12" + + ############ # SASL SUPPORT FOR CLIENTS # The following options set parameters needed by Postfix to enable # Cyrus-SASL support for authentication of mail clients. ############ # /etc/postfix/main.cf -postconf -e smtpd_sasl_auth_enable=yes + +# this is enabled separately for smpt 25 and submission 587 +#postconf -e smtpd_sasl_auth_enable=yes + postconf -e broken_sasl_auth_clients=yes -postconf -e smtpd_recipient_restrictions=permit_sasl_authenticated,reject_unauth_destination +postconf -e smtpd_sasl_security_options=noanonymous +postconf -e "smtpd_recipient_restrictions=permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination" +postconf -e "smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination" + # smtpd.conf cat >> /etc/postfix/sasl/smtpd.conf <> /etc/opendkim/TrustedHosts <> /etc/opendkim/KeyTable <> /etc/opendkim/SigningTable <> /etc/opendkim/TrustedHosts "*.$d" +done + +for d in $maildomain $virtual_domains; do + private_key_file=$(find /etc/opendkim/domainkeys/$d -iname *.private) + if [[ "$private_key_file" != "" ]]; then + echo >> /etc/opendkim/KeyTable "mail._domainkey.$d $d:mail:$private_key_file" + echo >> /etc/opendkim/SigningTable "*@$d mail._domainkey.$d" + fi +done + chown opendkim:opendkim $(find /etc/opendkim/domainkeys -iname *.private) -chmod 400 $(find /etc/opendkim/domainkeys -iname *.private) \ No newline at end of file +chmod 400 $(find /etc/opendkim/domainkeys -iname *.private) diff --git a/build.sh b/build.sh index d7b5420..ec5cca9 100755 --- a/build.sh +++ b/build.sh @@ -1,3 +1,3 @@ -#!/bin/bash +#!/bin/bash -xe -docker build -t catatnight/postfix . \ No newline at end of file +docker build -t benxo/postfix . diff --git a/postfix-spool.tgz b/postfix-spool.tgz new file mode 100644 index 0000000..fd95d0b Binary files /dev/null and b/postfix-spool.tgz differ