diff --git a/Dockerfile b/Dockerfile index 7f63f0e5afb33f858a75eae34f2046aea214a143..15a8a7b6e397b7bdfb966c3ac821a934fd7dfda9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -38,8 +38,9 @@ RUN \ COPY ./conf/etc/supervisord.conf /etc/supervisord.conf COPY ./conf/etc/entrypoint /etc/entrypoint COPY ./conf/etc/aliases /etc/aliases +COPY ./conf/etc/postfix/master.cf /etc/postfix -EXPOSE 25/tcp +EXPOSE 25 587 ENTRYPOINT ["/etc/entrypoint"] diff --git a/Makefile b/Makefile index 21e04a154f2c99c54ed71ccb87de765bf6477020..84d7ed012dc1bba51aaf59111ccc1b9b1b3637bc 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,9 @@ config ?= conf/faas-smtp.cnf include $(config) export $(shell sed 's/=.*//' $(config)) +credentials ?= conf/credentials/faas-smtp-default.cnf +include $(credentials) +export $(shell sed 's/=.*//' $(credentials)) .DEFAULT_GOAL := help @@ -13,10 +16,10 @@ build-nc: # build container without caching docker build --no-cache -t ${FAAS_SMTP_IMAGE} --build-arg FAAS_SMTP_NAME=${FAAS_SMTP_NAME} --build-arg FAAS_SMTP_IMAGE=${FAAS_SMTP_IMAGE} --build-arg FAAS_SMTP_VERSION=${FAAS_SMTP_VERSION} . run: # run container - docker run -i -t --detach --rm --env-file=$(config) -p=${FAAS_SMTP_PORT}:25 --name="${FAAS_SMTP_NAME}" ${FAAS_SMTP_IMAGE} + docker run -i -t --detach --rm --env-file=$(config) --env-file=$(credentials) -p=${FAAS_SMTP_PUBLIC_PORT}:587 --name="${FAAS_SMTP_NAME}" ${FAAS_SMTP_IMAGE} run-nd: # run container in no-deamon mode - docker run -i -t --rm --env-file=$(config) -p=${FAAS_SMTP_PORT}:25 --name="${FAAS_SMTP_NAME}" ${FAAS_SMTP_IMAGE} + docker run -i -t --rm --env-file=$(config) --env-file=$(credentials) -p=${FAAS_SMTP_PUBLIC_PORT}:587 --name="${FAAS_SMTP_NAME}" ${FAAS_SMTP_IMAGE} up: build run # build and run container diff --git a/conf/.gitignore b/conf/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..016744a706513154aab47cb9b0885c82c3639ec0 --- /dev/null +++ b/conf/.gitignore @@ -0,0 +1 @@ +/faas-smtp-production.cnf diff --git a/conf/credentials/.gitignore b/conf/credentials/.gitignore new file mode 100644 index 0000000000000000000000000000000000000000..016744a706513154aab47cb9b0885c82c3639ec0 --- /dev/null +++ b/conf/credentials/.gitignore @@ -0,0 +1 @@ +/faas-smtp-production.cnf diff --git a/conf/credentials/.gitkeep b/conf/credentials/.gitkeep new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/conf/credentials/faas-smtp-default.cnf b/conf/credentials/faas-smtp-default.cnf new file mode 100644 index 0000000000000000000000000000000000000000..712bd38ad877ea5e90019c4f27db16fde06172f1 --- /dev/null +++ b/conf/credentials/faas-smtp-default.cnf @@ -0,0 +1,2 @@ +FAAS_SMTP_RELAY_SMTP_USERNAME=changeme +FAAS_SMTP_RELAY_SMTP_PASSWORD=changeme diff --git a/conf/etc/entrypoint b/conf/etc/entrypoint index 8aa439c7487d49ca4c8d12ac623fa31a79f88555..c9405338941b450be2036f30835f9d9e930150cc 100755 --- a/conf/etc/entrypoint +++ b/conf/etc/entrypoint @@ -13,7 +13,6 @@ newaliases sed -i '/imklog/s/^/#/' /etc/rsyslog.conf - function update_postfix_config_value() { local key=${1} local value=${2} @@ -21,10 +20,11 @@ function update_postfix_config_value() { [ "${key}" == "" ] && echo "ERROR: Key is not set" && exit 1 [ "${value}" == "" ] && echo "ERROR:value is not set" && exit 1 - echo "Setting configuration option ${key} with value: ${value}" + #echo "Setting configuration option ${key} with value: ${value}" postconf -e "${key} = ${value}" } + [ -z "${FAAS_SMTP_MYHOSTNAME}" ] && echo "FAAS_SMTP_MYHOSTNAME is not set" && exit 1 [ -z "${FAAS_SMTP_INET_INTERFACES}" ] && echo "FAAS_SMTP_INET_INTERFACES is not set" && exit 1 [ -z "${FAAS_SMTP_INET_PROTOCOLS}" ] && echo "FAAS_SMTP_INET_PROTOCOLS is not set" && exit 1 @@ -34,6 +34,14 @@ update_postfix_config_value "inet_interfaces" ${FAAS_SMTP_INET_INTERFACES} update_postfix_config_value "inet_protocols" ${FAAS_SMTP_INET_PROTOCOLS} update_postfix_config_value "mynetworks" "${FAAS_SMTP_POSTFIX_MYNETWORKS}" +if [ "${FAAS_SMTP_RELAY}" = "yes" ]; then + echo "configure FAAS_SMTP_RELAY" + update_postfix_config_value "smtp_sasl_auth_enable" "${FAAS_SMTP_RELAY_SMTP_SASL_AUTH_ENABLE}" + update_postfix_config_value "smtp_sasl_security_options" "${FAAS_SMTP_RELAY_SMTP_SASL_SECURITY_OPTIONS}" + update_postfix_config_value "smtp_tls_security_level" "${FAAS_SMTP_RELAY_SMTP_TLS_SECURITY_LEVEL}" + update_postfix_config_value "relayhost" "${FAAS_SMTP_RELAY_SMTP_RELAYHOST}:${FAAS_SMTP_RELAY_SMTP_RELAYPORT}" + update_postfix_config_value "smtp_sasl_password_maps" "static:${FAAS_SMTP_RELAY_SMTP_USERNAME}:${FAAS_SMTP_RELAY_SMTP_PASSWORD}" +fi rm -f /var/spool/postfix/pid/master.pid rm -f /run/rsyslogd.pid diff --git a/conf/etc/postfix/master.cf b/conf/etc/postfix/master.cf new file mode 100644 index 0000000000000000000000000000000000000000..aca0c6ad2ca10f728e795d76f8a79c284fe7c776 --- /dev/null +++ b/conf/etc/postfix/master.cf @@ -0,0 +1,127 @@ +# +# Postfix master process configuration file. For details on the format +# of the file, see the master(5) manual page (command: "man 5 master" or +# on-line: http://www.postfix.org/master.5.html). +# +# Do not forget to execute "postfix reload" after editing this file. +# +# ========================================================================== +# service type private unpriv chroot wakeup maxproc command + args +# (yes) (yes) (no) (never) (100) +# ========================================================================== +smtp inet n - n - - smtpd +#smtp inet n - y - 1 postscreen +#smtpd pass - - y - - smtpd +#dnsblog unix - - y - 0 dnsblog +#tlsproxy unix - - y - 0 tlsproxy +submission inet n - n - - smtpd +# -o syslog_name=postfix/submission +# -o smtpd_tls_security_level=encrypt +# -o smtpd_sasl_auth_enable=yes +# -o smtpd_tls_auth_only=yes +# -o smtpd_reject_unlisted_recipient=no +# -o smtpd_client_restrictions=$mua_client_restrictions +# -o smtpd_helo_restrictions=$mua_helo_restrictions +# -o smtpd_sender_restrictions=$mua_sender_restrictions +# -o smtpd_recipient_restrictions= +# -o smtpd_relay_restrictions=permit_sasl_authenticated,reject +# -o milter_macro_daemon_name=ORIGINATING +#smtps inet n - y - - smtpd +# -o syslog_name=postfix/smtps +# -o smtpd_tls_wrappermode=yes +# -o smtpd_sasl_auth_enable=yes +# -o smtpd_reject_unlisted_recipient=no +# -o smtpd_client_restrictions=$mua_client_restrictions +# -o smtpd_helo_restrictions=$mua_helo_restrictions +# -o smtpd_sender_restrictions=$mua_sender_restrictions +# -o smtpd_recipient_restrictions= +# -o smtpd_relay_restrictions=permit_sasl_authenticated,reject +# -o milter_macro_daemon_name=ORIGINATING +#628 inet n - y - - qmqpd +pickup unix n - y 60 1 pickup +cleanup unix n - y - 0 cleanup +qmgr unix n - n 300 1 qmgr +#qmgr unix n - n 300 1 oqmgr +tlsmgr unix - - y 1000? 1 tlsmgr +rewrite unix - - y - - trivial-rewrite +bounce unix - - y - 0 bounce +defer unix - - y - 0 bounce +trace unix - - y - 0 bounce +verify unix - - y - 1 verify +flush unix n - y 1000? 0 flush +proxymap unix - - n - - proxymap +proxywrite unix - - n - 1 proxymap +smtp unix - - y - - smtp +relay unix - - y - - smtp + -o syslog_name=postfix/$service_name +# -o smtp_helo_timeout=5 -o smtp_connect_timeout=5 +showq unix n - y - - showq +error unix - - y - - error +retry unix - - y - - error +discard unix - - y - - discard +local unix - n n - - local +virtual unix - n n - - virtual +lmtp unix - - y - - lmtp +anvil unix - - y - 1 anvil +scache unix - - y - 1 scache +postlog unix-dgram n - n - 1 postlogd +# +# ==================================================================== +# Interfaces to non-Postfix software. Be sure to examine the manual +# pages of the non-Postfix software to find out what options it wants. +# +# Many of the following services use the Postfix pipe(8) delivery +# agent. See the pipe(8) man page for information about ${recipient} +# and other message envelope options. +# ==================================================================== +# +# maildrop. See the Postfix MAILDROP_README file for details. +# Also specify in main.cf: maildrop_destination_recipient_limit=1 +# +maildrop unix - n n - - pipe + flags=DRhu user=vmail argv=/usr/bin/maildrop -d ${recipient} +# +# ==================================================================== +# +# Recent Cyrus versions can use the existing "lmtp" master.cf entry. +# +# Specify in cyrus.conf: +# lmtp cmd="lmtpd -a" listen="localhost:lmtp" proto=tcp4 +# +# Specify in main.cf one or more of the following: +# mailbox_transport = lmtp:inet:localhost +# virtual_transport = lmtp:inet:localhost +# +# ==================================================================== +# +# Cyrus 2.1.5 (Amos Gouaux) +# Also specify in main.cf: cyrus_destination_recipient_limit=1 +# +#cyrus unix - n n - - pipe +# user=cyrus argv=/cyrus/bin/deliver -e -r ${sender} -m ${extension} ${user} +# +# ==================================================================== +# Old example of delivery via Cyrus. +# +#old-cyrus unix - n n - - pipe +# flags=R user=cyrus argv=/cyrus/bin/deliver -e -m ${extension} ${user} +# +# ==================================================================== +# +# See the Postfix UUCP_README file for configuration details. +# +uucp unix - n n - - pipe + flags=Fqhu user=uucp argv=uux -r -n -z -a$sender - $nexthop!rmail ($recipient) +# +# Other external delivery methods. +# +ifmail unix - n n - - pipe + flags=F user=ftn argv=/usr/lib/ifmail/ifmail -r $nexthop ($recipient) +bsmtp unix - n n - - pipe + flags=Fq. user=bsmtp argv=/usr/lib/bsmtp/bsmtp -t$nexthop -f$sender $recipient +scalemail-backend unix - n n - 2 pipe + flags=R user=scalemail argv=/usr/lib/scalemail/bin/scalemail-store ${nexthop} ${user} ${extension} +mailman unix - n n - - pipe + flags=FR user=list argv=/usr/lib/mailman/bin/postfix-to-mailman.py + ${nexthop} ${user} + diff --git a/conf/faas-smtp.cnf b/conf/faas-smtp.cnf index 5a680d795cd66a2234bb61d09a49a2071d90b18c..8a86cb09131f69fbb5a3b1ad81d95d7626238dcd 100644 --- a/conf/faas-smtp.cnf +++ b/conf/faas-smtp.cnf @@ -3,11 +3,18 @@ FAAS_SMTP_NAME=faas-smtp FAAS_SMTP_VERSION=1.0-SNAPSHOT FAAS_SMTP_IMAGE=${FAAS_SMTP_REPO}/${FAAS_SMTP_NAME}:${FAAS_SMTP_VERSION} -FAAS_SMTP_MYHOSTNAME=test.faas.geant.net FAAS_SMTP_INET_INTERFACES=all FAAS_SMTP_INET_PROTOCOLS=all +FAAS_SMTP_POSTFIX_MYNETWORKS=127.0.0.1/32 192.168.0.0/16 172.16.0.0/12 172.17.0.0/16 10.0.0.0/8 -FAAS_SMTP_PORT=9025 +FAAS_SMTP_PUBLIC_PORT=9025 -FAAS_SMTP_ROOT_ALIASES_LIST=janny@man.poznan.pl -FAAS_SMTP_POSTFIX_MYNETWORKS=127.0.0.1/32 192.168.0.0/16 172.16.0.0/12 172.17.0.0/16 10.0.0.0/8 \ No newline at end of file +FAAS_SMTP_MYHOSTNAME=changeme +FAAS_SMTP_ROOT_ALIASES_LIST=changeme@changeme + +FAAS_SMTP_RELAY=[no|yes] +FAAS_SMTP_RELAY_SMTP_SASL_AUTH_ENABLE=yes +FAAS_SMTP_RELAY_SMTP_SASL_SECURITY_OPTIONS=noanonymous +FAAS_SMTP_RELAY_SMTP_TLS_SECURITY_LEVEL=encrypt +FAAS_SMTP_RELAY_SMTP_RELAYHOST= +FAAS_SMTP_RELAY_SMTP_RELAYPORT= diff --git a/test/send.pl b/test/send.pl index d148effc9e59b1cb0759101fbc81c38c8a130e4b..b499c38612e0aa50b1bea40e6f1e4abff0368337 100644 --- a/test/send.pl +++ b/test/send.pl @@ -11,7 +11,7 @@ my $smtppassword = ''; #my $to = 'janny@man.poznan.pl'; my $to = 'dariusz.janny@gmail.com'; -my $from = 'root@test.faas.geant.net'; +my $from = 'janny@man.poznan.pl'; my $subject = 'subject no 2'; my $smtp = Net::SMTP->new($smtpserver, Port=>$smtpport, Timeout => 10, Debug => 1);