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. 29, 2016, 10:48 a.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 # Provisions a jail.local adjacent to the default configuration. 8 # Provisions a jail.local adjacent to the default configuration.
9 # By default entries will have the following parameters: 9 # By default entries will have the following parameters:
10 # 'enabled' => 'true', 10 # 'enabled' => 'true',
11 # 'port' => 'all', 11 # 'port' => 'all',
12 # 'maxretry' => 6, 12 # 'maxretry' => 6,
13 # 'banaction' => 'iptables-allports', 13 # 'banaction' => 'iptables-allports',
14 # 'bantime' => 3600, 14 # 'bantime' => 3600,
15 # 15 #
16 # For the default banaction iptables-allports, the port parameter 16 # For the default banaction iptables-allports, the port parameter
17 # is not used and only set here for documentation purposes. Note 17 # is not used and only set here for documentation purposes. Note
18 # that if 'banaction' is set to iptables-multiport, it requires that 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 . 19 # the 'port' parameter contains one or more comma-separated ports or protocols .
20 # 20 #
21 # [*package*] 21 # [*package*]
22 # 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.
23 # ensure => 'latest') or remove fail2ban (ensure => 'absent' or 'purged') 23 # ensure => 'latest') or remove fail2ban (ensure => 'absent' or 'purged')
24 # 24 #
25 # [*service*] 25 # [*service*]
26 # Overwrite the default service options. 26 # Overwrite the default service options.
27 # 27 #
28 # [*filters*] 28 # [*filters*]
29 # Adds adittional filters to the filters.d folder. 29 # Adds adittional filters to the filters.d folder.
30 #
30 # === Examples: 31 # === Examples:
31 # 32 #
32 # class {'fail2ban': 33 # class {'fail2ban':
33 # package => {ensure => 'present',}, 34 # package => {ensure => 'present',},
34 # service => {}, 35 # service => {},
35 # jail_config => { 36 # jails => {
36 # 'CVE-2013-0235' => { 37 # 'CVE-2013-0235' => {
37 # 'logpath' => '/var/log/nginx/access_log_hg', 38 # 'logpath' => '/var/log/nginx/access_log_hg',
38 #» 'banaction' => 'iptables-multiport', 39 # 'banaction' => 'iptables-multiport',
39 #» 'port' => 'https, http', 40 # 'port' => 'https, http',
f.nicolaisen 2016/11/29 11:01:05 lines not aligned?
40 # } 41 # }
41 # }, 42 # },
42 # filters => { 43 # filters => {
43 # 'CVE-2013-0235' => { 44 # 'CVE-2013-0235' => {
44 # failregex => [ 45 # regexes => [
45 # '^<HOST>.*\"WordPress\/.*', 46 # '^<HOST>.*\"WordPress\/.*',
46 # ], 47 # ],
47 # } 48 # }
48 # }, 49 # },
49 # } 50 # }
51 #
50 class fail2ban ( 52 class fail2ban (
51 $package = {}, 53 $package = hiera('fail2ban::package', {}),
52 $service = {}, 54 $service = hiera('fail2ban::service', {}),
53 $jail_config = {}, 55 $jails = hiera('fail2ban::jails', {}),
54 $filters = {}, 56 $filters = hiera('fail2ban::filters', {}),
55 ) { 57 ) {
56 58
57 include stdlib 59 include stdlib
58 60
59 $jail_default = { 61 $jail_default = {
60 'enabled' => 'true', 62 'enabled' => 'true',
61 'port' => 'all', 63 'port' => 'all',
62 'maxretry' => 6, 64 'maxretry' => 6,
63 'banaction' => 'iptables-allports', 65 'banaction' => 'iptables-allports',
64 'bantime' => 3600, 66 'bantime' => 3600,
65 } 67 }
66 68
67 ensure_resource('package', $title, $package) 69 ensure_resource('package', $title, $package)
68 70
69 # Used as default $ensure parameter for most resources below
70 $ensure = getparam(Package[$title], 'ensure') ? { 71 $ensure = getparam(Package[$title], 'ensure') ? {
71 /^(absent|purged)$/ => 'absent', 72 /^(absent|purged)$/ => 'absent',
72 default => 'present', 73 default => 'present',
73 } 74 }
74 75
75 # Service resources don't properly support the concept of absence
76 if ($ensure == 'present') { 76 if ($ensure == 'present') {
77 77
78 ensure_resource('service', $title, $service) 78 ensure_resource('service', $title, merge({
79 hasrestart => true,
80 hasstatus => true,
81 }, $service))
82
79 # See modules/fail2ban/manifests/filter.pp 83 # See modules/fail2ban/manifests/filter.pp
80 create_resources('fail2ban::filter', $filters) 84 create_resources('fail2ban::filter', $filters)
81 85
82 # Filters already present in the fail2ban distribution can 86 file {'/etc/fail2ban/jail.local':
83 # also be activated. 87 ensure => present,
84 # Another thing to consider is the possibility of 88 group => 'root',
85 # having the filters configured but not activated, so no conf is 89 mode => '0644',
86 # passed. 90 owner => 'root',
f.nicolaisen 2016/11/29 11:01:05 I still don't understand when I should consider th
87 if jail_config != undef { 91 content => template("fail2ban/jail.erb"),
88 file {'/etc/fail2ban/jail.local': 92 notify => Service['fail2ban'],
89 ensure => present, 93 require => Package['fail2ban'],
90 group => 'root',
91 mode => '0644',
92 owner => 'root',
93 content => template("fail2ban/jail.erb"),
94 notify => Service[$title],
95 }
96 } 94 }
97 95
98 Package[$title] -> File['/etc/fail2ban/jail.local'] 96 Package[$title] -> File['/etc/fail2ban/jail.local']
97 Service[$title] <~ Package[$title]
99 } 98 }
100 99
101 } 100 }
101
LEFTRIGHT

Powered by Google App Engine
This is Rietveld