74a650b41527c261c19588e733e5aa0cff20cdf0
[mirror/dsa-puppet.git] / modules / fail2ban / manifests / init.pp
1 class fail2ban {
2         package { 'fail2ban':
3                 ensure => installed,
4         }
5
6         service { 'fail2ban':
7                 ensure  => running,
8         }
9
10         file { '/etc/fail2ban/jail.d/dsa-00-default.conf':
11                 source => 'puppet:///modules/fail2ban/jail/dsa-00-default.conf',
12                 notify  => Service['fail2ban'],
13         }
14
15         @ferm::conf { 'f2b':
16                 content  => @(EOF),
17                                 @hook post  "type fail2ban-client > /dev/null && (fail2ban-client ping > /dev/null && fail2ban-client reload > /dev/null ) || true";
18                                 @hook flush "type fail2ban-client > /dev/null && (fail2ban-client ping > /dev/null && fail2ban-client reload > /dev/null ) || true";
19                                 | EOF
20         }
21
22         @ferm::rule { 'dsa-f2b-setup':
23                 prio        => '005',
24                 description => 'f2b master rule',
25                 chain       => 'INPUT',
26                 domain      => '(ip ip6)',
27                 rule        => 'saddr 0/0 @subchain "dsa-f2b" {}',
28                 notarule    => true,
29         }
30
31         # XXX Maybe this will be automatically done in buster, it is certainly needed in stretch. So maybe:  versioncmp($::lsbmajdistrelease, '9') <= 0
32         concat::fragment { 'dsa-puppet-stuff--fail2ban-cleanup':
33                 target => '/etc/cron.d/dsa-puppet-stuff',
34                 content  => @(EOF)
35                         17 * * * * root python3 -c "import sys, logging; logging.basicConfig(stream=sys.stdout, level=logging.INFO); from fail2ban.server.database import Fail2BanDb; db = Fail2BanDb('/var/lib/fail2ban/fail2ban.sqlite3'); db.purge(); db._db.cursor().execute('VACUUM')"
36                         | EOF
37         }
38
39 }