docker-postfix icon indicating copy to clipboard operation
docker-postfix copied to clipboard

Would want to use regex to do fancy masquerading

Open tardich opened this issue 6 months ago • 3 comments

Hello. I'm looking at a way to replace [email protected] with [email protected]

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)

tardich avatar Jan 11 '24 03:01 tardich

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.

bokysan avatar Jan 11 '24 07:01 bokysan

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

tardich avatar Jan 11 '24 13:01 tardich

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/ [email protected]
  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 [email protected] is now actually sent to [email protected], 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/ [email protected]", 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 :-)

tardich avatar Jan 11 '24 19:01 tardich

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

bokysan avatar Apr 23 '24 06:04 bokysan