Skip to content

feat: Add support for defining an allowlist for recipients#136

Closed
PyroDevil wants to merge 1 commit intojuanluisbaptiste:masterfrom
PyroDevil:feat-destination-allowlist
Closed

feat: Add support for defining an allowlist for recipients#136
PyroDevil wants to merge 1 commit intojuanluisbaptiste:masterfrom
PyroDevil:feat-destination-allowlist

Conversation

@PyroDevil
Copy link

As this Postfix relay server doesn't require authentication to send emails, devices that aren't fully trusted could spam emails using this relay. And this could result in the IP address of the mail server being blacklisted.

To prevent this server being used to send spam messages, this patch implements an allowlist for recipients via the RECIPIENT_ALLOWLIST environment variable. This variable can contain a list of recipient addresses or domains separated by spaces or commas.

Description of the change

This adds a RECIPIENT_ALLOWLIST environment variable, which allows to restrict allowed recipients to a certain allowlist.
Generally I use this postfix relay to allow devices, that either don't support TLS1.3 or for other reasons cannot send emails directly on my mail server.

However I also don't want to just allow any device to use my mail server to send anyone emails. I want to limit the allowed recipients or domains. This allows more control over what is allowed, thus it prevents rogue devices from sending spam, or accidentally sending/leaking emails to people outside of the organization.

How Has This Been Tested?

I tested sending emails to allowed recipients and not allowed recipients, and the result was as expected.

Types of Changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation (adding or updating documentation)

Checklist:

  • My change requires a change to the documentation and I have updated the documentation accordingly.
  • My change adds a new configuration variable and I have updated the .env.example file accordingly.

As this Postfix relay server doesn't require authentication to send
emails, devices that aren't fully trusted could spam emails using this
relay. And this could result in the IP address of the mail server being
blacklisted.

To prevent this server being used to send spam messages, this patch
implements an allowlist for recipients via the `RECIPIENT_ALLOWLIST`
environment variable. This variable can contain a list of recipient
addresses or domains separated by spaces or commas.

Signed-off-by: Pyro Devil <p.devil@randman.org>
@PyroDevil
Copy link
Author

Oh, I didn't notice that #130 exists. I should have looked into PRs first I guess.

@PyroDevil PyroDevil closed this Jan 30, 2026
@PyroDevil
Copy link
Author

@juanluisbaptiste, I solved this a bit differently, I named it 'recipients' because it can be full email addresses as well as domains, and the logic is a bit simpler, IMO. So if you are preferring this I can reopen it again. But I am fine with either #130 or this PR.

add_config_value "transport_maps" "lmdb://etc/postfix/transport"
IFS=', ' read -r -a recipient_allowlist_array <<< "${RECIPIENT_ALLOWLIST}"
for allowed_recipient in "${recipient_allowlist_array[@]}"; do
printf "%s :\n" "$allowed_recipient" >> /etc/postfix/transport
Copy link
Owner

Choose a reason for hiding this comment

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

Haven't tested it yet, but this code I think will have the same problem as with issue #130 , it will add duplicate lines to the configuration on restart.

Copy link
Author

Choose a reason for hiding this comment

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

I force pushed a fix shortly after I closed this PR, which prevents me from opening this PR now.

But this is a easy fix. I just added a rm -f /etc/postfix/transport before writing the first line:

https://github.com/PyroDevil/docker-postfix/blob/feat-destination-allowlist/run.sh#L130

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants