nginx-proxy-manager icon indicating copy to clipboard operation
nginx-proxy-manager copied to clipboard

[Request] Add Fail2Ban

Open lordraiden opened this issue 5 years ago • 60 comments

Please consider fail2ban https://www.fail2ban.org/wiki/index.php/Main_Page

and a 2 step verification method https://www.authelia.com/  https://github.com/clems4ever/authelia

BTW your software is being a total sucess here https://forums.unraid.net/topic/76460-support-djoss-nginx-proxy-manager/

lordraiden avatar Dec 25 '18 23:12 lordraiden

I agree on the fail2ban, I can see 2fa being good if it is going to be externally available. Big thing if you implement f2b, make sure it will pay attention to the forwarded-for IP. That way you don't end up blocking cloudflare.

I switched away from that docker container actually simply because it wasn't up-to-date enough for me. I needed the latest features such as the ability to forward HTTPS enabled sites.

vrelk avatar Dec 31 '18 22:12 vrelk

@lordraiden Thanks for the heads up, makes sense why so many issues being logged in the last 2 weeks! F2B is definitely a good improvement to be considered.

@vrelk Upstream SSL hosts support is done, in the next version I'll release today. Is that the only thing you needed that the docker version couldn't do?

jc21 avatar Jan 03 '19 04:01 jc21

@jc21 I guess I should have specified that I was referring to the docker container linked in the first post (unRAID). It is a few months out of date. My switch was from the jlesage fork to yours.

vrelk avatar Jan 05 '19 03:01 vrelk

please add fail2ban. otherwise you have a great software!

macshack76 avatar Mar 03 '19 03:03 macshack76

+1 for f2b!

WesSec avatar Mar 26 '19 14:03 WesSec

@jc21 Is there any new about the fail2ban addition?

lordraiden avatar Apr 24 '19 15:04 lordraiden

also voting for fail2ban 👍 Would be great

1337hium avatar May 09 '19 06:05 1337hium

Would also like fail2ban!

Fiala06 avatar May 13 '19 22:05 Fiala06

Would be great to have fail2ban built in like the linuxserver/letsencrypt Docker container!

maximberezin97 avatar Jun 25 '19 18:06 maximberezin97

Would also love to see fail2ban, or in the meantime, if anyone has been able to get it working manually and can share their setup/script

ghost avatar Jun 28 '19 17:06 ghost

Is there a (manual) way to use Nginx-proxy-manager reverse proxies in combination with Authelia 2FA? I love the proxy manager's interface and ease of use, and would like to use it together with a authentication service.

Elmardus avatar Jul 16 '19 15:07 Elmardus

+1 for both fail2ban and 2fa support. I would rank fail2ban as a primary concern and 2fa as a nice to have. With both of those features added i think this solution would be ready for smb production environments.

jsternadel avatar Sep 03 '19 16:09 jsternadel

+1 for fail2ban support.

neander avatar Oct 12 '19 11:10 neander

+1 for fail2ban too !

slobberbone avatar Oct 19 '19 10:10 slobberbone

Some update on fail2ban, since I don't see this happening anytime soon, I created a fail2ban filter myself. Create a file called "nginx-docker" in /etc/fail2ban/filder.d with the following contents

[INCLUDES]  

[Definition]  

failregex = ^<HOST>.+" (4\d\d|3\d\d) (\d\d\d|\d) .+$
            ^.+ 4\d\d \d\d\d - .+ \[Client <HOST>\] \[Length .+\] ".+" .+$

This will jail all requests that return a 4xx/3xx code on the main ip or a 400 on the specified hosts in the docker (no 300 here because of redirects used to force HTTPS)

enable the jail in the jail.local file:

[nginx-docker]
enabled = true
logpath = <docker-config-location>/nginx-proxy-manager/data/logs/default_host.log
          <docker-config-location>/nginx-proxy-manager/data/logs/proxy_host-*.log
maxretry = 3
bantime  = 360
findtime = 60

The only issue is that docker sort of bypasses all iptables entries, fail2ban makes the entry but those are ignored by docker, resulting in having the correct rule in iptables or ufw, but not actually blocking the IP. Maybe someone in here has a solution for this.

WesSec avatar Oct 22 '19 10:10 WesSec

wessel145 - I have played with the same problem ( docker ip block ) few days :) finally I have working solution;

  1. in /etc/docker/daemon.json - you need to add option "iptables": true
  2. you need to be sure docker create chain in iptables DOCKER-USER
  3. for fail2ban ( docker port ) use SINGLE PORT ONLY - custom action.d/customaction.conf --ctorigdstport !!! mine looks like this and it works customaction.conf [INCLUDES] before = iptables-common.conf [Definition] actionstart = -N f2b- -A f2b- -j -I DOCKER-USER -p -m conntrack --ctorigdstport --ctdir ORIGINAL -j f2b-

