Skip to content

fix: postfix-main.cf may depend upon postfix-master.cf#3880

Merged
polarathene merged 6 commits intomasterfrom
fix/override-postfix-configs-dependency
May 2, 2024
Merged

fix: postfix-main.cf may depend upon postfix-master.cf#3880
polarathene merged 6 commits intomasterfrom
fix/override-postfix-configs-dependency

Conversation

@polarathene
Copy link
Copy Markdown
Member

@polarathene polarathene commented Feb 10, 2024

Description

Custom parameters must be referenced to be retained when postconf -n is run.

If postfix-main.cf defines custom parameters that are referenced by postfix-master.cf, that needs to first update master.cf before updating main.cf (where postconf -n is relied upon).


Failure was a little tricky to troubleshoot as it only occurred during initial startup, reproducing the logic afterwards manually, or via container restart (with internal state persisted) worked fine as master.cf was already configured with the custom parameters.

Due to postconf -n outputting any errors to /dev/null, this sort of information is omitted from the logs:

postconf: warning: /etc/postfix/main.cf: unused parameter: some_custom_parameter=value

Discovered while answering: https://github.com/orgs/docker-mailserver/discussions/3847

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • My code follows the style guidelines of this project
  • I have performed a self-review of my code
  • I have commented my code, particularly in hard-to-understand areas
  • If necessary, I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have added information about changes made in this PR to CHANGELOG.md

Custom parameters must be referenced to be retained when `postconf -n` is run. If those parameters are referenced by `postfix-master.cf` this needs to update `master.cf` before updating `main.cf`.
@polarathene
Copy link
Copy Markdown
Member Author

Should we add a test case for this? Or is the inline comment about order dependency sufficient?

@georglauterbach
Copy link
Copy Markdown
Member

I think having a test for this is a good idea :)

@github-actions github-actions Bot added the meta/stale This issue / PR has become stale and will be closed if there is no further activity label Mar 2, 2024
@docker-mailserver docker-mailserver deleted a comment from github-actions Bot Mar 2, 2024
@polarathene polarathene added stale-bot/ignore Indicates that this issue / PR shall not be closed by our stale-checking CI and removed meta/stale This issue / PR has become stale and will be closed if there is no further activity labels Mar 2, 2024

# do not directly output to 'main.cf' as this causes a read-write-conflict
# Do not directly output to 'main.cf' as this causes a read-write-conflict
postconf -n >/tmp/postfix-main-new.cf 2>/dev/null
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Due to postconf -n outputting any errors to /dev/null, this sort of information is omitted from the logs

As long as annoying errors are not expected, 2>/dev/null should be removed:

Suggested change
postconf -n >/tmp/postfix-main-new.cf 2>/dev/null
postconf -n >/tmp/postfix-main-new.cf

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As long as annoying errors are not expected

What do you consider annoying?

I gave an example log line (warning), you get those as well for any duplicate parameters configured IIRC (due to postfix-main.cf appending overrides).

I can commit your suggestion if you think the added noise is worthwhile? (here is why we originally did this)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably I misunderstood something.

By moving the postfix master part at the top, the mentioned error should be fixed? Therefore postconf -n should run fine without errors. If that's the case, stderr should not be redirected to dev/null.

Copy link
Copy Markdown
Member Author

@polarathene polarathene Mar 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By moving the postfix master part at the top, the mentioned error should be fixed?

The log line example shown in this PR would be avoided if the setting is in master.cf yes.

Therefore postconf -n should run fine without errors. If that's the case, stderr should not be redirected to dev/null.

See the link to the original reason we added 2>/dev/null to avoid log spam due to a different condition. I assume that behaviour can still be reproduced and don't see how it would be desirable to show it.


EDIT: Confirmed, this can still be reproduced when removing 2>/dev/null.

While that output is very spammy for me (as the linked comment reports).. during actual container startup with a config file, the postconf command on this line only displayed a single warning line emitted per duplicate parameter in the produced main.cf file:

postconf: warning: /etc/postfix/main.cf, line 131: overriding earlier entry: max_idle=300

Still that is expected for each parameter in postfix-main.cf that has one already defined in main.cf, thus that noise isn't helpful in logs 🤷‍♂️

I suppose we could filter it out, so that other warnings are visible like the one this PR mentions:

postconf: warning: /etc/postfix/main.cf: unused parameter: some_custom_parameter=value

Process substitution seems to handle that. Not sure if this is optimal, but it works 😅

postconf -n >/tmp/postfix-main-new.cf 2> >(grep -v 'overriding earlier entry')

Copy link
Copy Markdown
Member Author

@polarathene polarathene left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the long delay on getting back to this!

Test case added. I've done some more revisions, but the new comments as part of this review is all you should need AFAIK. Feel free to look over the test case itself, it should be easy to grok👍


@georglauterbach ping for review, since I can't renew an existing request 😓

Comment on lines +129 to +132
# 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')
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the main change I added since the last round of reviews.

It should allow for retaining other output from postconf that may be of interest when something unexpected happens, as opposed to the more blunt 2>/dev/null approach we have 👍

You're both more comfortable with shell syntax than I am, so if you have any feedback here, happy to go with that instead 😎

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're both more comfortable with shell syntax than I am, so if you have any feedback here, happy to go with that instead 😎

No, looks all good to me!

Comment on lines +6 to +7
# This parameter is referenced by an override in `postfix-master.cf`:
custom_parameter = cidr:{{!172.16.0.42 REJECT}}, permit_sasl_authenticated, reject
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test adds this postfix-main.cf custom parameter, which postfix-master.cf uses for smtpd_client_restrictions value. This is the same as what the referenced discussion was using, it just prepends that cidr inline table to reject any IP that is not 172.16.0.42.

With the postfix.sh change to swap the order we apply postfix-main.cf and postfix-master.cf, the test demonstrates that we can correctly resolve/expand the $custom_parameter value in the updated /etc/postfix/master.cf file 👍

Comment on lines +18 to +19
# The `postconf` command can query both `main.cf` and `master.cf` at `/etc/postfix/`.
# Reference: http://www.postfix.org/postconf.1.html
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maintainer docs reference for this test file, since there's a few different options used with the postconf command in the test cases below, probably helpful to have here 😅

@polarathene polarathene requested a review from casperklein May 2, 2024 07:56
Copy link
Copy Markdown
Member

@georglauterbach georglauterbach left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍🏼 Nice work!

@polarathene polarathene merged commit e2c2a22 into master May 2, 2024
@polarathene polarathene deleted the fix/override-postfix-configs-dependency branch May 2, 2024 23:12
@polarathene
Copy link
Copy Markdown
Member Author

Cheers for the reviews/approvals! 😁

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/configuration (file) area/scripts kind/bug/fix A fix (PR) for a confirmed bug service/postfix stale-bot/ignore Indicates that this issue / PR shall not be closed by our stale-checking CI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants