Skip to content

Commit bc3adc3

Browse files
committed
fail2ban: implement initial filter/action setup for redmine
1 parent 7fef3b2 commit bc3adc3

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

manifests/fail2ban.pp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# == Define: redmine::fail2ban
2+
#
3+
# Fail2ban configuration for redmine. NOTE: name of the resource is
4+
# restricted to 29 - len(fail2ban-rm-) characters => 17
5+
# characters. This is due to a limit on iptable chain names.
6+
#
7+
# === Parameters
8+
#
9+
# [*root_dir*]
10+
# root directory
11+
# [*ports*]
12+
# optional port list - defaults to standard http and https
13+
# [*bantime*]
14+
# see fail2ban::jail
15+
# [*maxretry*]
16+
# see fail2ban::jail
17+
#
18+
# === Examples
19+
#
20+
# redmine::fail2ban { 'redmine.example':
21+
# root_dir => '/srv/www/redmine.example.net',
22+
# }
23+
#
24+
# === Authors
25+
#
26+
# Braiins Systems s.r.o.
27+
#
28+
# === Copyright
29+
#
30+
# Copyright 2015 Braiins Systems s.r.o.
31+
#
32+
define redmine::fail2ban(
33+
$port=['80', '443'],
34+
$bantime=15,
35+
$maxretry=3,
36+
$serveraliases=[],
37+
$root_dir,
38+
) {
39+
$fail2ban_name = "rm-${title}"
40+
# Check the supplied title to prevent exceeding the iptables chain name limit
41+
if size($title) > 17 {
42+
fail("redmine::fail2ban - title '${title}' longer than 17 characters, iptables chain name: '${fail2ban_name}' would exceed iptables limit, make the resource name shorter!")
43+
}
44+
fail2ban::filter { $fail2ban_name:
45+
filterfailregex => 'Failed login for \'.*\' from <HOST> .*$',
46+
} ->
47+
# The jail uses the default iptables multiport ban action
48+
fail2ban::jail { $fail2ban_name:
49+
logpath => "${redmine_rootdir}/current/log/production.log",
50+
bantime => $bantime,
51+
maxretry => $maxretry,
52+
port => $port,
53+
filter => $fail2ban_name,
54+
}
55+
}

0 commit comments

Comments
 (0)