update scripts for Amavis & SpamAssassin

This commit is contained in:
georglauterbach 2023-12-04 00:42:55 +01:00
parent b4cc602b0e
commit 93c9c04912
No known key found for this signature in database
GPG key ID: F367F7C43C118578
6 changed files with 10 additions and 15 deletions

View file

@ -30,8 +30,6 @@ COPY target/scripts/helpers/log.sh /usr/local/bin/helpers/log.sh
RUN /bin/bash /build/packages.sh && rm -r /build RUN /bin/bash /build/packages.sh && rm -r /build
# ----------------------------------------------- # -----------------------------------------------
# --- Compile deb packages ---------------------- # --- Compile deb packages ----------------------
# ----------------------------------------------- # -----------------------------------------------
@ -122,7 +120,8 @@ COPY \
# hadolint ignore=SC2016 # hadolint ignore=SC2016
RUN <<EOF RUN <<EOF
sedfile -i -r 's/^(CRON)=0/\1=1/g' /etc/default/spamassassin # ref: https://github.com/docker-mailserver/docker-mailserver/pull/3403#discussion_r1306282387
echo 'CRON=1' >/etc/default/spamassassin
sedfile -i -r 's/^\$INIT restart/supervisorctl restart amavis/g' /etc/spamassassin/sa-update-hooks.d/amavisd-new sedfile -i -r 's/^\$INIT restart/supervisorctl restart amavis/g' /etc/spamassassin/sa-update-hooks.d/amavisd-new
mkdir /etc/spamassassin/kam/ mkdir /etc/spamassassin/kam/
curl -sSfLo /etc/spamassassin/kam/kam.sa-channels.mcgrail.com.key https://mcgrail.com/downloads/kam.sa-channels.mcgrail.com.key curl -sSfLo /etc/spamassassin/kam/kam.sa-channels.mcgrail.com.key https://mcgrail.com/downloads/kam.sa-channels.mcgrail.com.key
@ -181,7 +180,6 @@ RUN <<EOF
ln -sf /var/log/mail/fail2ban.log /var/log/fail2ban.log ln -sf /var/log/mail/fail2ban.log /var/log/fail2ban.log
# disable sshd jail # disable sshd jail
rm /etc/fail2ban/jail.d/defaults-debian.conf rm /etc/fail2ban/jail.d/defaults-debian.conf
mkdir /var/run/fail2ban
EOF EOF
COPY target/opendkim/opendkim.conf /etc/opendkim.conf COPY target/opendkim/opendkim.conf /etc/opendkim.conf

View file

@ -88,7 +88,7 @@ function _reload_amavis() {
if [[ ${CHANGED} =~ ${DMS_DIR}/postfix-accounts.cf ]] || [[ ${CHANGED} =~ ${DMS_DIR}/postfix-virtual.cf ]]; then if [[ ${CHANGED} =~ ${DMS_DIR}/postfix-accounts.cf ]] || [[ ${CHANGED} =~ ${DMS_DIR}/postfix-virtual.cf ]]; then
# /etc/postfix/vhost was updated, amavis must refresh it's config by # /etc/postfix/vhost was updated, amavis must refresh it's config by
# reading this file again in case of new domains, otherwise they will be ignored. # reading this file again in case of new domains, otherwise they will be ignored.
amavisd-new reload amavisd reload
fi fi
} }

View file

@ -79,11 +79,6 @@ function __setup__security__spamassassin() {
# shellcheck disable=SC2016 # shellcheck disable=SC2016
sed -i -r 's|^\$sa_kill_level_deflt (.*);|\$sa_kill_level_deflt = '"${SA_KILL}"';|g' /etc/amavis/conf.d/20-debian_defaults sed -i -r 's|^\$sa_kill_level_deflt (.*);|\$sa_kill_level_deflt = '"${SA_KILL}"';|g' /etc/amavis/conf.d/20-debian_defaults
# fix cron.daily for spamassassin
sed -i \
's|invoke-rc.d spamassassin reload|/etc/init\.d/spamassassin reload|g' \
/etc/cron.daily/spamassassin
if [[ ${SA_SPAM_SUBJECT} == 'undef' ]]; then if [[ ${SA_SPAM_SUBJECT} == 'undef' ]]; then
# shellcheck disable=SC2016 # shellcheck disable=SC2016
sed -i -r 's|^\$sa_spam_subject_tag (.*);|\$sa_spam_subject_tag = undef;|g' /etc/amavis/conf.d/20-debian_defaults sed -i -r 's|^\$sa_spam_subject_tag (.*);|\$sa_spam_subject_tag = undef;|g' /etc/amavis/conf.d/20-debian_defaults

View file

@ -94,7 +94,7 @@ autostart=false
autorestart=true autorestart=true
stdout_logfile=/var/log/supervisor/%(program_name)s.log stdout_logfile=/var/log/supervisor/%(program_name)s.log
stderr_logfile=/var/log/supervisor/%(program_name)s.log stderr_logfile=/var/log/supervisor/%(program_name)s.log
command=/usr/sbin/amavisd-new foreground command=/usr/sbin/amavisd foreground
[program:rspamd] [program:rspamd]
startsecs=0 startsecs=0

View file

@ -51,10 +51,8 @@ function teardown_file() {
export CONTAINER_NAME=${CONTAINER1_NAME} export CONTAINER_NAME=${CONTAINER1_NAME}
# give Amavis just a bit of time to print out its full debug log # give Amavis just a bit of time to print out its full debug log
run _repeat_in_container_until_success_or_timeout 5 "${CONTAINER_NAME}" grep 'ANTI-SPAM-SA' /var/log/mail/mail.log run _repeat_in_container_until_success_or_timeout 20 "${CONTAINER_NAME}" grep 'SpamControl: init_pre_fork on SpamAssassin done' /var/log/mail/mail.log
assert_success assert_success
assert_output --partial 'loaded'
refute_output --partial 'NOT loaded'
} }
@test '(Amavis enabled) SA ENV should update Amavis config' { @test '(Amavis enabled) SA ENV should update Amavis config' {

View file

@ -29,8 +29,12 @@ function teardown_file() { _default_teardown ; }
} }
@test "SA - Amavis integration should not be active" { @test "SA - Amavis integration should not be active" {
_run_in_container_bash "grep -i 'ANTI-SPAM-SA code' /var/log/mail/mail.log | grep 'NOT loaded'" # Wait until Amavis has finished initializing:
run _repeat_in_container_until_success_or_timeout 20 "${CONTAINER_NAME}" grep 'Deleting db files in /var/lib/amavis/db' /var/log/mail/mail.log
assert_success assert_success
# Amavis module for SA should not be loaded (`SpamControl: scanner SpamAssassin, module Amavis::SpamControl::SpamAssassin`):
_run_in_container grep 'scanner SpamAssassin' /var/log/mail/mail.log
assert_failure
} }
@test "SA - should not have been called" { @test "SA - should not have been called" {