LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 09-18-2018, 05:05 AM   #1
taumeister
Member
 
Registered: Nov 2017
Location: Germany / Bonn
Distribution: Deepin Linux, Debian
Posts: 65

Rep: Reputation: 1
HAPROXY and fail2ban - block IPs


I want to block IP addresses that log on to a web server too often, i.e. call it too often ( no wrong logon )
And I want to do that on HAPROXY itself.

I have The following constellation:
HAPROXY
Web server 1
Web server 2

Apparently I have the problem to create the regex construct correctly.
I see the IP addresses in /var/log/haproxy.log but fail2ban does not lock.
I have been working on this topic since the day before yesterday and my eyes are glowing from reading web pages.

what I see in /var/log/haproxy.log many times is my IP Address that tries to access the mail server, and I simply want to block myself, when I try too often no matter if I sign up wrong or not, the HAPROXY cant see this anyway.

/var/log/haproxy.log
Code:
Sep 18 09:30:03 haproxy haproxy[513]: 37.24.59.146:61844 [18/Sep/2018:09:30:00.890] www_frontend~ mail_cluster/mail 3051/0/0/1/3052 200 321 - - ---- 2/2/0/1/0 0/0 "POST /webapp/kopano.php?service=fingerprint&type=keepalive HTTP/1.1"
1. iptables is configured to accept only 80,443.
2. fail2ban is configured as follows
I have tested many other configurations before..



/etc/fail2ban/jail.local
Code:
..
[haproxy]
# Check /var/log/haproxy.log, then block for 1200 Seconds addresses that made 3 requests in 20 Seconds
enabled  = true
bantime  = 1200
findtime = 10
maxretry = 3
filter   = haproxy
logpath  = /var/log/haproxy.log
port     = 80,443
banaction =  iptables-allports
action = iptables-multiport[name=haproxy,port="http,https", protocol=tcp]
/etc/fail2ban/filter.d/haproxy.conf
Code:
[Definition]

#failregex = ^.*haproxy\[[0-9]+\]: <HOST>:.* "(GET |POST )/Login HTTP/1.1"$
failregex = ^<HOST> -.*"GET.*
ignoreregex =
But no matter how hard I demand the proxy, I'm simply not blocked
Please do me a favor and help me with this, if you have another idea.

Already read:
https://github.com/fail2ban/fail2ban...nfig/jail.conf
https://github.com/fail2ban/fail2ban/issues/1307
https://raymii.org/s/snippets/haprox...addresses.html
https://security.stackexchange.com/q...ts-in-a-second

etc..etc.etc..

EDIT1:

Although I've tried so many configurations, fail2ban just doesn't seem to work.

I slowly get the feeling that what this has to do with is that all the servers are in LXD containers and fail2ban just doesn't have permission to interfere with iptables.


EDIT2:
Ok, confirmed. fail2ban does not have the right to alter iptables in LXC Containers.puhh.
Doesn't anyone work productively with it?
How is something like this properly secured?

Last edited by taumeister; 09-18-2018 at 11:22 AM.
 
Old 10-21-2018, 07:01 AM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
Quote:
Originally Posted by taumeister View Post
Ok, confirmed. fail2ban does not have the right to alter iptables in LXC Containers.
Showing reproducible evidence of that may help fellow LQ members help you. Apart from that: any reason not to implement HAproxy's stick tables for rate limiting?
 
Old 10-22-2018, 10:42 AM   #3
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
Quote:
Originally Posted by taumeister View Post
/etc/fail2ban/jail.local
Code:
..
[haproxy]
findtime = 10
every 10 seconds is a little excessive,
If it takes f2b 11 seconds to scan a file, what do you think happens? f2b constantly running.

When i doubt, use defaults values. (60 in this case)

Just sayin'

Peace
John out.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: How to protect your server with badIPs.com and report IPs with Fail2ban on Debian LXer Syndicated Linux News 0 02-09-2017 06:45 PM
how to get fail2ban to block a single port ? papampi Linux - Security 6 07-26-2012 07:38 AM
Suspicious requests in haproxy log. Need to block. Help? jc_oo12 Linux - Security 2 04-14-2011 08:10 AM
Allow internal ips block external ips Jz87 Linux - Security 10 07-19-2010 09:42 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 07:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration