Skip to content

Fail2ban docs & example#2144

Closed
williamdes wants to merge 2 commits intodocker-mailserver:masterfrom
williamdes:fail2ban
Closed

Fail2ban docs & example#2144
williamdes wants to merge 2 commits intodocker-mailserver:masterfrom
williamdes:fail2ban

Conversation

@williamdes
Copy link
Copy Markdown
Contributor

Description

Added email sending example and added db volume mount phrase.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Improvement (non-breaking change that does improve existing functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation (README.md or the documentation under docs/)
  • If necessary I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

- `fail2ban-jail.cf` -> `/etc/fail2ban/jail.d/user-jail.local`
- `fail2ban-fail2ban.cf` -> `/etc/fail2ban/fail2ban.local`

You might want to make a volume bind for the `fail2ban` db to persist at `/var/lib/fail2ban/fail2ban.sqlite3` between container re-creations.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be confusing, as it's DMS default, to make it this way.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure to understand the action I should take, do you mean that somehow it already persists in a volume ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wrong.

Our default config makes mailstate persistant:

- ./data/mailstate:/var/mail-state

However, if you set ONE_DIR to 1 (which I did), all states (fail2ban etc) are consolidate into this single directory (and preserved during restarts) --> mail-state. This looks like this:

# ll /var/mail-state
drwxrwxr-x  2 root         root     4.0K Feb  1  2021 etc-postsrsd
drwxr-x---  8 amavis       amavis   4.0K Aug 22 22:54 lib-amavis
drwxr-xr-x  2 clamav       dovecot  4.0K May 29 01:01 lib-clamav
drwxr-xr-x  2 root         root     4.0K Aug 22 22:54 lib-dovecot
drwxr-xr-x  2 root         root     4.0K May 14 23:21 lib-fail2ban
drwxr-xr-x  2 postfix      postfix  4.0K Mar  4  2020 lib-postfix
drwx------  2 postgrey     opendkim 4.0K Feb  1  2021 lib-postgrey
drwxr-xr-x  2 root         root     4.0K Aug 24  2020 lib-shared
drwxr-xr-x  5 debian-spamd postgrey 4.0K Mar  5  2020 lib-spamassassin
drwxr-xr-x 20 postfix      root     4.0K Mar  4  2020 spool-postfix

Maybe we should promote ONE_DIR=1 as default.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know, I also use ONE_DIR
Will have to investigate

Comment thread config/fail2ban-jail.cf
Comment on lines +22 to +34

# Email settings

#destemail = [email protected]
#sender = [email protected]
#sendername = fail2ban
#mta = sendmail

# to ban & send an e-mail with whois report to the destemail.
#action = %(action_mw)s

# same as action_mw but also send relevant log lines
#action = %(action_mwl)s
Copy link
Copy Markdown
Member

@casperklein casperklein Aug 22, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did on purpose only include those configuration options in the example config, that we customize for DMS: https://github.com/docker-mailserver/docker-mailserver/blob/master/target/fail2ban/jail.local

In my experience, you don't want an email notification on every ban 😄 Also most public whois servers are rate limited and you likely will be temporary blocked pretty fast.

If you still want to include it, then I suggest (to keep it streamlined) , to add the original comments (from the default configuration) as well:

# Destination email address used solely for the interpolations in
# jail.{conf,local,d/*} configuration files.
destemail = root@localhost

# Sender email address used solely for some actions
sender = root@<fq-hostname>

# E-mail action. Since 0.8.1 Fail2Ban uses sendmail MTA for the
# mailing. Change mta configuration parameter to mail if you want to
# revert to conventional 'mail'.
mta = sendmail

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my experience, you don't want an email notification on every ban smile Also most public whois servers are rate limited and you likely will be temporary blocked pretty fast.

Thanks for letting me know, I will maybe disable whois in production then

I just wanted to document the possibility, maybe should I add this block to the docs page ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fyi: all available configuration options (not only mail stuff) can be easily looked up with

docker exec mailserver cat /etc/fail2ban/jail.conf
docker exec mailserver cat /etc/fail2ban/fail2ban.conf

Then you'll only need to copy/paste the neccesary parts to your custom fail2ban config and adjust them.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good to know, I would not even have guessed that
Will update the docs page

@williamdes
Copy link
Copy Markdown
Contributor Author

williamdes commented Aug 30, 2021

@casperklein casperklein marked this pull request as draft August 30, 2021 10:19
@casperklein casperklein added area/documentation kind/improvement Improve an existing feature, configuration file or the documentation priority/low labels Aug 30, 2021
@georglauterbach georglauterbach added this to the v10.3.0 milestone Sep 19, 2021
@georglauterbach
Copy link
Copy Markdown
Member

@williamdes can you somehow take a bit of time to wrap up this PR? This way, we can have the docs changes for F2B in the v10.2.0 docs ;)

@georglauterbach
Copy link
Copy Markdown
Member

Just FYI: v10.2.0 is roughly to be released Oct 3rd, 2021 :)

@williamdes
Copy link
Copy Markdown
Contributor Author

Just FYI: v10.2.0 is roughly to be released Oct 3rd, 2021 :)

Thanks, I bit overloaded currently

@github-actions github-actions Bot added the Stale label Oct 21, 2021
@github-actions github-actions Bot closed this Nov 1, 2021
@polarathene polarathene removed the Stale label Nov 14, 2021
@polarathene polarathene reopened this Nov 14, 2021
@github-actions
Copy link
Copy Markdown
Contributor

Documentation preview for this PR is ready! 🎉

Built with commit: 9aada36

@polarathene polarathene added the meta/help wanted The OP requests help from others - chime in! :D label Nov 14, 2021
@polarathene polarathene modified the milestones: v10.3.0, v11.0.0 Nov 14, 2021
Copy link
Copy Markdown
Member

@polarathene polarathene left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of thread/review thus far:

  • config/fail2ban-jail.cf should not be altered and instead added as an example in docs for those interested in this functionality (send notification email whenever a ban occurs).
  • docs/content/config/security/fail2ban.md can mention the sqlite DB for persistence, but no actual action is required for this when following existing docs / examples for persisting DMS state.
  • Author additionally expressed interest in documenting sa-learn, while moving the config example to docs as per review feedback.

No action has been taken for some time, nor much interest in this being merged.

@williamdes do you still want to contribute this feature? Otherwise I don't think anyone is going to pick it up. I can leave it open if you think you'll find time for it, if not that's ok and we can close it.

@williamdes williamdes closed this Nov 30, 2021
@williamdes
Copy link
Copy Markdown
Contributor Author

I agree, closing this as I will not find time for it soon

@polarathene polarathene removed this from the v11.0.0 milestone Nov 30, 2021
@polarathene polarathene added the meta/closed due to age or inactivity This issue / PR has been closed due to inactivity label Nov 30, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/documentation kind/improvement Improve an existing feature, configuration file or the documentation meta/closed due to age or inactivity This issue / PR has been closed due to inactivity meta/help wanted The OP requests help from others - chime in! :D priority/low

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants