2020-09-05 14:19:12 +00:00
|
|
|
SHELL = /bin/bash
|
|
|
|
|
2016-04-21 10:15:34 +00:00
|
|
|
NAME = tvial/docker-mailserver:testing
|
2019-10-23 09:22:23 +00:00
|
|
|
VCS_REF := $(shell git rev-parse --short HEAD)
|
2020-01-12 11:09:29 +00:00
|
|
|
VCS_VERSION := $(shell git describe --tags --contains --always)
|
2015-10-18 19:02:46 +00:00
|
|
|
|
2020-09-05 14:19:12 +00:00
|
|
|
SLEEP = 15s
|
|
|
|
|
2019-10-23 09:22:23 +00:00
|
|
|
all: build backup generate-accounts run generate-accounts-after-run fixtures tests clean
|
2018-03-21 18:55:41 +00:00
|
|
|
no-build: backup generate-accounts run generate-accounts-after-run fixtures tests clean
|
2020-09-05 14:19:12 +00:00
|
|
|
complete_test: lint build generate-accounts run generate-accounts-after-run fixtures tests
|
2016-04-13 19:43:25 +00:00
|
|
|
|
2015-10-18 19:02:46 +00:00
|
|
|
build:
|
2019-10-23 09:22:23 +00:00
|
|
|
docker build \
|
|
|
|
--build-arg VCS_REF=$(VCS_REF) \
|
|
|
|
--build-arg VCS_VERSION=$(VCS_VERSION) \
|
|
|
|
-t $(NAME) .
|
2015-10-18 19:02:46 +00:00
|
|
|
|
2018-03-21 18:55:41 +00:00
|
|
|
backup:
|
2020-09-05 14:19:12 +00:00
|
|
|
# if backup directories exist, clean hasn't been called, therefore
|
|
|
|
# we shouldn't overwrite it. It still contains the original content.
|
2020-10-21 16:16:32 +00:00
|
|
|
@ if [[ ! -d config.bak ]]; then cp -rp config config.bak; fi
|
|
|
|
@ if [[ ! -d testconfig.bak ]]; then cp -rp test/config testconfig.bak; fi
|
2018-03-21 18:55:41 +00:00
|
|
|
|
2016-04-25 14:00:39 +00:00
|
|
|
generate-accounts:
|
2020-09-05 14:19:12 +00:00
|
|
|
@ docker run --rm -e MAIL_USER=user1@localhost.localdomain -e MAIL_PASS=mypassword -t $(NAME) /bin/sh -c 'echo "$$MAIL_USER|$$(doveadm pw -s SHA512-CRYPT -u $$MAIL_USER -p $$MAIL_PASS)"' > test/config/postfix-accounts.cf
|
|
|
|
@ docker run --rm -e MAIL_USER=user2@otherdomain.tld -e MAIL_PASS=mypassword -t $(NAME) /bin/sh -c 'echo "$$MAIL_USER|$$(doveadm pw -s SHA512-CRYPT -u $$MAIL_USER -p $$MAIL_PASS)"' >> test/config/postfix-accounts.cf
|
|
|
|
@ echo "# this is a test comment, please don't delete me :'(" >> test/config/postfix-accounts.cf
|
|
|
|
@ echo " # this is also a test comment, :O" >> test/config/postfix-accounts.cf
|
2016-08-21 20:13:13 +00:00
|
|
|
|
2015-10-18 19:02:46 +00:00
|
|
|
run:
|
2020-09-05 14:19:12 +00:00
|
|
|
# run containers
|
|
|
|
-@ echo "Sleeping $(SLEEP) after each container"
|
2019-09-07 18:48:00 +00:00
|
|
|
docker run --rm -d --name mail \
|
2016-04-11 22:04:33 +00:00
|
|
|
-v "`pwd`/test/config":/tmp/docker-mailserver \
|
2019-07-30 11:16:23 +00:00
|
|
|
-v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \
|
2016-05-24 06:21:18 +00:00
|
|
|
-v "`pwd`/test/onedir":/var/mail-state \
|
2019-11-08 01:22:33 +00:00
|
|
|
-v "`pwd`/test/config/user-patches/user-patches.sh":/tmp/docker-mailserver/user-patches.sh \
|
2016-12-25 21:54:37 +00:00
|
|
|
-e ENABLE_CLAMAV=1 \
|
2018-03-07 18:33:43 +00:00
|
|
|
-e SPOOF_PROTECTION=1 \
|
2016-12-25 21:54:37 +00:00
|
|
|
-e ENABLE_SPAMASSASSIN=1 \
|
2018-03-18 18:52:28 +00:00
|
|
|
-e REPORT_RECIPIENT=user1@localhost.localdomain \
|
2018-05-01 17:57:31 +00:00
|
|
|
-e REPORT_SENDER=report1@mail.my-domain.com \
|
2017-04-18 12:18:42 +00:00
|
|
|
-e SA_TAG=-5.0 \
|
2016-02-18 21:11:24 +00:00
|
|
|
-e SA_TAG2=2.0 \
|
|
|
|
-e SA_KILL=3.0 \
|
2017-06-23 19:50:01 +00:00
|
|
|
-e SA_SPAM_SUBJECT="SPAM: " \
|
2016-10-08 17:02:47 +00:00
|
|
|
-e VIRUSMAILS_DELETE_DELAY=7 \
|
2018-03-18 19:15:06 +00:00
|
|
|
-e ENABLE_SRS=1 \
|
2016-07-23 17:54:10 +00:00
|
|
|
-e SASL_PASSWD="external-domain.com username:password" \
|
2016-04-29 15:09:48 +00:00
|
|
|
-e ENABLE_MANAGESIEVE=1 \
|
2017-10-10 06:15:18 +00:00
|
|
|
--cap-add=SYS_PTRACE \
|
2016-12-23 22:56:39 +00:00
|
|
|
-e PERMIT_DOCKER=host \
|
|
|
|
-e DMS_DEBUG=0 \
|
2016-02-18 21:11:24 +00:00
|
|
|
-h mail.my-domain.com -t $(NAME)
|
2020-09-05 14:19:12 +00:00
|
|
|
-@ sleep $(SLEEP)
|
2019-09-07 18:48:00 +00:00
|
|
|
docker run --rm -d --name mail_smtponly_without_config \
|
2017-06-07 13:35:42 +00:00
|
|
|
-e SMTP_ONLY=1 \
|
|
|
|
-e ENABLE_LDAP=1 \
|
|
|
|
-e PERMIT_DOCKER=network \
|
|
|
|
-e OVERRIDE_HOSTNAME=mail.mydomain.com \
|
|
|
|
-t $(NAME)
|
2020-09-05 14:19:12 +00:00
|
|
|
-@ sleep $(SLEEP)
|
2019-09-07 18:48:00 +00:00
|
|
|
docker run --rm -d --name mail_override_hostname \
|
2017-02-13 10:07:30 +00:00
|
|
|
-v "`pwd`/test/config":/tmp/docker-mailserver \
|
2019-07-30 11:16:23 +00:00
|
|
|
-v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \
|
2017-02-13 10:07:30 +00:00
|
|
|
-e PERMIT_DOCKER=network \
|
2017-08-07 15:39:40 +00:00
|
|
|
-e DMS_DEBUG=0 \
|
2018-06-19 06:17:32 +00:00
|
|
|
-e ENABLE_SRS=1 \
|
2017-02-13 10:07:30 +00:00
|
|
|
-e OVERRIDE_HOSTNAME=mail.my-domain.com \
|
2018-04-05 17:04:55 +00:00
|
|
|
-h unknown.domain.tld \
|
2017-02-13 10:07:30 +00:00
|
|
|
-t $(NAME)
|
2020-09-05 14:19:12 +00:00
|
|
|
-@ sleep $(SLEEP)
|
2019-09-07 18:48:00 +00:00
|
|
|
docker run --rm -d --name mail_domainname \
|
2018-06-19 06:17:32 +00:00
|
|
|
-v "`pwd`/test/config":/tmp/docker-mailserver \
|
2019-07-30 11:16:23 +00:00
|
|
|
-v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \
|
2018-06-19 06:17:32 +00:00
|
|
|
-e PERMIT_DOCKER=network \
|
|
|
|
-e DMS_DEBUG=0 \
|
|
|
|
-e ENABLE_SRS=1 \
|
|
|
|
-e DOMAINNAME=my-domain.com \
|
|
|
|
-h unknown.domain.tld \
|
|
|
|
-t $(NAME)
|
2020-09-05 14:19:12 +00:00
|
|
|
-@ sleep $(SLEEP)
|
2019-09-07 18:48:00 +00:00
|
|
|
docker run --rm -d --name mail_srs_domainname \
|
2018-06-19 06:17:32 +00:00
|
|
|
-v "`pwd`/test/config":/tmp/docker-mailserver \
|
2019-07-30 11:16:23 +00:00
|
|
|
-v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \
|
2018-06-19 06:17:32 +00:00
|
|
|
-e PERMIT_DOCKER=network \
|
|
|
|
-e DMS_DEBUG=0 \
|
|
|
|
-e ENABLE_SRS=1 \
|
|
|
|
-e SRS_DOMAINNAME=srs.my-domain.com \
|
|
|
|
-e DOMAINNAME=my-domain.com \
|
|
|
|
-h unknown.domain.tld \
|
|
|
|
-t $(NAME)
|
2020-09-05 14:19:12 +00:00
|
|
|
-@ sleep $(SLEEP)
|
2019-09-07 18:48:00 +00:00
|
|
|
docker run --rm -d --name mail_disabled_clamav_spamassassin \
|
2016-08-04 19:04:26 +00:00
|
|
|
-v "`pwd`/test/config":/tmp/docker-mailserver \
|
2019-07-30 11:16:23 +00:00
|
|
|
-v "`pwd`/test/test-files":/tmp/docker-mailserver-test:ro \
|
2016-12-25 21:54:37 +00:00
|
|
|
-e ENABLE_CLAMAV=0 \
|
|
|
|
-e ENABLE_SPAMASSASSIN=0 \
|
2017-08-07 15:39:40 +00:00
|
|
|
-e DMS_DEBUG=0 \
|
2016-08-04 19:04:26 +00:00
|
|
|
-h mail.my-domain.com -t $(NAME)
|
2020-09-05 14:19:12 +00:00
|
|
|
-@ sleep $(SLEEP)
|
Introducing Postscreen (#799)
* Introduced Postscreen
cheaper, earlier and simpler blocking of zombies/spambots.
From http://postfix.cs.utah.edu/POSTSCREEN_README.html :
As a first layer, postscreen(8) blocks connections from zombies and other spambots that are responsible for about 90% of all spam. It is implemented as a single process to make this defense as cheap as possible.
Things we need to consider:
- Do we need a whitelist/backlist file? (http://postfix.cs.utah.edu/postconf.5.html#postscreen_access_list)
- Via introducing an optional config/postfix-access.cidr
- The only permanent whitelisting I could imagine are monitoring services(which might (still?) behave weird/hastely) or blacklisting backup servers(since no traffic should be coming from them anyway)
- Do we need deep inspections? They are desireable, but these tests are expensive: a good client must disconnect after it passes the test, before it can talk to a real Postfix SMTP server. Considered tests are:
- postscreen_bare_newline_enable (http://postfix.cs.utah.edu/postconf.5.html#postscreen_bare_newline_action)
- postscreen_non_smtp_command_enable (http://postfix.cs.utah.edu/postconf.5.html#postscreen_non_smtp_command_action)
- postscreen_pipelining_enable (http://postfix.cs.utah.edu/postconf.5.html#postscreen_pipelining_action)
- Do we need to make the blacklisting via dnsblocking configurable? It's currently set and weighted as follows, where a score of 3 results in blocking, a score of -1 results in whitelisting:
(*: adds the specified weight to the SMTP client's DNSBL score. Specify a negative number for whitelisting.)
(http://postfix.cs.utah.edu/postconf.5.html#postscreen_dnsbl_sites)
- zen.spamhaus.org*3
- bl.mailspike.net
- b.barracudacentral.org*2
- bl.spameatingmonkey.net
- bl.spamcop.net
- dnsbl.sorbs.net
- psbl.surriel.com
- list.dnswl.org=127.0.[0..255].0*-2
- list.dnswl.org=127.0.[0..255].1*-3
- list.dnswl.org=127.0.[0..255].[2..3]*-4
- What to do when blacklisting? I currently set it to drop. We could
- 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.
- 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.
In the end I think we could drop postgrey support. Postscreen replaces postgrey in its entirety, while being more selective and not delaying mail. Especially if we consider using the deep inspection options of postscreen.
Hope that wasn't too much to read! ;)
* main.cf got misformatted..
Don't know how, should be ok now.
* fixed malformatted main.cf & repaired master.cf
* reenabled rbl stuff.. It's cached, therefore doesn't hurt
* fixed tests
* added tests, repaired tests, added info, introduced new Variable POSTSCREEN_ACTION, fixes
2018-02-04 20:31:08 +00:00
|
|
|
|
2017-10-10 06:15:18 +00:00
|
|
|
generate-accounts-after-run:
|
2020-09-05 14:19:12 +00:00
|
|
|
@ docker run --rm -e MAIL_USER=added@localhost.localdomain -e MAIL_PASS=mypassword -t $(NAME) /bin/sh -c 'echo "$$MAIL_USER|$$(doveadm pw -s SHA512-CRYPT -u $$MAIL_USER -p $$MAIL_PASS)"' >> test/config/postfix-accounts.cf
|
|
|
|
@ docker exec mail addmailuser pass@localhost.localdomain 'may be \a `p^a.*ssword'
|
|
|
|
@ sleep $(SLEEP)
|
2017-12-31 11:33:48 +00:00
|
|
|
|
2015-10-18 19:02:46 +00:00
|
|
|
fixtures:
|
2020-09-05 14:19:12 +00:00
|
|
|
# setup sieve
|
2016-04-28 06:57:50 +00:00
|
|
|
docker cp "`pwd`/test/config/sieve/dovecot.sieve" mail:/var/mail/localhost.localdomain/user1/.dovecot.sieve
|
2020-09-05 14:19:12 +00:00
|
|
|
sleep $(SLEEP)
|
|
|
|
sleep $(SLEEP)
|
|
|
|
# sending test mails
|
2016-04-20 23:08:14 +00:00
|
|
|
docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-spam.txt"
|
|
|
|
docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/amavis-virus.txt"
|
|
|
|
docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-alias-external.txt"
|
|
|
|
docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-alias-local.txt"
|
2017-03-03 17:27:22 +00:00
|
|
|
docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-alias-recipient-delimiter.txt"
|
2017-04-18 12:18:42 +00:00
|
|
|
docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user1.txt"
|
|
|
|
docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user2.txt"
|
2017-10-10 06:15:18 +00:00
|
|
|
docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-added.txt"
|
2016-07-23 19:01:01 +00:00
|
|
|
docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user-and-cc-local-alias.txt"
|
2016-05-24 04:43:08 +00:00
|
|
|
docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-regexp-alias-external.txt"
|
|
|
|
docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-regexp-alias-local.txt"
|
2016-07-23 21:42:18 +00:00
|
|
|
docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-catchall-local.txt"
|
2016-04-28 06:57:50 +00:00
|
|
|
docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/sieve-spam-folder.txt"
|
2017-05-10 07:54:02 +00:00
|
|
|
docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/sieve-pipe.txt"
|
2016-04-20 23:08:14 +00:00
|
|
|
docker exec mail /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/non-existing-user.txt"
|
2017-04-18 12:18:42 +00:00
|
|
|
docker exec mail_disabled_clamav_spamassassin /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user1.txt"
|
2018-04-23 18:35:33 +00:00
|
|
|
docker exec mail /bin/sh -c "sendmail root < /tmp/docker-mailserver-test/email-templates/root-email.txt"
|
2020-09-05 14:19:12 +00:00
|
|
|
# postfix virtual transport lmtp
|
2017-04-18 12:18:42 +00:00
|
|
|
docker exec mail_override_hostname /bin/sh -c "nc 0.0.0.0 25 < /tmp/docker-mailserver-test/email-templates/existing-user1.txt"
|
2020-09-05 14:19:12 +00:00
|
|
|
# wait for mails to be analyzed
|
2017-10-18 05:43:30 +00:00
|
|
|
sleep 80
|
2015-10-18 19:02:46 +00:00
|
|
|
|
|
|
|
tests:
|
2019-08-07 00:24:56 +00:00
|
|
|
./test/bats/bin/bats test/*.bats
|
|
|
|
|
|
|
|
.PHONY: ALWAYS_RUN
|
|
|
|
test/%.bats: ALWAYS_RUN
|
|
|
|
./test/bats/bin/bats $@
|
2016-01-22 17:47:43 +00:00
|
|
|
|
|
|
|
clean:
|
2020-09-05 14:19:12 +00:00
|
|
|
# remove running and stopped test containers
|
|
|
|
-@ docker ps -a | grep -E "docker-mailserver:testing|ldap_for_mail" | cut -f 1-1 -d ' ' | xargs --no-run-if-empty docker rm -f
|
|
|
|
-@ if [ -d config.bak ]; then\
|
2018-03-21 18:55:41 +00:00
|
|
|
rm -rf config ;\
|
2018-03-16 17:52:49 +00:00
|
|
|
mv config.bak config ;\
|
2016-09-12 15:49:46 +00:00
|
|
|
fi
|
2020-09-05 14:19:12 +00:00
|
|
|
-@ if [ -d testconfig.bak ]; then\
|
2018-04-02 08:45:58 +00:00
|
|
|
sudo rm -rf test/config ;\
|
2018-03-21 18:55:41 +00:00
|
|
|
mv testconfig.bak test/config ;\
|
|
|
|
fi
|
2020-09-06 10:27:40 +00:00
|
|
|
-@ sudo rm -rf test/onedir test/alias test/quota test/relay test/config/dovecot-lmtp/userdb test/config/key* test/config/opendkim/keys/domain.tld/ test/config/opendkim/keys/example.com/ test/config/opendkim/keys/localdomain2.com/ test/config/postfix-aliases.cf test/config/postfix-receive-access.cf test/config/postfix-receive-access.cfe test/config/dovecot-quotas.cf test/config/postfix-send-access.cf test/config/postfix-send-access.cfe test/config/relay-hosts/chksum test/config/relay-hosts/postfix-aliases.cf test/config/dhparams.pem test/config/dovecot-lmtp/dh.pem test/config/relay-hosts/dovecot-quotas.cf test/config/user-patches.sh test/alias/config/postfix-virtual.cf test/quota/config/dovecot-quotas.cf test/quota/config/postfix-accounts.cf test/relay/config/postfix-relaymap.cf test/relay/config/postfix-sasl-password.cf
|
2020-09-05 14:19:12 +00:00
|
|
|
|
2020-10-04 17:34:15 +00:00
|
|
|
lint: eclint hadolint shellcheck
|
|
|
|
|
|
|
|
hadolint:
|
|
|
|
@ ./test/linting/lint.sh hadolint
|
|
|
|
|
2020-09-05 14:19:12 +00:00
|
|
|
shellcheck:
|
2020-10-04 17:34:15 +00:00
|
|
|
@ ./test/linting/lint.sh shellcheck
|
2020-09-24 12:54:21 +00:00
|
|
|
|
|
|
|
eclint:
|
2020-10-04 17:34:15 +00:00
|
|
|
@ ./test/linting/lint.sh eclint
|