Fail2ban rules for package

Hi all, somebody ask me if I have a fail2ban rules for Sonerezh. I explain.

I’ve installed Sonerezh (https://www.sonerezh.bzh/) , via the Yunohost package https://github.com/YunoHost-Apps/sonerezh_ynh As you can see, Sonerezh doesn’t use the Yunohost user, it needs an account creation. I’ve update Sonerezh manually (the actual version is 1.1.3, the Yunohost package provided the 1.1.1 version, i’ve submitted an issue https://github.com/YunoHost-Apps/sonerezh_ynh/issues/) So now, an URL address like mycloud.com/sonerezh/login is available (I’m not automatically redirected to Yunohost login if I’m not logged).

How can I :

  • add the redirection to mycloud.com (Yunohost default login) if I’m not logged in Yunohost, in order to hide the mycloud.com/sonerezh/login until I’m logged in Yunohost
  • add a fail2ban rules dedicated to sonerezh login page.

Thanks for your help :slight_smile:

Some submitted me this and other people confirm it works. Already implemented on my server, need to confirm it works (fail2ban is stard, don’t want to block myself so I need to test it on a virtual machine)

In the folder /etc/fail2ban/filter.d/ create a sonerezh.conf file

[Definition]
failregex = Error: Failed authentication .*. from
ignoreregex =

New rule to add to jail.conf file

[sonerezh]
enabled = true
port = http,https
filter = sonerezh
logpath = /var/log/nginx/sonerezh.mydomain-error.log
maxretry = 4

Hi it seems you missed the end of the failregex, you need to put the host to found in your failregex
Maybe like this :

Error: Failed authentication ...... from [192.168.1.20]
You need to use your failregex like this : 
Error: Failed authentication .*. from \[<HOST>\]
If the log is like this : 
Error: Failed authentication ...... from (192.168.1.20)
You need to use your failregex like this : 
Error: Failed authentication .*. from \(<HOST>\)

For the regex rules ( fail2ban is a Python program ) use this link for french http://apprendre-python.com/page-expressions-regulieres-regular-python