docker-mailserver: [Review/Improve] fail2ban service
Review/Improve Request
Context
At the moment, the fail2ban service seems not to operate optimal.
Is your Feature Request related to a Problem?
At least:
https://github.com/docker-mailserver/docker-mailserver/pull/1661 https://github.com/docker-mailserver/docker-mailserver/issues/1810
Describe the Solution you’d like
The whole fail2ban implementation should be reviewed and optimized.
Are you going to implement it?
No (at least, not in short-term). This is more for tracking/discussing the topic.
What are you going to contribute?
Lifetime 😄
Things to discuss / clarify / To-do
Is#1895https://github.com/docker-mailserver/docker-mailserver/blob/master/target/fail2ban/jail.confstill needed, what was the original intent not to use the default shipped configuration?What services are covered by fail2ban?dovecot, postfix, postfix-saslShould an attacker be blocked completely? Currently, the IP address is only blocked for a specific service. IMHO if someone tries to brute force POP3, the IP address should also be blocked for IMAP etc, or even better completely.Default ban behavior of fail2ban is to REJECT packets. Maybe DROP is better?Check ifupdate-alternatives --set iptables /usr/sbin/iptables-legacy # switch iptables and ip6tables to legacy for Fail2Banfrom Dockerfile is (still) needed
There are probably other things to consider. Just let me know and I’ll keep this list up-to-date.
Possible solutions
Block all ports instead of service port only
sed -i '/^banaction = iptables-multiport$/ s|iptables-multiport|iptables-allports|' /etc/fail2ban/jail.conf
DROP connections instead of REJECT
sed -i 's/^blocktype = REJECT.*/blocktype = DROP/' /etc/fail2ban/action.d/iptables-common.conf
Proposed configuration options
| Variable | Values | Default | Description |
|---|---|---|---|
| FAIL2BAN_BLOCK_TYPE | REJECT, DROP | DROP | iptables block behaviour; REJECT sends ICMP unreachable; DROP sends no reply |
| FAIL2BAN_BLOCK_ALL | true, false | true | If true, block an attacker on all ports, not only the attacked one. |
| FAIL2BAN_BLOCK_PERMANENT | true, false | false | Block an attacker forever |
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Comments: 40 (33 by maintainers)
I am going to close this issue soon, as almost all has been done:
config/fail2ban-jail.cf.$FAIL2BAN_BLOCKTYPE=drop|reject.FAIL2BAN_BLOCK_PERMANENTwas not implemented. This can be easily done, by setting a pretty longbantimeinconfig/fail2ban-jail.cf.The changes are now merged into the master branch, but have not been released yet.
@BlockI0tChain @aendeavor @wernerfred
That would be great. Please test and let me know, if you encounter any problems. I use this setup now for about a week and had no issues so far.
Some things may not be as easy to test locally as they might be against a deployed instance. If you want to test fail2ban rules, that might also apply? (I’m not familiar with f2b much, just regarding IP or domain names)
I had the same problem at the start of the year with my PRs. They’re reasonably well documented I think with comments (the bats tests), although mine differs a bit, I reworked this one too which is more like most tests.
I should be able to assist/guide you with any questions about putting a test together. As the docs are being reworked, this is also a contributing section that needs to be covered, so it’s best to utilize your inexperience with writing the bats tests to get the questions and feedback to help knowing what needs to be covered 😃
I’m not sure if tests can be run via Docker (since they start containers themselves), and I opted to run my tests in a temporary $5/month VPS. You need to be on Linux otherwise I think to run the tests, or use a VM (Ubuntu 20.04) that matches what Github uses.
I recall needing to run a command for cloning over the submodules (bats being one of them) to run, and another for initializing docker-mailserver for testing (dummy accounts) that
makeruns, as per the Github CI workflow we have does.Other than that, it was just making a
test-name.batsfile like I linked to, that describes the docker-mailserver image configuration followed by some@testsections that run commands and assert the result is what you expect for success or failure conditions.As you’re testing new PR, you’d need to additionally build a new Docker image to test against (the tests use
${NAME}) which defaults tomailserver-testing:ci.I can help you with any of that, or any other questions you have 👍
Currently this is defined:
This can be overwritten/extended via
config/fail2ban-jail.cf.Does this site from the docs answer your question?
If available, I’d gladly test any tag/configuration on my env.
The following tasks have to be done (let me know if something is missing):
For the bat tests, I need support from someone else. Also testing should be ideally done by more people. The other stuff I should be able to take care of within the next weeks.
Edit: “Update Docu” added.
I’ve added possible configuration options to my first post, including
BLOCK_PERMANENT.The default ban time is 3 hours and wasn’t subject to change?