f4f7b9fd08d2f7c9bb64a8645e3d53c0eee961ba
[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-setup1':
23                 prio        => '005',
24                 description => 'f2b master rule',
25                 chain       => 'dsa-f2b',
26                 domain      => '(ip ip6)',
27                 rule        => '',
28                 notarule    => true,
29         }
30         ferm::rule { 'dsa-f2b-setup2':
31                 prio        => '005',
32                 description => 'f2b master rule',
33                 chain       => 'INPUT',
34                 domain      => '(ip ip6)',
35                 rule        => 'jump dsa-f2b',
36         }
37
38         # XXX Maybe this will be automatically done in buster, it is certainly needed in stretch. So maybe:  versioncmp($::lsbmajdistrelease, '9') <= 0
39         concat::fragment { 'puppet-crontab--fail2ban-cleanup':
40                 target => '/etc/cron.d/puppet-crontab',
41                 content  => @(EOF)
42                         17 * * * * root chronic 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')"
43                         | EOF
44         }
45
46 }