Project

General

Profile

HowTo Configure Fail2ban For Redmine » History » Version 4

Jan Catrysse, 2021-06-08 13:57
Otherwise fail2ban fails on blank lines with only whitespace

1 1 David Siewert
h1. HowTo Configure Fail2ban For Redmine
2
3
4
h2. Install
5
6
install fail2ban with apt-get if not installed ( or use yum, pacman or another package manager)
7
8
<pre>
9
 apt-get install fail2ban
10
</pre>
11
12
13
h2. Configure
14
15
create a new file in /etc/fail2ban/filter.d/redmine.conf
16
explanation: here we create our new filter to match failed login attempts
17
18
<pre>
19
# redmine configuration file
20
#
21
# Author: David Siewert
22
#
23
# $Revision$
24
#
25 4 Jan Catrysse
[INCLUDES]
26
27
# Read common prefixes. If any customizations available -- read them from
28
# common.local
29
before = common.conf
30 1 David Siewert
 
31
[Definition]
32
 
33
failregex = Failed [-/\w]+ for .* from <HOST>
34
 
35
# Option:  ignoreregex
36
# Notes.:  regex to ignore. If this regex matches, the line is ignored.
37
# Values:  TEXT
38
#
39
ignoreregex =
40
41
# Source:
42
#http://www.fail2ban.org/wiki/index.php/MANUAL_0_8
43
</pre>
44
45
46
47
48
add following lines somewhere in your /etc/fail2ban/jail.conf
49 3 David Siewert
explanation: here we enable our newly created filter and add some configuration options
50 1 David Siewert
<pre>
51
[redmine]
52
enabled  = true
53
filter   = redmine
54
port     = 80,443
55
#backend  = polling
56
action   = iptables-allports[name=redmine]
57
logpath  = /var/log/redmine/default/production.log
58
maxretry = 5
59
findtime = 7320
60
bantime  = 7320
61
</pre>
62
63
note 1:
64
if you our web server uses local time, then you need to increase findtime and bantime accordingly to the drift in comparison to UTC time
65
in my example configuration i used 2 h + 2 minutes = 3600 * 2 +120  = 7320,
66 2 David Siewert
because my local server time was always 2 hours earlier and i added 2 minutes just in case
67 1 David Siewert
68
69
note 2:
70
if you do not use redmine in production mode, then you need to change the logpath as well
71
72
note 3:
73
if this configuration does not work, you can try uncommenting "backend  = polling"
74
75
h2. Test
76
77
78
if you make any changes, you can check the syntax with:
79
80
<pre>
81
fail2ban-regex /var/log/redmine/default/production.log /etc/fail2ban/filter.d/redmine.conf 
82
</pre>
83
84
85
finally start/restart fail2ban
86
87
<pre>
88
/etc/init.d/fail2ban restart
89
</pre>
90
91
and test if you can get yourself banned :)
92
note: your failed login attempts need to match the maxretry value in /etc/fail2ban/jail.conf