Compare commits

..

No commits in common. "e7923cf4cb56ac698da44fb9afab8f08bd21e47c" and "702d3529888fdf3b5c6cf49445036dfdc15362e1" have entirely different histories.

3 changed files with 72 additions and 91 deletions

View File

@ -1,5 +1,5 @@
#
# simple postfix smtp relay
# simple postfix smarthost smtp relay
#
FROM alpine:3.13
@ -9,13 +9,13 @@ LABEL author="Asif Bacchus <asif@bacchus.cloud>"
LABEL maintainer="Asif Bacchus <asif@bacchus.cloud>"
LABEL org.label-schema.schema-version="1.0"
LABEL org.label-schema.docker.cmd=""
LABEL org.label-schema.description="Simple postfix smtp mail relay on Alpine."
LABEL org.label-schema.url="https://git.asifbacchus.app/ab-docker/postfix-smtp-relay"
LABEL org.label-schema.usage="https://git.asifbacchus.app/ab-docker/postfix-smtp-relay"
LABEL org.label-schema.vcs-url="https://git.asifbacchus.app/ab-docker/postfix-smtp-relay.git"
LABEL org.label-schema.description="Simple postfix smarthost smtp mail relay on Alpine Linux."
LABEL org.label-schema.url=""
LABEL org.label-schema.usage=""
LABEL org.label-schema.vcs-url=""
# install packages and clean-up
RUN apk --no-cache add \
# install mSMTP
RUN apk --no-cache \
ca-certificates \
postfix \
bind-tools \
@ -23,8 +23,8 @@ RUN apk --no-cache add \
# set environment variables
ENV TZ=Etc/UTC
ENV LOCAL_HOSTNAME=""
ENV LOCAL_DOMAINNAME=""
ENV LOCAL_HOSTNAME=${HOSTNAME}
ENV LOCAL_DOMAINNAME=${HOSTNAME#*.}
ENV LOCAL_ENCRYPTION=false
ENV SMARTHOST=""
ENV SMARTHOST_PORT=587
@ -41,8 +41,8 @@ ENTRYPOINT [ "/usr/local/bin/entrypoint.sh" ]
CMD [ "/usr/local/sbin/postfix", "start-fg" ]
# set parameters, vendor, version and build-date labels
LABEL org.label-schema.docker.params="TZ=Etc/UTC, HOSTNAME=(container hostname), DOMAINNAME=(derived from hostname), LOCAL_ENCRYPTION=false|optional|true, SMARTHOST=..., SMARTHOST_PORT=587, SMARTHOST_USERNAME=..., SMARTHOST_PASSWORD=..., SMARTHOST_ENCRYPTION=optional|false|true"
LABEL org.label-schema.docker.params="TZ=Etc/UTC, HOSTNAME=HOSTNAME, DOMAINNAME=(derived from hostname), LOCAL_ENCRYPTION=false, SMARTHOST, SMARTHOST_PORT=587, SMARTHOST_USERNAME, SMARTHOST_PASSWORD, SMARTHOST_ENCRYPTION='OPTIONAL'"
LABEL org.label-schema.vendor="Alpine 3.13, Postfix 3.5.10-r0"
LABEL org.label-schema.version="0.5"
LABEL org.label-schema.version="0.1"
ARG BUILD_DATE
LABEL org.label-schema.build-date=${BUILD_DATE}

View File

@ -8,89 +8,70 @@ convertCase () {
printf "%s" "$1" | tr "[:lower:]" "[:upper:]"
}
if [ -f "/etc/postfix/main.cf.override" ]; then
# use provided configuration file
printf "\nAppending provided MAIN configuration... "
cat /etc/postfix/main.cf.override >> /etc/postfix/main.cf
\rm -f /tmp/main.cf.insert
else
# process auto-setup
printf "\nVerifying environment variables... "
printf "\nVerifying environment variables... "
# check for missing environment variable values
if [ -z "$SMARTHOST" ]; then
printf "\nYou must specify the hostname or IP address of a smarthost where mail should be relayed.\n\n"
exit 1
fi
if [ -z "$SMARTHOST_USERNAME" ]; then
printf "\nYou must provide a username for smarthost authentication.\n\n"
exit 1
fi
if [ -z "$SMARTHOST_PASSWORD" ]; then
printf "\nYou must provide a password for smarthost authentication.\n\n"
exit 1
fi
# set failsafes
[ -z "$SMARTHOST_PORT" ] && SMARTHOST_PORT=587
[ -z "$LOCAL_HOSTNAME" ] && LOCAL_HOSTNAME="$(uname -n)"
[ -z "$LOCAL_DOMAINNAME" ] && LOCAL_DOMAINNAME="${LOCAL_HOSTNAME#*.}"
printf "done\n"
printf "updating configuration files... "
# update main.cf
sed -i "s/{LOCAL_HOSTNAME}/${LOCAL_HOSTNAME}/" /tmp/main.cf.insert
sed -i "s/{LOCAL_DOMAINNAME}/${LOCAL_DOMAINNAME}/" /tmp/main.cf.insert
sed -i "s/{SMARTHOST}/${SMARTHOST}/" /tmp/main.cf.insert
sed -i "s/{SMARTHOST_PORT}/${SMARTHOST_PORT}/" /tmp/main.cf.insert
sed -i "s/{SMARTHOST_USERNAME}/${SMARTHOST_USERNAME}/" /tmp/main.cf.insert
sed -i "s/{SMARTHOST_PASSWORD}/${SMARTHOST_PASSWORD}/" /tmp/main.cf.insert
LOCAL_ENCRYPTION="$(convertCase "$LOCAL_ENCRYPTION")"
case "$LOCAL_ENCRYPTION" in
OPT*)
sed -i 's/{LOCAL_ENCRYPTION}/may/' /tmp/main.cf.insert
sed -i 's/#smtpd_/smtpd_/g' /tmp/main.cf.insert
;;
TRUE)
sed -i 's/{LOCAL_ENCRYPTION}/encrypt/' /tmp/main.cf.insert
sed -i 's/#smtpd_/smtpd_/g' /tmp/main.cf.insert
;;
*)
sed -i 's/{LOCAL_ENCRYPTION}//' /tmp/main.cf.insert
;;
esac
SMARTHOST_ENCRYPTION="$(convertCase "$SMARTHOST_ENCRYPTION")"
case "$SMARTHOST_ENCRYPTION" in
OPT*)
sed -i 's/{SMARTHOST_ENCRYPTION}/may/' /tmp/main.cf.insert
;;
TRUE)
sed -i 's/{SMARTHOST_ENCRYPTION}/secure/' /tmp/main.cf.insert
;;
*)
sed -i 's/{SMARTHOST_ENCRYPTION}/none/' /tmp/main.cf.insert
;;
esac
# append configuration and remove temp file
cat /tmp/main.cf.insert >> /etc/postfix/main.cf
\rm -f /tmp/main.cf.insert
# check for missing environment variable values
if [ -z "$SMARTHOST" ]; then
printf "\nYou must specify the hostname or IP address of a smarthost where mail should be relayed.\n\n"
fi
printf "done\n"
if [ -f "/etc/postfix/master.cf.override" ]; then
# use provided configuration file
printf "\nUsing provided MASTER configuration... "
\cp --force /etc/postfix/master.cf.override /etc/postfix/master.cf
else
# update master.cf
sed -i 's/#tlsproxy/tlsproxy/' /etc/postfix/master.cf
if [ -z "$SMARTHOST_USERNAME" ]; then
printf "\nYou must provide a username for smarthost authentication.\n\n"
fi
if [ -z "$SMARTHOST_PASSWORD" ]; then
printf "\nYou must provide a password for smarthost authentication.\n\n"
fi
printf "done\n"
# set failsafes
[ -z "$SMARTHOST_PORT" ] && SMARTHOST_PORT=587
[ -z "$LOCAL_HOSTNAME" ] && LOCAL_HOSTNAME="smarthost"
[ -z "$LOCAL_DOMAINNAME" ] && LOCAL_DOMAINNAME="smarthost"
printf "done\n"
printf "updating configuration files... "
# update main.cf
sed -i "s/{LOCAL_HOSTNAME}/${LOCAL_HOSTNAME}/" /tmp/main.cf.insert
sed -i "s/{LOCAL_DOMAINNAME}/${LOCAL_DOMAINNAME}/" /tmp/main.cf.insert
sed -i "s/{SMARTHOST}/${SMARTHOST}/" /tmp/main.cf.insert
sed -i "s/{SMARTHOST_PORT}/${SMARTHOST_PORT}/" /tmp/main.cf.insert
sed -i "s/{SMARTHOST_USERNAME}/${SMARTHOST_USERNAME}/" /tmp/main.cf.insert
sed -i "s/{SMARTHOST_PASSWORD}/${SMARTHOST_PASSWORD}/" /tmp/main.cf.insert
LOCAL_ENCRYPTION="$(convertCase "$LOCAL_ENCRYPTION")"
case "$LOCAL_ENCRYPTION" in
OPT*)
sed -i 's/{LOCAL_ENCRYPTION}/may/' /tmp/main.cf.insert
sed -i 's/#smtpd_/smtpd_/g' /tmp/main.cf.insert
;;
TRUE)
sed -i 's/{LOCAL_ENCRYPTION}/encrypt/' /tmp/main.cf.insert
sed -i 's/#smtpd_/smtpd_/g' /tmp/main.cf.insert
;;
*)
sed -i 's/{LOCAL_ENCRYPTION}//' /tmp/main.cf.insert
;;
esac
SMARTHOST_ENCRYPTION="$(convertCase "$SMARTHOST_ENCRYPTION")"
case "$SMARTHOST_ENCRYPTION" in
OPT*)
sed -i 's/{SMARTHOST_ENCRYPTION}/may/' /tmp/main.cf.insert
;;
TRUE)
sed -i 's/{SMARTHOST_ENCRYPTION}/secure/' /tmp/main.cf.insert
;;
*)
sed -i 's/{SMARTHOST_ENCRYPTION}/none/' /tmp/main.cf.insert
;;
esac
cat /tmp/main.cf.insert >> /etc/postfix/main.cf
rm -f /tmp/main.cf.insert
# update master.cf
sed -i 's/#tlsproxy/tlsproxy/' /etc/postfix/master.cf
printf "done\n"
printf "container setup complete!\n"
# run CMD passed to this container

View File

@ -13,7 +13,7 @@ relayhost = [{SMARTHOST}]:{SMARTHOST_PORT}
#smtpd_tls_chain_files = /certs/privkey.pem, /certs/fullchain.pem
#smtpd_tls_mandatory_ciphers = high
#smtpd_tls_mandatory_exclude_ciphers = aNULL, MD5
#smptd_tls_mandatory_exclude_ciphers = aNULL, MD5
#smtpd_tls_mandatory_protocols = >=TLSv1.2
#smtpd_tls_security_level = {LOCAL_ENCRYPTION}