Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 117 additions & 4 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
### Data types

* [`Fail2ban::IP`](#Fail2ban--IP): can be a list of IP addresses, CIDR masks or DNS hosts
* [`Fail2ban::Time`](#Fail2ban--Time): Describes time format allowed for bantime and findtime The time entries in fail2ban configuration (like findtime or bantime) can be provided
* [`Fail2ban::Time`](#Fail2ban--Time): Describes time format allowed for bantime and findtime The time entries in fail2ban configuration (like findtime or bantime) can be provided

### Tasks

Expand Down Expand Up @@ -68,11 +68,22 @@ The following parameters are available in the `fail2ban` class:
* [`config_file_template`](#-fail2ban--config_file_template)
* [`config_file_notify`](#-fail2ban--config_file_notify)
* [`config_file_require`](#-fail2ban--config_file_require)
* [`jail_file_path`](#-fail2ban--jail_file_path)
* [`jail_file_template`](#-fail2ban--jail_file_template)
* [`debian_defaults_conf_ensure`](#-fail2ban--debian_defaults_conf_ensure)
* [`el_firewalld_conf_ensure`](#-fail2ban--el_firewalld_conf_ensure)
* [`service_ensure`](#-fail2ban--service_ensure)
* [`service_name`](#-fail2ban--service_name)
* [`service_enable`](#-fail2ban--service_enable)
* [`log_level`](#-fail2ban--log_level)
* [`logtarget`](#-fail2ban--logtarget)
* [`syslogsocket`](#-fail2ban--syslogsocket)
* [`socket`](#-fail2ban--socket)
* [`pidfile`](#-fail2ban--pidfile)
* [`allowipv6`](#-fail2ban--allowipv6)
* [`dbfile`](#-fail2ban--dbfile)
* [`dbpurgeage`](#-fail2ban--dbpurgeage)
* [`dbmaxmatches`](#-fail2ban--dbmaxmatches)
* [`bantime_increment`](#-fail2ban--bantime_increment)
* [`bantime_rndtime`](#-fail2ban--bantime_rndtime)
* [`bantime_maxtime`](#-fail2ban--bantime_maxtime)
Expand Down Expand Up @@ -151,7 +162,7 @@ Data type: `Stdlib::Absolutepath`

Determines if the configuration file should be managed.

Default value: `'/etc/fail2ban/jail.local'`
Default value: `'/etc/fail2ban/fail2ban.local'`

##### <a name="-fail2ban--config_file_owner"></a>`config_file_owner`

Expand Down Expand Up @@ -183,7 +194,7 @@ Data type: `String[1]`

Determines which configuration file template to use.

Default value: `'fail2ban/jail.local.epp'`
Default value: `'fail2ban/fail2ban.local.epp'`

##### <a name="-fail2ban--config_file_notify"></a>`config_file_notify`

Expand All @@ -201,6 +212,22 @@ Determines which package a configuration file depends on.

Default value: `'Package[fail2ban]'`

##### <a name="-fail2ban--jail_file_path"></a>`jail_file_path`

Data type: `Stdlib::Absolutepath`

Determines if the jail configuration file should be managed.

Default value: `'/etc/fail2ban/jail.local'`

##### <a name="-fail2ban--jail_file_template"></a>`jail_file_template`

Data type: `String[1]`

Determines which jail configuration file template to use

Default value: `'fail2ban/jail.local.epp'`

##### <a name="-fail2ban--debian_defaults_conf_ensure"></a>`debian_defaults_conf_ensure`

Data type: `Enum['absent', 'present']`
Expand Down Expand Up @@ -241,6 +268,93 @@ Determines if the service should be enabled at boot.

Default value: `true`

##### <a name="-fail2ban--log_level"></a>`log_level`

Data type: `Optional[Enum['DEBUG','INFO','NOTICE','WARNING','ERROR','CRITICAL']]`

Set the log level output.

Default value: `undef`

##### <a name="-fail2ban--logtarget"></a>`logtarget`

Data type:

```puppet
Optional[Variant[
Enum['STDOUT','STDERR','SYSLOG','SYSOUT', 'SYSTEMD-JOURNAL'],
Stdlib::AbsolutePath
]]
```

Set the log target. This could be a file, SYSTEMD-JOURNAL, SYSLOG, STDERR or STDOUT.
Only one log target can be specified.
If you change logtarget from the default value and you are
using logrotate -- also adjust or disable rotation in the
corresponding configuration file

Default value: `undef`

##### <a name="-fail2ban--syslogsocket"></a>`syslogsocket`

Data type: `Optional[Variant[Enum['auto'],Stdlib::Absolutepath]]`

Set the syslog socket file. Only used when logtarget is SYSLOG
auto uses platform.system() to determine predefined paths

Default value: `undef`

##### <a name="-fail2ban--socket"></a>`socket`

Data type: `Optional[Stdlib::Absolutepath]`

Set the socket file. This is used to communicate with the daemon. Do
not remove this file when Fail2ban runs. It will not be possible to
communicate with the server afterwards.

Default value: `undef`

##### <a name="-fail2ban--pidfile"></a>`pidfile`

Data type: `Optional[Stdlib::Absolutepath]`

Set the PID file. This is used to store the process ID of the
fail2ban server.

Default value: `undef`

##### <a name="-fail2ban--allowipv6"></a>`allowipv6`

Data type: `Optional[Enum['auto','yes','no']]`

Allows IPv6 interface

Default value: `undef`

##### <a name="-fail2ban--dbfile"></a>`dbfile`

Data type: `Optional[Variant[Enum['None',':memory:'],Stdlib::Absolutepath]]`

Set the file for the fail2ban persistent data to be stored.

Default value: `undef`

##### <a name="-fail2ban--dbpurgeage"></a>`dbpurgeage`

Data type: `Optional[Integer[1]]`

Sets age at which bans should be purged from the database

Default value: `undef`

##### <a name="-fail2ban--dbmaxmatches"></a>`dbmaxmatches`

Data type: `Optional[Integer[1]]`

Number of matches stored in database per ticket

Default value: `undef`

##### <a name="-fail2ban--bantime_increment"></a>`bantime_increment`

Data type: `Optional[Boolean]`
Expand Down Expand Up @@ -740,4 +854,3 @@ The jail to operate on
Data type: `Array[Stdlib::IP::Address]`

IP addresses to unban

13 changes: 12 additions & 1 deletion manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
require => $fail2ban::config_file_require,
}

file { 'jail.local':
file { 'fail2ban.local':
ensure => $fail2ban::config_file_ensure,
content => epp($fail2ban::config_file_template),
path => $fail2ban::config_file_path,
Expand All @@ -24,6 +24,17 @@
require => $fail2ban::config_file_require,
}

file { 'jail.local':
ensure => $fail2ban::config_file_ensure,
content => epp($fail2ban::jail_file_template),
path => $fail2ban::jail_file_path,
owner => $fail2ban::config_file_owner,
group => $fail2ban::config_file_group,
mode => $fail2ban::config_file_mode,
notify => $fail2ban::config_file_notify,
require => $fail2ban::config_file_require,
}

# Operating system specific configuration
case $facts['os']['family'] {
'Debian': {
Expand Down
62 changes: 59 additions & 3 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
# @param config_file_require
# Determines which package a configuration file depends on.
#
# @param jail_file_path
# Determines if the jail configuration file should be managed.
#
# @param jail_file_template
# Determines which jail configuration file template to use
#
# @param debian_defaults_conf_ensure
# Determines whether the file `/etc/fail2ban/jail.d/defaults-debian.conf` should be deleted or not.
#
Expand All @@ -51,6 +57,41 @@
# @param service_enable
# Determines if the service should be enabled at boot.
#
# @param log_level
# Set the log level output.
#
# @param logtarget
# Set the log target. This could be a file, SYSTEMD-JOURNAL, SYSLOG, STDERR or STDOUT.
# Only one log target can be specified.
# If you change logtarget from the default value and you are
# using logrotate -- also adjust or disable rotation in the
# corresponding configuration file
#
# @param syslogsocket
# Set the syslog socket file. Only used when logtarget is SYSLOG
# auto uses platform.system() to determine predefined paths
#
# @param socket
# Set the socket file. This is used to communicate with the daemon. Do
# not remove this file when Fail2ban runs. It will not be possible to
# communicate with the server afterwards.
#
# @param pidfile
# Set the PID file. This is used to store the process ID of the
# fail2ban server.
#
# @param allowipv6
# Allows IPv6 interface
#
# @param dbfile
# Set the file for the fail2ban persistent data to be stored.
#
# @param dbpurgeage
# Sets age at which bans should be purged from the database
#
# @param dbmaxmatches
# Number of matches stored in database per ticket
#
# @param bantime_increment
# Increment ban time for previously banned IPs.
#
Expand Down Expand Up @@ -158,25 +199,40 @@
# },
# },
# }
#
#
class fail2ban (
Enum['absent', 'latest', 'present', 'purged'] $package_ensure = 'present',
String[1] $package_name = 'fail2ban',
Optional[Array[String]] $package_list = undef,
Stdlib::Absolutepath $config_dir_path = '/etc/fail2ban',
Boolean $config_dir_purge = false,
Stdlib::Absolutepath $config_file_path = '/etc/fail2ban/jail.local',
Stdlib::Absolutepath $config_file_path = '/etc/fail2ban/fail2ban.local',
String[1] $config_file_owner = 'root',
String[1] $config_file_group = 'root',
String[1] $config_file_mode = '0644',
String[1] $config_file_template = 'fail2ban/jail.local.epp',
String[1] $config_file_template = 'fail2ban/fail2ban.local.epp',
String[1] $config_file_notify = 'Service[fail2ban]',
String[1] $config_file_require = 'Package[fail2ban]',
Stdlib::Absolutepath $jail_file_path = '/etc/fail2ban/jail.local',
String[1] $jail_file_template = 'fail2ban/jail.local.epp',
Enum['absent', 'present'] $debian_defaults_conf_ensure = 'present',
Enum['absent', 'present'] $el_firewalld_conf_ensure = 'present',
Enum['running', 'stopped'] $service_ensure = 'running',
String[1] $service_name = 'fail2ban',
Boolean $service_enable = true,
# ------------------------- fail2ban.local/[DEFAULT] ------------------------- #
Optional[Enum['DEBUG','INFO','NOTICE','WARNING','ERROR','CRITICAL']] $log_level = undef,
Optional[Variant[
Enum['STDOUT','STDERR','SYSLOG','SYSOUT', 'SYSTEMD-JOURNAL'],
Stdlib::AbsolutePath
]] $logtarget = undef,
Optional[Variant[Enum['auto'],Stdlib::Absolutepath]] $syslogsocket = undef,
Optional[Stdlib::Absolutepath] $socket = undef,
Optional[Stdlib::Absolutepath] $pidfile = undef,
Optional[Enum['auto','yes','no']] $allowipv6 = undef,
Optional[Variant[Enum['None',':memory:'],Stdlib::Absolutepath]] $dbfile = undef,
Optional[Integer[1]] $dbpurgeage = undef,
Optional[Integer[1]] $dbmaxmatches = undef,
# --------------------------- jails.local/[DEFAULT] -------------------------- #
Optional[Boolean] $bantime_increment = undef,
Optional[Integer[1]] $bantime_rndtime = undef,
Expand Down
3 changes: 2 additions & 1 deletion spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
it { is_expected.to contain_class('fail2ban::install').that_comes_before('Class[fail2ban::config]') }
it { is_expected.to contain_class('fail2ban::config').that_notifies('Class[fail2ban::service]') }
it { is_expected.to contain_class('fail2ban::service') }
it { is_expected.to contain_class('fail2ban').with_config_file_template('fail2ban/jail.local.epp') }
it { is_expected.to contain_class('fail2ban').with_config_file_template('fail2ban/fail2ban.local.epp') }
it { is_expected.to contain_class('fail2ban').with_jail_file_template('fail2ban/jail.local.epp') }

describe 'fail2ban::install' do
context 'defaults' do
Expand Down
27 changes: 27 additions & 0 deletions templates/fail2ban.local.epp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# THIS FILE IS MANAGED BY PUPPET
# DO NOT EDIT MANUALLY!
<%# Parameters in [DEFAULTS] -%>
<%- $default_params = {
loglevel => $fail2ban::log_level,
logtarget => $fail2ban::logtarget,
syslogsocket => $fail2ban::syslogsocket,
socket => $fail2ban::socket,
pidfile => $fail2ban::pidfile,
allowipv6 => $fail2ban::allowipv6,
dbfile => $fail2ban::dbfile,
dbpurgeage => $fail2ban::dbpurgeage,
dbmaxmatches => $fail2ban::dbmaxmatches,
}
# After removing undefined values, is the hash not empty?
$has_default_params = !$default_params.filter |$key, $value| { $value != undef }.empty()
-%>
<%# If there is at least one parameter, populate the section with defined params -%>
<%- if $has_default_params { -%>
[DEFAULT]
<%- $default_params.each |$name, $value| { -%>
<%- if $value != undef { -%>
<%= $name %> = <%= $value %>
<%- } -%>
<%- } -%>
<%- } -%>
#
Loading