| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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. |
|
mathias
2016/11/29 13:21:24
Another comment-line (hash-tag in the beginning, o
f.lopez
2016/12/01 09:13:49
Acknowledged.
| |
| 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', |
| 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 # } |
|
mathias
2016/11/29 13:21:25
Another comment-line (hash-tag in the beginning, o
f.lopez
2016/12/01 09:13:50
Acknowledged.
| |
| 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 | |
|
mathias
2016/11/29 13:21:25
There is more than just a service resource taken c
f.lopez
2016/12/01 09:13:49
Acknowledged.
| |
| 76 if ($ensure == 'present') { | 76 if ($ensure == 'present') { |
| 77 | 77 |
| 78 ensure_resource('service', $title, $service) | 78 ensure_resource('service', $title, merge({ |
|
mathias
2016/11/29 13:21:25
What about the $hasrestart and $hasstatus paramete
f.lopez
2016/12/01 09:13:49
We can, indeed, set those params to true
| |
| 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 # One can aslo decide not to configure any extra filters | 88 group => 'root', |
| 85 # so no configuration file would be created then. | 89 mode => '0644', |
| 86 if jail_config != undef { | 90 owner => 'root', |
|
mathias
2016/11/29 13:21:25
This condition should check for empty($jail_config
f.lopez
2016/12/01 09:13:50
You are right, if we iterate over an empty param i
| |
| 87 file {'/etc/fail2ban/jail.local': | 91 content => template("fail2ban/jail.erb"), |
| 88 ensure => present, | 92 notify => Service['fail2ban'], |
| 89 group => 'root', | 93 require => Package['fail2ban'], |
| 90 mode => '0644', | |
| 91 owner => 'root', | |
| 92 content => template("fail2ban/jail.erb"), | |
| 93 notify => Service[$title], | |
| 94 } | |
| 95 } | 94 } |
| 96 | 95 |
| 97 Package[$title] -> File['/etc/fail2ban/jail.local'] | 96 Package[$title] -> File['/etc/fail2ban/jail.local'] |
|
mathias
2016/11/29 13:21:25
A relationship declaring the Service[$title] being
f.lopez
2016/12/01 09:13:49
Acknowledged.
| |
| 97 Service[$title] <~ Package[$title] | |
| 98 } | 98 } |
| 99 | 99 |
| 100 } | 100 } |
| 101 | 101 |
| LEFT | RIGHT |