foxcpp / maddy

✉️ Composable all-in-one mail server.
https://maddy.email
GNU General Public License v3.0
5.13k stars 249 forks source link

Proxy protocol support for SMTP and IMAP #568

Closed drdaeman closed 1 year ago

drdaeman commented 1 year ago

Hey, first of all, once again thank you for this project! I need to put maddy behind a reverse proxy (Traefik, but shouldn't really matter), but it needs to be aware about the original IP address, so I want it to support PROXY protocol.

What do you think about this implementation? I haven't fully battle-tested it yet, but it seem to work and to best of my awareness it should resolve two out of three remaining point of #369. Of course, I want this to be accepted, so I'm willing to make this PR as good as possible (if needed) and would appreciate any feedback.

Two potential issues I see are related to tests:

Thanks!

drdaeman commented 1 year ago

I've battle-tested this on my own SMTP service running latest Maddy with my patches included for the last week, using proxy_protocol behind Traefik - and it seem to work without issues. All the headers and logs are spot on, no 192.168s. I haven't production-tested IMAP - I run Dovecot (because of dsync) - but I don't suppose it should be any different.

codecov-commenter commented 1 year ago

Codecov Report

Merging #568 (3910d91) into master (96fce6b) will increase coverage by 0.03%. The diff coverage is 60.65%.

@@            Coverage Diff             @@
##           master     #568      +/-   ##
==========================================
+ Coverage   52.76%   52.79%   +0.03%     
==========================================
  Files         127      128       +1     
  Lines       13040    13101      +61     
==========================================
+ Hits         6880     6917      +37     
- Misses       5514     5532      +18     
- Partials      646      652       +6     
Flag Coverage Δ
integration 34.02% <60.65%> (+0.14%) :arrow_up:
unit 54.42% <25.00%> (-0.02%) :arrow_down:

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
internal/endpoint/imap/imap.go 60.75% <25.00%> (-0.93%) :arrow_down:
internal/proxy_protocol/proxy_protocol.go 60.37% <60.37%> (ø)
internal/endpoint/smtp/smtp.go 67.35% <100.00%> (+0.45%) :arrow_up:

:mega: We’re building smart automated test selection to slash your CI/CD build times. Learn more

drdaeman commented 1 year ago

Hey, sorry for a long time to respond - had a few things going on in my life that took all of my time. My bad.

I've rebased my branch and updated the tests, using the recommended 127.0.0.17 address - good consideration, thank you.

I gave it some thought and I'm a bit reluctant to remove the tls directive from proxy_protocol. Here's my logic:

I hope this makes sense. If it doesn't, or you feel like that's not a scenario you want to support - let me know and I'll just nuke tls directive from there.

Again, sorry for a long silence and thanks!

foxcpp commented 1 year ago

Thanks for your work!