Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: modules/fail2ban/manifests/init.pp

Issue 29364214: Issue 2487 - Introduce fail2ban module (Closed)
Left Patch Set: Issue 2487 - Introduce fail2ban module Created Nov. 25, 2016, 3:17 p.m.
Right Patch Set: For comment 22 and 23 Created Dec. 2, 2016, 2:22 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « modules/fail2ban/manifests/filter.pp ('k') | modules/fail2ban/templates/filter.erb » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # == Class: fail2ban 1 # == Class: fail2ban
2 # 2 #
3 # Create and maintain fail2ban (http://www.fail2ban.org/) setups. 3 # Create and maintain fail2ban (http://www.fail2ban.org/) setups.
4 # 4 #
5 # == Parameters: 5 # == Parameters:
6 # 6 #
7 # [*jail_config*] 7 # [*jails*]
8 # Adds jail.local to the default configuration of fail2ban 8 # Provisions a jail.local adjacent to the default configuration.
9 # By default entries will have the following parameters:
10 # 'enabled' => 'true',
11 # 'port' => 'all',
12 # 'maxretry' => 6,
13 # 'banaction' => 'iptables-allports',
14 # 'bantime' => 3600,
15 #
16 # For the default banaction iptables-allports, the port parameter
17 # is not used and only set here for documentation purposes. Note
18 # that if 'banaction' is set to iptables-multiport, it requires that
19 # the 'port' parameter contains one or more comma-separated ports or protocols .
9 # 20 #
10 # [*package*] 21 # [*package*]
11 # Overwrite the default package options, to fine-tune the target version (i.e. 22 # Overwrite the default package options, to fine-tune the target version (i.e.
12 # ensure => 'latest') or remove fail2ban (ensure => 'absent' or 'purged') 23 # ensure => 'latest') or remove fail2ban (ensure => 'absent' or 'purged')
13 # 24 #
14 # [*service*] 25 # [*service*]
15 # Overwrite the default service options. 26 # Overwrite the default service options.
16 # 27 #
17 # [*filters*] 28 # [*filters*]
18 # Adds adittional filters to the filters.d folder 29 # Adds adittional filters to the filters.d folder.
30 #
19 # === Examples: 31 # === Examples:
20 # 32 #
21 # class {'fail2ban': 33 # class {'fail2ban':
22 # package => {ensure => 'present',}, 34 # package => {ensure => 'present',},
23 # service => {}, 35 # service => {},
24 # jail_config => { 36 # jails => {
f.nicolaisen 2016/11/25 16:23:29 We should require setting a port here, and if not
f.lopez 2016/11/25 17:41:10 That is the actual motive for this kinda of config
25 # 'wordpress' => { 37 # 'CVE-2013-0235' => {
26 # logpath => '/var/log/nginx/access.log', 38 # 'logpath' => '/var/log/nginx/access_log_hg',
27 # }, 39 # 'banaction' => 'iptables-multiport',
28 # }, 40 # 'port' => 'https, http',
29 # filters => { 41 # }
30 # 'wordpress' => { 42 # },
31 # failregex => [ 43 # filters => {
32 # '^<HOST>.*\"WordPress\/.*', 44 # 'CVE-2013-0235' => {
33 # ], 45 # regexes => [
34 # } 46 # » '^<HOST>.*\"WordPress\/.*',
35 # }, 47 # » ],
36 # } 48 # }
49 # },
50 # }
51 #
37 class fail2ban ( 52 class fail2ban (
38 $package = hiera('fail2ban::package', 'present'), 53 $package = hiera('fail2ban::package', {}),
39 $service = hiera('fail2ban::service', {}), 54 $service = hiera('fail2ban::service', {}),
40 $jail_config = hiera('fail2ban::jail_config', {}), 55 $jails = hiera('fail2ban::jails', {}),
41 $filters = hiera('fail2ban::filters', {}), 56 $filters = hiera('fail2ban::filters', {}),
42 ) { 57 ) {
43 58
44 include stdlib 59 include stdlib
45 60
46 ensure_resource('package', $title, {ensure => $package}) 61 $jail_default = {
62 'enabled' => 'true',
63 'port' => 'all',
64 'maxretry' => 6,
65 'banaction' => 'iptables-allports',
66 'bantime' => 3600,
67 }
47 68
48 # Used as default $ensure parameter for most resources below 69 ensure_resource('package', $title, $package)
70
49 $ensure = getparam(Package[$title], 'ensure') ? { 71 $ensure = getparam(Package[$title], 'ensure') ? {
50 /^(absent|purged)$/ => 'absent', 72 /^(absent|purged)$/ => 'absent',
51 default => 'present', 73 default => 'present',
52 } 74 }
53 75
54 # Service resources don't properly support the concept of absence
55 if ($ensure == 'present') { 76 if ($ensure == 'present') {
56 77
57 ensure_resource('service', $title, $service) 78 ensure_resource('service', $title, merge({
79 hasrestart => true,
80 hasstatus => true,
81 }, $service))
82
58 # See modules/fail2ban/manifests/filter.pp 83 # See modules/fail2ban/manifests/filter.pp
59 create_resources('fail2ban::filter', $filters) 84 create_resources('fail2ban::filter', $filters)
60 85
61 # According to the docs one can also enable filters that are 86 file {'/etc/fail2ban/jail.local':
62 # already in there, so the config file should be done indepentently 87 ensure => present,
63 # of the filters, another thing to consider is the possibility of 88 group => 'root',
64 # having the filters configured but not activated, so no conf is 89 mode => '0644',
65 # passed. 90 owner => 'root',
66 if jail_config != undef { 91 content => template("fail2ban/jail.erb"),
67 file {'/etc/fail2ban/jail.local': 92 notify => Service['fail2ban'],
f.nicolaisen 2016/11/25 16:23:29 Like stated earlier, if no ports have been configu
68 ensure => present, 93 require => Package['fail2ban'],
69 group => 'root',
70 mode => '0644',
71 owner => 'root',
72 content => template("fail2ban/jail.erb"),
73 notify => Service[$title],
74 }
75 } 94 }
76 95
77 Package[$title] -> File['/etc/fail2ban/jail.local'] 96 Package[$title] -> File['/etc/fail2ban/jail.local']
78 97 Service[$title] <~ Package[$title]
79 } 98 }
80 99
81 } 100 }
101
LEFTRIGHT

Powered by Google App Engine
This is Rietveld