Merge pull request #80 from tomav/fix-spamassassin-default-config

Added Spamassassin configuration using ENV variables (see README)
This commit is contained in:
Thomas VIAL 2016-02-18 23:16:06 +01:00
commit 10d04efece
4 changed files with 32 additions and 9 deletions

View file

@ -1,19 +1,30 @@
NAME = tvial/docker-mailserver NAME = tvial/docker-mailserver
VERSION = $(TRAVIS_BUILD_ID)
all: build run fixtures tests clean all: build run fixtures tests clean
all-no-build: run fixtures tests clean all-no-build: run fixtures tests clean
build: build:
docker build --no-cache -t $(NAME):$(VERSION) . docker build --no-cache -t $(NAME) .
run: run:
# Copy test files # Copy test files
cp test/accounts.cf postfix/ cp test/accounts.cf postfix/
cp test/virtual postfix/ cp test/virtual postfix/
# Run containers # Run containers
docker run -d --name mail -v "`pwd`/postfix":/tmp/postfix -v "`pwd`/spamassassin":/tmp/spamassassin -v "`pwd`/test":/tmp/test -h mail.my-domain.com -t $(NAME):$(VERSION) docker run -d --name mail \
docker run -d --name mail_pop3 -v "`pwd`/postfix":/tmp/postfix -v "`pwd`/spamassassin":/tmp/spamassassin -v "`pwd`/test":/tmp/test -e ENABLE_POP3=1 -h mail.my-domain.com -t $(NAME):$(VERSION) -v "`pwd`/postfix":/tmp/postfix \
-v "`pwd`/spamassassin":/tmp/spamassassin \
-v "`pwd`/test":/tmp/test \
-e SA_TAG=1.0 \
-e SA_TAG2=2.0 \
-e SA_KILL=3.0 \
-h mail.my-domain.com -t $(NAME)
docker run -d --name mail_pop3 \
-v "`pwd`/postfix":/tmp/postfix \
-v "`pwd`/spamassassin":/tmp/spamassassin \
-v "`pwd`/test":/tmp/test \
-e ENABLE_POP3=1 \
-h mail.my-domain.com -t $(NAME)
# Wait for containers to fully start # Wait for containers to fully start
sleep 60 sleep 60

View file

@ -88,6 +88,12 @@ Example:
* ENABLE_POP3 * ENABLE_POP3
* *empty* (default) => POP3 service disabled * *empty* (default) => POP3 service disabled
* 1 => Enables POP3 service * 1 => Enables POP3 service
* SA_TAG
* *2.0* (default) => add spam info headers if at, or above that level
* SA_TAG2
* *6.31* (default) => add 'spam detected' headers at that level
* SA_KILL
* *6.31* (default) => triggers spam evasive actions)
Please read [how the container starts](https://github.com/tomav/docker-mailserver/blob/master/start-mailserver.sh) to understand what's expected. Please read [how the container starts](https://github.com/tomav/docker-mailserver/blob/master/start-mailserver.sh) to understand what's expected.

View file

@ -182,13 +182,11 @@ echo "Creating /etc/mailname"
echo $(hostname -d) > /etc/mailname echo $(hostname -d) > /etc/mailname
echo "Configuring Spamassassin" echo "Configuring Spamassassin"
echo "required_hits 5.0" >> /etc/mail/spamassassin/local.cf SA_TAG=${SA_TAG:="2.0"} && sed -i -r 's/^\$sa_tag_level_deflt (.*);/\$sa_tag_level_deflt = '$SA_TAG';/g' /etc/amavis/conf.d/20-debian_defaults
echo "report_safe 0" >> /etc/mail/spamassassin/local.cf SA_TAG2=${SA_TAG2:="6.31"} && sed -i -r 's/^\$sa_tag2_level_deflt (.*);/\$sa_tag2_level_deflt = '$SA_TAG2';/g' /etc/amavis/conf.d/20-debian_defaults
echo "required_score 5" >> /etc/mail/spamassassin/local.cf SA_KILL=${SA_KILL:="6.31"} && sed -i -r 's/^\$sa_kill_level_deflt (.*);/\$sa_kill_level_deflt = '$SA_KILL';/g' /etc/amavis/conf.d/20-debian_defaults
echo "rewrite_header Subject ***SPAM***" >> /etc/mail/spamassassin/local.cf
cp /tmp/spamassassin/rules.cf /etc/spamassassin/ cp /tmp/spamassassin/rules.cf /etc/spamassassin/
echo "Configuring fail2ban" echo "Configuring fail2ban"
# enable filters # enable filters
perl -i -0pe 's/(\[postfix\]\n\n).*\n/\1enabled = true\n/' /etc/fail2ban/jail.conf perl -i -0pe 's/(\[postfix\]\n\n).*\n/\1enabled = true\n/' /etc/fail2ban/jail.conf

View file

@ -68,6 +68,14 @@ assert_raises "docker exec mail grep ': error:' /var/log/mail.log" 1
assert_raises "docker exec mail_pop3 grep 'non-null host address bits in' /var/log/mail.log" 1 assert_raises "docker exec mail_pop3 grep 'non-null host address bits in' /var/log/mail.log" 1
assert_raises "docker exec mail_pop3 grep ': error:' /var/log/mail.log" 1 assert_raises "docker exec mail_pop3 grep ': error:' /var/log/mail.log" 1
# Testing Spamssassin config in Amavis
assert_raises "docker exec mail_pop3 grep '\$sa_tag_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= 2.0'" 0
assert_raises "docker exec mail_pop3 grep '\$sa_tag2_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= 6.31'" 0
assert_raises "docker exec mail_pop3 grep '\$sa_kill_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= 6.31'" 0
assert_raises "docker exec mail grep '\$sa_tag_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= 1.0'" 0
assert_raises "docker exec mail grep '\$sa_tag2_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= 2.0'" 0
assert_raises "docker exec mail grep '\$sa_kill_level_deflt' /etc/amavis/conf.d/20-debian_defaults | grep '= 3.0'" 0
# Testing OpenDKIM # Testing OpenDKIM
assert "docker exec mail cat /etc/opendkim/KeyTable | wc -l" "2" assert "docker exec mail cat /etc/opendkim/KeyTable | wc -l" "2"
assert "docker exec mail ls -l /etc/opendkim/keys/ | grep '^d' | wc -l" "2" assert "docker exec mail ls -l /etc/opendkim/keys/ | grep '^d' | wc -l" "2"