Replies: 5 comments 10 replies
-
Please note that this response was created using generative AI, leveraging previously available information from the repository. This information may be helpful. However, it is our strong recommendation that you carefully consider the information before blindly applying it. This response is generated only once - you will not be able to interact with the glime-ai. When using Docker Mailserver (DMS) behind a Traefik reverse proxy with the PROXY protocol, Fail2Ban may face challenges in banning IPs because the original client IP is preserved by the PROXY protocol, but the banning mechanism might not be correctly applied. Here are some steps and considerations to help you configure Fail2Ban to work in this setup:
For more detailed guidance, you can refer to the following sources: This comment was generated by Glime. |
Beta Was this translation helpful? Give feedback.
-
I am not familiar with Fail2Ban that much, this is an area of expertise for @casperklein . If you could provide that additional information, it would likely be helpful for them. From what I understand Fail2Ban should be monitoring the Postfix and Dovecot logs for the client IPs. These should be the proper client IP with PROXY protocol configured correctly. The banning itself AFAIK is via a syscall to the kernel or something like this to interface with iptables/nftables to apply the ban. When the connection is made to the Postfix or Dovecot service from Traefik, I think this would always be allowed. So for the IP to be banned effectively, it needs to be the one connecting to the host, which should prevent even Traefik receiving the connection. PROXY protocol should avoid any issues with IPv6 to IPv4 (docker network gateway IP) mishaps that could happen with Docker. So I don't think it'd be related to this. You also mention you have explicitly tried banning the client IPs and they're still able to connect to the host 🤷♂️ Until @casperklein is available, my troubleshooting would be:
Without knowing fail2ban that well, I am not sure how much relevance the containerized service in DMS is. I would focus on replicating the ban manually on the host without it if necessary, as the ban itself needs to work correctly before anything else is relevant 😓 I know that with kubernetes when Traefik is run on a separate host, Fail2Ban is ineffective and another approach is required to have the ingress/gateway manage banned clients. Once the manual banning is working as expected, you may still have an issue with Fail2Ban monitoring Postfix/Dovecot if ports are relevant context. I'm not quite sure on what monitoring rules are used there. |
Beta Was this translation helpful? Give feedback.
-
I created a
I'd say fail2ban correctly detects malicious actors, but the ban does not acutally work.
According to documentation all traffic from these ips, e.g. 194.169.175.20 should be dropped. So my understanding is that the last entry should not be possible because the ip is already banned. Banning is probably not working because the connection is proxied and the firewall adds the source ip and doesn't know about Traefik. I have currently no idea how to change that. I'll try your suggestions above just to make sure too, later this evening. |
Beta Was this translation helpful? Give feedback.
-
Just to make sure I removed
|
Beta Was this translation helpful? Give feedback.
-
I tested some more.
Yes, this works. I just tested without Traefik.
Automatic ban without Traefik works. I did not test manual ban without Traefik. But I assume this should work too if automatic ban works.
Yes this is where it breaks. The ip's get correctly detected, but the ban is not enforced, I see the ips still trying to connect in
Yes, they are in the f2b-chain of the container, not the host. This is the same if Traefik is used or not though.
There are three IPs that try to do a brute foce attack all the time. So this is a real world scenario :-) I am out of ideas at the moment what the problem could be or where to look. |
Beta Was this translation helpful? Give feedback.
-
I followed the Mailserver behind Proxy documentation, to put my DMS behind a Traefik reverse proxy. I did not enable proxy on existing ports, but configured services with separate ports for the PROXY protocol just like it is described in the linked document.
Mail sending / receiving works but it seems fail2ban is not able to ban ips with this configuration. Even if I add ips manually using setup fail2ban ban, I still see many connection attempts from the banned ips.
Can anyone point me into the right direction how to change the fail2ban configuration in a way that it works behind Traefik. Or is it not possible at all?
Many thanks!
Beta Was this translation helpful? Give feedback.
All reactions