From 60656aec492936d4287132bf523cf1576d07a6ab Mon Sep 17 00:00:00 2001 From: ixeft Date: Tue, 1 May 2018 19:57:31 +0200 Subject: [PATCH] Report sender (#965) * added REPORT_SENDER env variable to the container. * integration test for REPORT_SENDER * added tests for default REPORT_SENDER --- .env.dist | 6 ++++++ Makefile | 2 ++ README.md | 9 +++++++++ docker-compose.elk.yml.dist | 1 + docker-compose.yml.dist | 1 + target/bin/postfix-summary | 4 ++-- target/start-mailserver.sh | 5 ++++- test/tests.bats | 10 ++++++++++ 8 files changed, 35 insertions(+), 3 deletions(-) diff --git a/.env.dist b/.env.dist index 6a064212..8222f4d8 100644 --- a/.env.dist +++ b/.env.dist @@ -107,6 +107,12 @@ POSTFIX_DAGENT= # => Specify the recipient address REPORT_RECIPIENT=0 + +# Change the sending address for mail report +# **empty** => mailserver-report@hostname +# => Specify the report sender (From) address +REPORT_SENDER= + # Changes the interval in which a report is being sent. # **daily** => Send a daily report # weekly => Send a report every week diff --git a/Makefile b/Makefile index b286cd27..d3c48e57 100644 --- a/Makefile +++ b/Makefile @@ -35,6 +35,7 @@ run: -e SPOOF_PROTECTION=1 \ -e ENABLE_SPAMASSASSIN=1 \ -e REPORT_RECIPIENT=user1@localhost.localdomain \ + -e REPORT_SENDER=report1@mail.my-domain.com \ -e SA_TAG=-5.0 \ -e SA_TAG2=2.0 \ -e SA_KILL=3.0 \ @@ -153,6 +154,7 @@ run: -e DOVECOT_TLS=no \ -e DOVECOT_PASS_FILTER="(&(objectClass=PostfixBookMailAccount)(uniqueIdentifier=%n))" \ -e DOVECOT_USER_FILTER="(&(objectClass=PostfixBookMailAccount)(uniqueIdentifier=%n))" \ + -e REPORT_RECIPIENT=1 \ -e ENABLE_SASLAUTHD=1 \ -e SASLAUTHD_MECHANISMS=ldap \ -e SASLAUTHD_LDAP_SERVER=ldap \ diff --git a/README.md b/README.md index d15901ea..72ebe224 100644 --- a/README.md +++ b/README.md @@ -314,12 +314,14 @@ Enabled by ENABLE_POSTFIX_VIRTUAL_TRANSPORT. Specify the final delivery of postf - **empty** => postmaster@domain.com - => Specify the postmaster address + ##### POSTSCREEN_ACTION - **enforce** => Allow other tests to complete. Reject attempts to deliver mail with a 550 SMTP reply, and log the helo/sender/recipient information. Repeat this test the next time the client connects. - drop => Drop the connection immediately with a 521 SMTP reply. Repeat this test the next time the client connects. - ignore => Ignore the failure of this test. Allow other tests to complete. Repeat this test the next time the client connects. This option is useful for testing and collecting statistics without blocking mail. + ##### REPORT_RECIPIENT Enables a report being sent (created by pflogsumm) on a regular basis. @@ -327,6 +329,13 @@ Enabled by ENABLE_POSTFIX_VIRTUAL_TRANSPORT. Specify the final delivery of postf - 1 => Using POSTMASTER_ADDRESS as the recipient - => Specify the recipient address +##### REPORT_SENDER + + Change the sending address for mail report + - **empty** => mailserver-report@hostname + - => Specify the report sender (From) address + + ##### REPORT_INTERVAL changes the interval in which a report is being sent. diff --git a/docker-compose.elk.yml.dist b/docker-compose.elk.yml.dist index e717e927..4613ac86 100644 --- a/docker-compose.elk.yml.dist +++ b/docker-compose.elk.yml.dist @@ -28,6 +28,7 @@ services: - POSTSCREEN_ACTION=${POSTSCREEN_ACTION} - ENABLE_SRS=${ENABLE_SRS} - REPORT_RECIPIENT=${REPORT_RECIPIENT} + - REPORT_SENDER=${REPORT_SENDER} - REPORT_INTERVAL=${REPORT_INTERVAL} - SMTP_ONLY=${SMTP_ONLY} - SSL_TYPE=${SSL_TYPE} diff --git a/docker-compose.yml.dist b/docker-compose.yml.dist index b8156581..a1a17a19 100644 --- a/docker-compose.yml.dist +++ b/docker-compose.yml.dist @@ -25,6 +25,7 @@ services: - POSTMASTER_ADDRESS=${POSTMASTER_ADDRESS} - POSTSCREEN_ACTION=${POSTSCREEN_ACTION} - REPORT_RECIPIENT=${REPORT_RECIPIENT} + - REPORT_SENDER=${REPORT_SENDER} - REPORT_INTERVAL=${REPORT_INTERVAL} - SMTP_ONLY=${SMTP_ONLY} - SSL_TYPE=${SSL_TYPE} diff --git a/target/bin/postfix-summary b/target/bin/postfix-summary index 8bba8e7f..db3138bf 100755 --- a/target/bin/postfix-summary +++ b/target/bin/postfix-summary @@ -2,7 +2,7 @@ HOSTNAME=$1 RECIPIENT=$2 - +SENDER=$3 errex() { echo -e "$@" 1>&2 exit 1 @@ -23,7 +23,7 @@ The $HOSTNAME Mailserver" fi sendmail -t <> /root/.bashrc @@ -1234,7 +1236,8 @@ function _setup_logrotate() { function _setup_mail_summary() { notify 'inf' "Enable postfix summary with recipient $REPORT_RECIPIENT" [ "$REPORT_RECIPIENT" = 1 ] && REPORT_RECIPIENT=$POSTMASTER_ADDRESS - sed -i "s|}| postrotate\n /usr/local/bin/postfix-summary $HOSTNAME $REPORT_RECIPIENT\n endscript\n}\n|" /etc/logrotate.d/maillog + sed -i "s|}| postrotate\n /usr/local/bin/postfix-summary $HOSTNAME \ + $REPORT_RECIPIENT $REPORT_SENDER\n endscript\n}\n|" /etc/logrotate.d/maillog } function _setup_environment() { diff --git a/test/tests.bats b/test/tests.bats index 769afcea..8ea54871 100644 --- a/test/tests.bats +++ b/test/tests.bats @@ -1596,6 +1596,16 @@ load 'test_helper/bats-assert/load' sleep 10 run docker exec mail grep "Subject: Postfix Summary for " /var/mail/localhost.localdomain/user1/new/ -R assert_success + # check sender is the one specified in REPORT_SENDER + run docker exec mail grep "From: report1@mail.my-domain.com" /var/mail/localhost.localdomain/user1/new/ -R + assert_success + # check sender is not the default one. + run docker exec mail grep "From: mailserver-report@mail.my-domain.com" /var/mail/localhost.localdomain/user1/new/ -R + assert_failure + + # checking default sender is correctly set when env variable not defined + run docker exec mail_with_ldap grep "mailserver-report@mail.my-domain.com" /etc/logrotate.d/maillog + assert_success # checking default logrotation setup run docker exec mail_with_ldap grep "daily" /etc/logrotate.d/maillog assert_success