Skip to content

Commit bc23bf4

Browse files
authored
Merge pull request #336 from CrypticCommit/patch-1
Enhance Postfix TLS Configuration (with ECC Support) and Domain Exceptions
2 parents 9f37407 + f249620 commit bc23bf4

File tree

2 files changed

+52
-13
lines changed

2 files changed

+52
-13
lines changed

README.md

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,18 @@ linux/arm64
158158

159159
* `POSTFIX_DEBUG`: Enable debug (default `false`)
160160
* `POSTFIX_MESSAGE_SIZE_LIMIT`: The maximal size in bytes of a message, including envelope information (default `26214400`)
161-
* `POSTFIX_SMTPD_TLS`: Enabling TLS in the Postfix SMTP server (default `false`)
161+
* `POSTFIX_SMTPD_TLS`: Enabling TLS in the Postfix SMTP server (default `false`, possible values: `true`|`may`|`encrypt`|`ask`|`require`, see [Postfix TLS README](https://www.postfix.org/TLS_README.html#client_tls_levels))
162162
* `POSTFIX_SMTPD_TLS_CERT_FILE`: File with the Postfix SMTP server RSA certificate in PEM format
163-
* `POSTFIX_SMTPD_TLS_KEY_FILE`: File with the Postfix SMTP server RSA private key in PEM format
164-
* `POSTFIX_SMTP_TLS`: Enabling TLS in the Postfix SMTP client (default `false`)
163+
* `POSTFIX_SMTPD_TLS_ECCERT_FILE`: File with the Postfix SMTP server RSA private key in PEM format
164+
* `POSTFIX_SMTPD_TLS_ECKEY_FILE`: File with the Postfix SMTP server ECC certificate in PEM format
165+
* `POSTFIX_SMTPD_TLS_KEY_FILE`: File with the Postfix SMTP server ECC private key in PEM format
166+
* `POSTFIX_SMTP_TLS`: Enabling TLS in the Postfix SMTP client (default `false`, possible values: `true`|`may`|`encrypt`|`dane`|`dane-only`|`verify`|`secure`, see [Postfix TLS README](https://www.postfix.org/TLS_README.html#server_vrfy_client))
165167
* `POSTFIX_RELAYHOST`: Default host to send mail to
166168
* `POSTFIX_RELAYHOST_AUTH_ENABLE`: Enable client-side authentication for relayhost (default `false`)
167169
* `POSTFIX_RELAYHOST_USERNAME`: Postfix SMTP Client username for relayhost authentication
168170
* `POSTFIX_RELAYHOST_PASSWORD`: Postfix SMTP Client password for relayhost authentication
169-
* `POSTFIX_RELAYHOST_SSL_ENCRYPTION`: enable SSL encrpytion over SMTP where TLS is not available. (default `false`)
171+
* `POSTFIX_RELAYHOST_SSL_ENCRYPTION`: enable SSL encrpytion over SMTP where TLS is not available. (default `false`, possible values: `true`|`tls_policy`, `tls_policy` uses the policy defined by `POSTFIX_SMTP_TLS`)
172+
* `POSTFIX_SMTP_TLS_DOMAINS_EXCEPTIONS`: Comma-separated list of domains with TLS exceptions (`TLS policy`: `may`)
170173
* `POSTFIX_SPAMAUS_DQS_KEY`: Personal key for [Spamhaus DQS](#spamhaus-dqs-configuration)
171174

172175
> [!NOTE]

rootfs/etc/cont-init.d/15-config-postfix.sh

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,15 +120,14 @@ milter_mail_macros = i {mail_addr} {client_addr} {client_name} {auth_authen}
120120
EOL
121121
fi
122122

123-
if [ "$POSTFIX_SMTPD_TLS" = "true" ]; then
123+
if [[ "$POSTFIX_SMTPD_TLS" =~ ^(true|may|encrypt|ask|require)$ ]]; then
124124
echo "Setting Postfix smtpd TLS configuration"
125125
cat >>/etc/postfix/main.cf <<EOL
126126
127127
# SMTPD
128128
smtpd_use_tls=yes
129129
smtpd_tls_session_cache_database = lmdb:\${data_directory}/smtpd_scache
130130
smtpd_tls_CApath = /etc/ssl/certs
131-
smtpd_tls_security_level = may
132131
smtpd_tls_protocols = !SSLv2, !SSLv3, !TLSv1
133132
smtpd_tls_loglevel = 1
134133
smtpd_tls_session_cache_database = lmdb:\${data_directory}/smtpd_scache
@@ -148,9 +147,26 @@ EOL
148147
if [ -n "$POSTFIX_SMTPD_TLS_KEY_FILE" ]; then
149148
echo "smtpd_tls_key_file=${POSTFIX_SMTPD_TLS_KEY_FILE}" >>/etc/postfix/main.cf
150149
fi
150+
if [ -n "$POSTFIX_SMTPD_TLS_ECCERT_FILE" ]; then
151+
echo "smtpd_tls_eccert_file=${POSTFIX_SMTPD_TLS_ECCERT_FILE}" >>/etc/postfix/main.cf
152+
fi
153+
if [ -n "$POSTFIX_SMTPD_TLS_ECKEY_FILE" ]; then
154+
echo "smtpd_tls_eckey_file=${POSTFIX_SMTPD_TLS_ECKEY_FILE}" >>/etc/postfix/main.cf
155+
fi
156+
157+
# TLS policy for smtpd
158+
if [[ "$POSTFIX_SMTPD_TLS" =~ ^(true|may)$ ]]; then
159+
echo "smtpd_tls_security_level = may" >>/etc/postfix/main.cf # Default value if true
160+
else
161+
echo "smtpd_tls_security_level = encrypt" >>/etc/postfix/main.cf
162+
fi
163+
164+
# Additional options for client certificates
165+
[[ "$POSTFIX_SMTPD_TLS" == "ask" ]] && echo "smtpd_tls_ask_ccert = yes" >>/etc/postfix/main.cf
166+
[[ "$POSTFIX_SMTPD_TLS" == "require" ]] && echo "smtpd_tls_req_ccert = yes" >>/etc/postfix/main.cf
151167
fi
152168

153-
if [ "$POSTFIX_SMTP_TLS" = "true" ]; then
169+
if [[ "$POSTFIX_SMTP_TLS" =~ ^(true|may|encrypt|dane|dane-only|verify|secure)$ ]]; then
154170
echo "Setting Postfix smtp TLS configuration"
155171
cat >>/etc/postfix/main.cf <<EOL
156172
@@ -167,16 +183,36 @@ smtp_tls_mandatory_exclude_ciphers = MD5, DES, ADH, RC4, PSD, SRP, 3DES, eNULL,
167183
smtp_tls_exclude_ciphers = MD5, DES, ADH, RC4, PSD, SRP, 3DES, eNULL, aNULL
168184
EOL
169185

170-
if [ "$POSTFIX_RELAYHOST_SSL_ENCRYPTION" = "true" ]; then
186+
# TLS policy for smtp
187+
if [[ "$POSTFIX_SMTP_TLS" == "true" ]]; then
188+
if [ "$POSTFIX_RELAYHOST_SSL_ENCRYPTION" = "true" ]; then
189+
echo "smtp_tls_security_level = encrypt" >>/etc/postfix/main.cf # Backwards compatibility
190+
else
191+
echo "smtp_tls_security_level = may" >>/etc/postfix/main.cf # Default value if true
192+
fi
193+
else
194+
echo "smtp_tls_security_level = $POSTFIX_SMTP_TLS" >>/etc/postfix/main.cf
195+
fi
196+
197+
# DNS support for DANE
198+
if [[ "$POSTFIX_SMTP_TLS" =~ ^(dane|dane-only)$ ]]; then
199+
echo "smtp_dns_support_level = dnssec" >>/etc/postfix/main.cf
200+
fi
201+
202+
if [[ "$POSTFIX_RELAYHOST_SSL_ENCRYPTION" =~ ^(true|tls_policy)$ ]]; then
171203
cat >>/etc/postfix/main.cf <<EOL
172204
smtp_tls_wrappermode = yes
173-
smtp_tls_security_level = encrypt
174-
EOL
175-
else
176-
cat >>/etc/postfix/main.cf <<EOL
177-
smtp_tls_security_level = may
178205
EOL
179206
fi
207+
208+
# TLS "may" Exception for specific domains
209+
if [ -n "$POSTFIX_SMTP_TLS_DOMAINS_EXCEPTIONS" ]; then
210+
IFS=',' read -r -a domains <<< "$POSTFIX_SMTP_TLS_DOMAINS_EXCEPTIONS"
211+
for domain in "${domains[@]}"; do
212+
echo "$domain may" >>/etc/postfix/tls_policy
213+
done
214+
echo "smtp_tls_policy_maps = hash:/etc/postfix/tls_policy" >>/etc/postfix/main.cf
215+
fi
180216
fi
181217

182218
if [ "$POSTFIX_RELAYHOST_AUTH_ENABLE" = "true" ]; then

0 commit comments

Comments
 (0)