Skip to content
This repository was archived by the owner on Jan 13, 2022. It is now read-only.

Commit 1f1945d

Browse files
authored
Add TLS/SASL support (#2)
* Add support for TLS/SASL * Add CA bundle for TLS * Add a Git ignore configuration * Update README * Update CHANGELOG
1 parent 806f2c1 commit 1f1945d

6 files changed

Lines changed: 51 additions & 5 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
### JetBrains template
2+
.idea/

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).
66

7-
## [v0.1.1] - 2018-08-13
7+
## [v0.1.2] - 2018-10-25
8+
### Added
9+
- TLS support
10+
- SASL Auth support
11+
12+
## [v0.1.1] - 2018-09-24
813
### Added
914
- Project `CHANGELOG.md`, `README.md`, and `LICENSE`
1015
- Initial commit of Docker, build, and configuration

Dockerfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ ENV DEBIAN_FRONTEND noninteractive
88

99
RUN apt-get update \
1010
&& apt-get install --yes \
11+
ca-certificates \
1112
postfix \
1213
rsyslog \
1314
supervisor \

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,10 @@ See `./bin/postfix_init.sh` for configuration parameters that are available via
1010

1111
* Supervisor to manaage `postfix`, `rsyslog`, and log output to `stdout`
1212
* Logging support is added with `rsyslog`
13+
* TLS Support
14+
* Set `POSTFIX_TLS` to `true`
15+
* Default: unset/disabled
16+
* SASL Support
17+
* Set `POSTFIX_SASL_AUTH` to `<SMTP_USERNAME>:<SMTP_PASSWORD>`
18+
* Requires `POSTFIX_RELAYHOST` and `POSTFIX_TLS`
19+
* Default: unset/disabled

bin/postfix_init.sh

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
set -eo pipefail
1919

2020
echo "Configuring postfix with any environment variables that are set"
21+
2122
if [[ -n "${POSTFIX_MYNETWORKS}" ]]; then
2223
echo "Setting custom 'mynetworks' to '${POSTFIX_MYNETWORKS}'"
2324
postconf mynetworks="${POSTFIX_MYNETWORKS}"
@@ -28,7 +29,7 @@ fi
2829

2930
if [[ -n "${POSTFIX_RELAYHOST}" ]]; then
3031
echo "Setting custom 'relayhost' to '${POSTFIX_RELAYHOST}'"
31-
postconf relayhost="${POSTFIX_RELAYHOST}"
32+
postconf relayhost="[${POSTFIX_RELAYHOST}]:${POSTFIX_RELAYHOST_PORT}"
3233
else
3334
echo "Revert 'relayhost' to default (unset)"
3435
postconf -# relayhost
@@ -38,5 +39,35 @@ echo "Disable chroot for the smtp service"
3839
postconf -F smtp/inet/chroot=n
3940
postconf -F smtp/unix/chroot=n
4041

42+
if [[ "${POSTFIX_TLS}" = "true" ]]; then
43+
echo "Configuring TLS"
44+
postconf smtp_tls_CAfile="/etc/ssl/certs/ca-certificates.crt"
45+
postconf smtp_tls_security_level="encrypt"
46+
postconf smtp_use_tls="yes"
47+
fi
48+
49+
echo "Configuring SASL Auth"
50+
if [[ -n "${POSTFIX_SASL_AUTH}" ]]; then
51+
if [[ -z "${POSTFIX_RELAYHOST}" || -z "${POSTFIX_TLS}" ]]; then
52+
echo "Please set 'POSTFIX_RELAYHOST' AND 'POSTFIX_TLS' before attempting to enable SSL auth."
53+
exit 1
54+
fi
55+
56+
postconf smtp_sasl_auth_enable="yes"
57+
postconf smtp_sasl_password_maps="hash:/etc/postfix/sasl_passwd"
58+
postconf smtp_sasl_security_options="noanonymous"
59+
postconf smtp_tls_note_starttls_offer="yes"
60+
61+
# generate the SASL password map
62+
echo "${POSTFIX_RELAYHOST} ${POSTFIX_SASL_AUTH}" > /etc/postfix/sasl_passwd
63+
64+
# generate a .db file and clean it up
65+
postmap hash:/etc/postfix/sasl_passwd && rm /etc/postfix/sasl_passwd
66+
67+
# set permissions
68+
chmod 600 /etc/postfix/sasl_passwd.db
69+
fi
70+
71+
4172
echo "Starting postfix in the foreground"
4273
postfix start-fg

bin/travis-ci/check_tag.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
set -eo pipefail
1919

20-
# echo "Installing shtdlib"
20+
echo "Installing shtdlib"
2121
shtdlib_local_path="/usr/local/bin/shtdlib.sh"
2222
sudo curl -s -L -o "${shtdlib_local_path}" https://github.com/sdelements/shtdlib/raw/master/shtdlib.sh
2323
sudo chmod 775 "${shtdlib_local_path}"
@@ -30,11 +30,11 @@ latest_tag="$(git fetch -t && git tag -l | sort --version-sort | tail -n1)"
3030
color_echo green "Latest Git tag: '${latest_tag}'"
3131

3232
# Get the latest tag from the CHANGELOG
33-
changelog_ver="$(grep -oP '\[v\d\.\d\.\d\]' CHANGELOG.md | tr -d '[]' | sort -nr | head -n1)"
33+
changelog_ver="$(grep -oP '\[v\d+\.\d+\.\d+\]' CHANGELOG.md | tr -d '[]' | sort --version-sort -r | head -n1)"
3434
color_echo green "CHANGELOG version: '${changelog_ver}'"
3535

3636
# Validate version strings
37-
version_pattern='^v\d\.\d\.\d$'
37+
version_pattern='^v\d+\.\d+\.\d+$'
3838
echo "${latest_tag}" | grep -qP ${version_pattern} || ( color_echo red "Invalid tag from repo: '${latest_tag}'" && exit 1 )
3939
echo "${changelog_ver}" | grep -qP ${version_pattern} || ( color_echo red "Invalid tag from CHANGELOG: '${changelog_ver}'" && exit 1 )
4040

0 commit comments

Comments
 (0)