diff --git a/target/scripts/startup/setup.d/postfix.sh b/target/scripts/startup/setup.d/postfix.sh index 1a6356a6..3ebdeb9d 100644 --- a/target/scripts/startup/setup.d/postfix.sh +++ b/target/scripts/startup/setup.d/postfix.sh @@ -119,14 +119,17 @@ function __postfix__setup_override_configuration() { __postfix__log 'trace' "No extra Postfix master settings loaded because optional '${OVERRIDE_CONFIG_POSTFIX_MASTER}' was not provided" fi - # NOTE: Must come after postfix-master.cf as custom parameter support only works provided either config references it. + # NOTE: `postfix-main.cf` should be handled after `postfix-master.cf` as custom parameters require an existing reference + # in either `main.cf` or `master.cf` prior to `postconf` reading `main.cf`, otherwise it is discarded from output. local OVERRIDE_CONFIG_POSTFIX_MAIN='/tmp/docker-mailserver/postfix-main.cf' if [[ -f ${OVERRIDE_CONFIG_POSTFIX_MAIN} ]]; then cat "${OVERRIDE_CONFIG_POSTFIX_MAIN}" >>/etc/postfix/main.cf _adjust_mtime_for_postfix_maincf - # Do not directly output to 'main.cf' as this causes a read-write-conflict - postconf -n >/tmp/postfix-main-new.cf 2>/dev/null + # Do not directly output to 'main.cf' as this causes a read-write-conflict. + # `postconf` output is filtered to skip expected warnings regarding overrides: + # https://github.com/docker-mailserver/docker-mailserver/pull/3880#discussion_r1510414576 + postconf -n >/tmp/postfix-main-new.cf 2> >(grep -v 'overriding earlier entry') mv /tmp/postfix-main-new.cf /etc/postfix/main.cf _adjust_mtime_for_postfix_maincf diff --git a/test/config/override-configs/postfix-master.cf b/test/config/override-configs/postfix-master.cf index d284575b..f54d37d3 100644 --- a/test/config/override-configs/postfix-master.cf +++ b/test/config/override-configs/postfix-master.cf @@ -2,5 +2,6 @@ submission/inet/smtpd_sasl_security_options=noanonymous # this is a test comment, please don't delete me :'( # this is also a test comment, :O -# `postfix-main.cf` must be processed first before this custom parameter is in scope: +# DMS must first process `postfix-master.cf` to `master.cf` when any custom parameters are from `postfix-main.cf` +# before an updated `main.cf` is read via `postconf`, otherwise without an existing reference the parameter is excluded. submission/inet/smtpd_client_restrictions=$custom_parameter diff --git a/test/tests/parallel/set1/config_overrides.bats b/test/tests/parallel/set1/config_overrides.bats index 2f9673ff..139765cb 100644 --- a/test/tests/parallel/set1/config_overrides.bats +++ b/test/tests/parallel/set1/config_overrides.bats @@ -41,17 +41,20 @@ function teardown_file() { _default_teardown ; } } # Custom parameter support works correctly: -@test "Postfix - 'postfix-main.cf' should apply before 'postfix-master.cf'" { +# NOTE: This would only fail on a fresh container state, any restart would pass successfully: +# https://github.com/docker-mailserver/docker-mailserver/pull/3880 +@test "Postfix - 'postfix-master.cf' should apply before 'postfix-main.cf'" { # Retrieve the value for this setting, `postfix-master.cf` should have the override set: _run_in_container postconf -Ph 'submission/inet/smtpd_client_restrictions' assert_success + refute_output --partial 'postconf: warning: /etc/postfix/master.cf: undefined parameter: custom_parameter' asset_output '$custom_parameter' - # As it's a custom parameter ($ prefix), ensure the parameters value is correctly configured: + # As it's a custom parameter (`$` prefix), ensure the parameter value expands correctly: _run_in_container postconf -Phx 'submission/inet/smtpd_client_restrictions' assert_success + refute_output --partial 'postconf: warning: /etc/postfix/master.cf: undefined parameter: custom_parameter' assert_output 'cidr:{{!172.16.0.42 REJECT}}, permit_sasl_authenticated, reject' - refute_output 'postconf: warning: /etc/postfix/master.cf: undefined parameter: custom_parameter' } @test "Dovecot - 'dovecot.cf' overrides applied to '/etc/dovecot/local.conf'" {