actionstop = -D DOCKER-USER -p -m conntrack --ctorigdstport --ctdir ORIGINAL -j f2b- -X f2b- actioncheck = -n -L DOCKER-USER | grep -q 'f2b-[ \t]' actionban = -I f2b- 1 -s -j actionunban = -D f2b- -s -j [Init]

  1. in your jail add action [nginx-docker] enabled = true logpath = /nginx-proxy-manager/data/logs/default_host.log /nginx-proxy-manager/data/logs/proxy_host-*.log

banaction = customaction

maxretry = 3 bantime = 360 findtime = 60

NOTE: for docker to ban port need to use single port and option iptables -m conntrack --ctorigdstport --ctdir ORIGINAL

dariusateik avatar Oct 22 '19 22:10 dariusateik

my personal opinion nginx-proxy-manager should be ONLY nginx-proxy-manager ; as with docker concept fail2ban and etc, etc, you can have as separate containers; better to have one good nginx-proxy-manager without mixing; jc21/nginx-proxy-manager made nice job. ! thanks

dariusateik avatar Oct 22 '19 22:10 dariusateik

@dariusateik i do not agree on that since the letsencrypt docker container also comes with fail2ban, 'all reverse proxy traffic' will go through this container and is therefore a good place to handle fail2ban.

WesSec avatar Dec 10 '19 12:12 WesSec

@dariusateik the other side of docker containers is to make deployment easy. Currently fail2ban doesn't play so well sitting in the host OS and working with a container. Setting up fail2ban is also a bit more advanced then firing up the nginx-proxy-manager container and using a UI to easily configure subdomains. Having f2b inside the npm container and pre-configured, similiar to the linuxio container, gives end users without experience in building jails and filters an extra layer of security. And those of us with that experience can easily tweak f2b to our liking. If you are using volumes and backing them up nightly you can easily move your npm container or rebuild it if necessary. I want to try out this container in a production environment but am hesitant to do so without f2b baked in. In production I need to have security, back ups, and disaster recovery.

jsternadel avatar Dec 10 '19 20:12 jsternadel

@dariusateik the other side of docker containers is to make deployment easy. Currently fail2ban doesn't play so well sitting in the host OS and working with a container. Setting up fail2ban is also a bit more advanced then firing up the nginx-proxy-manager container and using a UI to easily configure subdomains. Having f2b inside the npm container and pre-configured, similiar to the linuxio container, gives end users without experience in building jails and filters an extra layer of security. And those of us with that experience can easily tweak f2b to our liking. If you are using volumes and backing them up nightly you can easily move your npm container or rebuild it if necessary. I want to try out this container in a production environment but am hesitant to do so without f2b baked in. In production I need to have security, back ups, and disaster recovery.

it is always - we could find many "yes" and many "no" ; there is no one answer... If npm will have it - why not; but i am using crazymax/fail2ban for this; more complexing docker, more possible mistakes; configs, etc; how will be or f2b integrated - should decide jc21

dariusateik avatar Dec 10 '19 22:12 dariusateik

Personally I don't understand the fascination with f2b. There's talk about security, but I've worked for multi million dollar companies with massive amounts of sensitive customer data, used by government agencies and never once have we been hacked or had any suspicious attempts to gain access.

And we have never used f2b.

On one hand, this project's goals was for the average joe to be able to easily use HTTPS for their incoming websites; not become a network security specialist. I understand that there are malicious people out there and there are users who want to protect themselves, but is f2b the only way for them to do this?

On the other hand, f2b is easy to add to the docker container. It's the configuration of it that would be hard for the average joe. Anyone who wants f2b can take my docker image and build a new one with f2b installed.

Super secret stuff: I'm not working on v2 anymore, and instead slowly working on v3. I'll be considering all feature requests for this next version.

jc21 avatar Dec 10 '19 22:12 jc21

100 % agree - > ... On the other hand, f2b is easy to add to the docker container

dariusateik avatar Dec 10 '19 23:12 dariusateik

hopping in to say that a 2fa solution (such the the one authelia brings) would be an amazing addition.

Authelia itself doesnt require a LDAP server or its own mysql database, it can use built in single file equivalents just fine for small personal installations

Rami-Pastrami avatar Jan 01 '20 04:01 Rami-Pastrami

Any news on that?

JoschaMiddendorf avatar Mar 30 '20 02:03 JoschaMiddendorf

To y'all looking to use fail2ban with your nginx-proxy-manager in docker here's a tip:

In your jail.local file under where the section (jail) for nginx-http-auth is you need to add this line so when something is banned it routes through iptables correctly with docker:

chain = DOCKER-USER

wtf911 avatar Apr 18 '20 21:04 wtf911

+1 for this thread. Thank jc21, great work!

Nenodema avatar Apr 22 '20 06:04 Nenodema

+1 Any news on this?

johnnny1337 avatar Jul 14 '20 19:07 johnnny1337

+1 Last thing really need as of now. :)

EmmanuelZapata avatar Aug 24 '20 06:08 EmmanuelZapata

+! Fail2ban would be amazing to secure our subdomains!

maxi1134 avatar Sep 04 '20 19:09 maxi1134

Anyone who has a guide how to implement this by myself in the image?

johnnny1337 avatar Oct 05 '20 12:10 johnnny1337