bokysan / docker-postfix

Multi architecture simple SMTP server (postfix null relay) host for your Docker and Kubernetes containers. Based on Debian/Ubuntu/Alpine.
MIT License
555 stars 152 forks source link

Would want to use regex to do fancy masquerading #175

Closed tardich closed 7 months ago

tardich commented 10 months ago

Hello. I'm looking at a way to replace anyuser@int.this.fake.domain with anyuser@this.real.domain.com

I know I can do this by using smtp_generic_maps, but I'd need to specify all "internal" senders, one by one to something decent externally.

I'd prefer using a regex to do so. And this can be done with postfix-pcre regex module. Documentation to do so is at: https://serverfault.com/questions/930819/postfix-smtp-generic-maps-with-regular-expression

Would be really nice to have that included (the package, at least)

bokysan commented 10 months ago

Sure, that does sound something that could be added. While it's not, you're free to create your own init script, mount it to /docker-init.db and it will be executed automatically on startup.

tardich commented 10 months ago

Ah good insight! Forgot that :-( I'll take a look at it, meanwhile

tardich commented 10 months ago

OK, I made it working. Here's what I did.

1) Created and mounted an init script to install postfix-pcre module from a secret (with the help of extraVolumes and extraVolumeMounts). This portion should be done at the docker image creation level I'd say 2) Created and mounted the pcre map as /etc/postfix/generic.pcre from a secret again, containing in my case: /([a-z]+)@int.fake.stba/ $1@int.real.ca 3) Added config.postfix.smtp_generic_maps: "pcre:/etc/postfix/generic.pcre" as a value to the deployment

And then test. A message, originating from myuser@int.fake.stba is now actually sent to myuser@int.real.ca, which was the expected result.

Even more, this could be a little more templated from Helm to make it a little more seemlessly accessible. Something, maybe, like pcre.map: "/([a-z]+)@int.fake.stba/ $1@int.real.ca", pcre.enabled: true, and pcre.filename: somefilename.pcre that could create the secret (or configMap) with the content, mount it to /etc/postfix/somefilename.pcre, and add smtp_generic_maps: pcre:/etc/postfix/somefilename.pcre to /etc/postfix/main.cf

This would be the ultimate goal, but I can live without it :-)

bokysan commented 7 months ago

Latest image (currently in master branch only) now includes install of postfix-pcre.