Add template to manage fail2ban.conf (see #1)

Also corrected some tests and documentation
This commit is contained in:
Javier Bértoli committed 2013-04-29 16:26:21 -03:00
1 parent d213d8408c
commit 3bcea81f82
5 files changed
+64 -28

No files matched your search

+34 -10
View File
@@ -14,7 +14,7 @@
# Can be defined also by the (top scope) variable $fail2ban_myclass # Can be defined also by the (top scope) variable $fail2ban_myclass
# #
# [*source*] # [*source*]
# Sets the content of source parameter for main configuration file # Sets the content of source parameter for main configuration file (fail2ban.conf)
# If defined, fail2ban main config file will have the param: source => $source # If defined, fail2ban main config file will have the param: source => $source
# Can be defined also by the (top scope) variable $fail2ban_source # Can be defined also by the (top scope) variable $fail2ban_source
# #
@@ -79,23 +79,28 @@
# #
# [*jails_file*] # [*jails_file*]
# Path to 'jail.local' file # Path to 'jail.local' file
# Default: /etc/fail2ban/jail.local
# #
# [*jails_config*] # [*jails_config*]
# Define how you want to manage jails configuration: # Define how you want to manage jails configuration:
# "file" - To provide jail.local as a normal file. If you choose this option, # "file" - To provide jail.local as a normal file. If you choose this option,
# set ONE of [*jails_source*] or [*jails_template*] # set ONE of [*jails_source*] or [*jails_template*]
# "concat" - To build it up using different fragments # "concat" - To build it up using different fragments
# - This option, set as default, permits the use of the fail2ban::jail define # - This option, (preferred), permits the use of the fail2ban::jail define
# Default: empty. Uses "jail.local" from distribution, if any.
# #
# [*jails_source*] # [*jails_source*]
# Sets the content of source parameter for the jail.local configuration file # Sets the content of source parameter for the jail.local configuration file
# Note that single stanzas of jail.local can be managed by fail2ban::jails
# #
# [*jails_template*] # [*jails_template*]
# Sets the path to the template to use as content for the jail.local configuration file # Sets the path to the template to use as content for the jail.local configuration file
# If defined, fail2ban jails config file has: content => content("$jails_template") # If defined, fail2ban jails config file has: content => content("$jails_template")
# Note source and template parameters are mutually exclusive: don't use both # Note source and template parameters are mutually exclusive: don't use both
# #
# [*jails*]
# When using [*jails_template*] you can have some control on what jail is enabled or not
# setting an array named "jails", containing the names of the jail you want enabled.
#
# [*jails_template_header*] # [*jails_template_header*]
# Path to the template to use as header with concat # Path to the template to use as header with concat
# Used by fail2ban::jails # Used by fail2ban::jails
@@ -112,7 +117,7 @@
# Default: INPUT # Default: INPUT
# #
# [*options*] # [*options*]
# An hash of custom options to be used in templates for arbitrary settings. # A hash of custom options to be used in templates for arbitrary settings.
# Can be defined also by the (top scope) variable $fail2ban_options # Can be defined also by the (top scope) variable $fail2ban_options
# #
# [*service_autorestart*] # [*service_autorestart*]
@@ -236,8 +241,20 @@
# [*log_dir*] # [*log_dir*]
# Base logs directory. Used by puppi # Base logs directory. Used by puppi
# #
# [*log_level*]
# Set the log level output.
# 1 = ERROR
# 2 = WARN
# 3 = INFO
# 4 = DEBUG
# Default: 3
#
# [*log_file*] # [*log_file*]
# Log file(s). Used by puppi # Log file(s). Used by puppi also.
#
# [*socket*]
# Socket file used by fail2ban-client to communicate with fail2ban.
# Default: /var/run/fail2ban/fail2ban.sock
# #
# == Examples # == Examples
# #
@@ -247,7 +264,6 @@
# #
# See README for details. # See README for details.
# #
#
# == Author # == Author
# Alessandro Franceschi <al@lab42.it/> # Alessandro Franceschi <al@lab42.it/>
# Javier Bertoli <javier@netmanagers.com.ar/> # Javier Bertoli <javier@netmanagers.com.ar/>
@@ -292,6 +308,8 @@ class fail2ban (
$data_dir = params_lookup( 'data_dir' ), $data_dir = params_lookup( 'data_dir' ),
$log_dir = params_lookup( 'log_dir' ), $log_dir = params_lookup( 'log_dir' ),
$log_file = params_lookup( 'log_file' ), $log_file = params_lookup( 'log_file' ),
$log_level = params_lookup( 'log_level' ),
$socket = params_lookup( 'socket' ),
$ignoreip = params_lookup( 'ignoreip' ), $ignoreip = params_lookup( 'ignoreip' ),
$bantime = params_lookup( 'bantime' ), $bantime = params_lookup( 'bantime' ),
$findtime = params_lookup( 'findtime' ), $findtime = params_lookup( 'findtime' ),
@@ -421,7 +439,16 @@ class fail2ban (
# How to manage fail2ban jail.local configuration # How to manage fail2ban jail.local configuration
case $fail2ban::jails_config { case $fail2ban::jails_config {
'concat': { include fail2ban::jailsconcat }
'file': { 'file': {
$array_jails = is_array($fail2ban::jails) ? {
false => $fail2ban::jails ? {
'' => [],
default => [$fail2ban::jails],
},
default => $fail2ban::jails,
}
$manage_file_jails_source = $fail2ban::jails_source ? { $manage_file_jails_source = $fail2ban::jails_source ? {
'' => undef, '' => undef,
default => $fail2ban::jails_source, default => $fail2ban::jails_source,
@@ -431,7 +458,7 @@ class fail2ban (
'' => undef, '' => undef,
default => template($fail2ban::jails_template), default => template($fail2ban::jails_template),
} }
file { 'jail.local': file { 'jail.local':
ensure => $fail2ban::manage_file, ensure => $fail2ban::manage_file,
path => $fail2ban::jails_file, path => $fail2ban::jails_file,
@@ -446,9 +473,6 @@ class fail2ban (
audit => $fail2ban::manage_audit, audit => $fail2ban::manage_audit,
noop => $fail2ban::bool_noops, noop => $fail2ban::bool_noops,
} }
}
'concat': { include fail2ban::jailsconcat
} }
default: { } default: { }
} }
+5 -2
View File
@@ -103,6 +103,9 @@ class fail2ban::params {
default => '/var/log/fail2ban/fail2ban.log', default => '/var/log/fail2ban/fail2ban.log',
} }
$log_level = '3'
$socket = '/var/run/fail2ban/fail2ban.sock'
$ignoreip = ['127.0.0.1/8'] $ignoreip = ['127.0.0.1/8']
$bantime = '600' $bantime = '600'
$findtime = '600' $findtime = '600'
@@ -114,7 +117,7 @@ class fail2ban::params {
$jails_protocol = 'tcp' $jails_protocol = 'tcp'
$jails_chain = 'INPUT' $jails_chain = 'INPUT'
$jails = [] $jails = ''
$jails_source = '' $jails_source = ''
$jails_template = '' $jails_template = ''
$jails_template_header = 'fail2ban/concat/jail.local-header.erb' $jails_template_header = 'fail2ban/concat/jail.local-header.erb'
@@ -123,9 +126,9 @@ class fail2ban::params {
# General Settings # General Settings
$my_class = '' $my_class = ''
$source = '' $source = ''
$template = ''
$source_dir = '' $source_dir = ''
$source_dir_purge = false $source_dir_purge = false
$template = ''
$options = '' $options = ''
$service_autorestart = true $service_autorestart = true
$version = 'present' $version = 'present'
+8 -7
View File
@@ -25,19 +25,20 @@ describe 'fail2ban' do
end end
describe 'Test jails managed throuh file - template' do describe 'Test jails managed throuh file - template' do
let(:facts) { {:operatingsystem => 'Debian' } }
let(:params) { {:jails_config => 'file', :jails_template => 'fail2ban/jail.local.erb', :jails => 'ssh' } }
it { should contain_file('jail.local').without_source }
it { should contain_file('jail.local').with_content(/"*ssh-iptables]
enabled = true*/) }
end
describe 'Test jails managed throuh file - custom template' do
let(:params) { {:jails_config => 'file', :jails_template => 'fail2ban/spec.erb', :options => { 'opt_a' => 'value_a' } } } let(:params) { {:jails_config => 'file', :jails_template => 'fail2ban/spec.erb', :options => { 'opt_a' => 'value_a' } } }
it { should contain_file('jail.local').with_content(/fqdn: rspec.example42.com/) } it { should contain_file('jail.local').with_content(/fqdn: rspec.example42.com/) }
it { should contain_file('jail.local').without_source } it { should contain_file('jail.local').without_source }
it { should contain_file('jail.local').with_content(/value_a/) } it { should contain_file('jail.local').with_content(/value_a/) }
end end
# describe 'Test jails managed throuh concat' do
# let(:params) { {:jails_config => 'concat' } }
# it { should include_class('fail2ban::jailsconcat') }
# it { should contain_fail2ban__jailsconcat() }
#
# end
describe 'Test installation of a specific version' do describe 'Test installation of a specific version' do
let(:params) { {:version => '1.0.42' } } let(:params) { {:version => '1.0.42' } }
it { should contain_package('fail2ban').with_ensure('1.0.42') } it { should contain_package('fail2ban').with_ensure('1.0.42') }
+8
View File
@@ -0,0 +1,8 @@
# This file is managed by Puppet. DO NOT EDIT.
#
[Definition]
loglevel = <%= scope.lookupvar('fail2ban::log_level') %>
logtarget = <%= scope.lookupvar('fail2ban::log_file') %>
socket = <%= scope.lookupvar('fail2ban::socket') %>
+9 -9
View File
@@ -1,13 +1,13 @@
# This file is managed by Puppet. DO NOT EDIT. # This file is managed by Puppet. DO NOT EDIT.
[DEFAULT] [DEFAULT]
ignoreip = 127.0.0.1 ignoreip = <%= scope.lookupvar('fail2ban::ignoreip') %>
bantime = 600 bantime = <%= scope.lookupvar('fail2ban::bantime') %>
findtime = 600 findtime = <%= scope.lookupvar('fail2ban::findtime') %>
maxretry = 3 maxretry = <%= scope.lookupvar('fail2ban::maxretry') %>
backend = auto backend = <%= scope.lookupvar('fail2ban::backend') %>
[imap-iptables] [imap-iptables]
enabled = <%= scope.lookupvar('fail2ban::jails').include? "imap" %> enabled = <%= scope.lookupvar('fail2ban::array_jails').include? "imap" %>
filter = dovecot filter = dovecot
action = iptables[name=IMAP, port=imap, protocol=tcp] action = iptables[name=IMAP, port=imap, protocol=tcp]
<% unless scope.lookupvar('fail2ban::mailto').empty? -%> <% unless scope.lookupvar('fail2ban::mailto').empty? -%>
@@ -17,7 +17,7 @@ logpath = /var/log/maillog
maxretry = 5 maxretry = 5
[pop3-iptables] [pop3-iptables]
enabled = <%= scope.lookupvar('fail2ban::jails').include? "pop3" %> enabled = <%= scope.lookupvar('fail2ban::array_jails').include? "pop3" %>
filter = mail filter = mail
action = iptables[name=POP3, port=pop3, protocol=tcp] action = iptables[name=POP3, port=pop3, protocol=tcp]
<% unless scope.lookupvar('fail2ban::mailto').empty? -%> <% unless scope.lookupvar('fail2ban::mailto').empty? -%>
@@ -27,7 +27,7 @@ logpath = /var/log/maillog
maxretry = 5 maxretry = 5
[ssh-iptables] [ssh-iptables]
enabled = <%= scope.lookupvar('fail2ban::jails').include? "ssh" %> enabled = <%= scope.lookupvar('fail2ban::array_jails').include? "ssh" %>
filter = sshd filter = sshd
action = iptables[name=SSH, port=ssh, protocol=tcp] action = iptables[name=SSH, port=ssh, protocol=tcp]
<% unless scope.lookupvar('fail2ban::mailto').empty? -%> <% unless scope.lookupvar('fail2ban::mailto').empty? -%>
@@ -41,7 +41,7 @@ logpath = /var/log/secure
maxretry = 5 maxretry = 5
[vsftpd-iptables] [vsftpd-iptables]
enabled = <%= scope.lookupvar('fail2ban::jails').include? "vsftpd" %> enabled = <%= scope.lookupvar('fail2ban::array_jails').include? "vsftpd" %>
filter = vsftpd filter = vsftpd
action = iptables[name=VSFTPD, port=ftp, protocol=tcp] action = iptables[name=VSFTPD, port=ftp, protocol=tcp]
<% unless scope.lookupvar('fail2ban::mailto').empty? -%> <% unless scope.lookupvar('fail2ban::mailto').empty? -%>