Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
95b1d1231f | ||
|
|
7ae861c216 | ||
|
|
70c6bf4a88 | ||
|
|
50210d9cc3 | ||
|
|
52b3523d4d | ||
|
|
de94a58c3e | ||
|
|
a0fae48b67 | ||
|
|
f9e4cfa10b | ||
|
|
2e68e4259a | ||
|
|
0cdcd5b673 | ||
|
|
12dc849ad3 | ||
|
|
47f47e784d | ||
|
|
af31e1fe07 | ||
|
|
dab8e07069 | ||
|
|
a4b5dae912 | ||
|
|
a7458e33ce | ||
|
|
d71e25c0ae | ||
|
|
be537ee29b | ||
|
|
8e00da08a5 | ||
|
|
582b6a1788 | ||
|
|
344ed1dbbb | ||
|
|
1f2c9a8e8e | ||
|
|
ceff3a4ed5 | ||
|
|
32fcff31f8 | ||
|
|
2c4731e5c9 | ||
|
|
5eba942fcf |
33
.travis.yml
33
.travis.yml
@@ -1,22 +1,33 @@
|
||||
---
|
||||
language: ruby
|
||||
rvm:
|
||||
- 1.8.7
|
||||
- 1.9.3
|
||||
script:
|
||||
- "rake spec SPEC_OPTS='--format documentation'"
|
||||
- 2.0.0
|
||||
script: "bundle exec rake spec SPEC_OPTS='--format documentation' && bundle exec rake test"
|
||||
branches:
|
||||
only:
|
||||
master
|
||||
env:
|
||||
- PUPPET_VERSION="~> 2.6.0"
|
||||
- PUPPET_VERSION="~> 2.7.0"
|
||||
- PUPPET_VERSION="~> 3.0.0"
|
||||
- PUPPET_VERSION="~> 3.1.0"
|
||||
matrix:
|
||||
- PUPPET_GEM_VERSION="~> 2.7.0"
|
||||
- PUPPET_GEM_VERSION="~> 3.0.0"
|
||||
- PUPPET_GEM_VERSION="~> 3.1.0"
|
||||
- PUPPET_GEM_VERSION="~> 3.2.0"
|
||||
matrix:
|
||||
allow_failures:
|
||||
# - rvm: ruby-head
|
||||
exclude:
|
||||
- rvm: 1.8.7
|
||||
env: PUPPET_GEM_VERSION="~> 2.7.0"
|
||||
- rvm: 1.9.3
|
||||
env: PUPPET_VERSION="~> 2.6.0"
|
||||
gemfile: .gemfile
|
||||
- rvm: 1.9.3
|
||||
env: PUPPET_VERSION="~> 2.7.0"
|
||||
gemfile: .gemfile
|
||||
env: PUPPET_GEM_VERSION="~> 2.7.0"
|
||||
- rvm: 2.0.0
|
||||
env: PUPPET_GEM_VERSION="~> 2.7.0"
|
||||
- rvm: 2.0.0
|
||||
env: PUPPET_GEM_VERSION="~> 3.0.0"
|
||||
- rvm: 2.0.0
|
||||
env: PUPPET_GEM_VERSION="~> 3.1.0"
|
||||
gemfile: .gemfile
|
||||
notifications:
|
||||
email:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
name 'netmanagers-fail2ban'
|
||||
version '1.2.0'
|
||||
version '1.4.0'
|
||||
author 'Javier Bertoli'
|
||||
license 'Apache2'
|
||||
project_page 'http://www.netmanagers.com.ar'
|
||||
|
||||
40
Rakefile
40
Rakefile
@@ -1,5 +1,41 @@
|
||||
require 'rubygems'
|
||||
require 'puppetlabs_spec_helper/rake_tasks'
|
||||
require 'puppet-lint/tasks/puppet-lint'
|
||||
PuppetLint.configuration.send('disable_80chars')
|
||||
require 'puppet-syntax/tasks/puppet-syntax'
|
||||
|
||||
# These two gems aren't always present, for instance
|
||||
# on Travis with --without development
|
||||
begin
|
||||
require 'rspec-system/rake_task'
|
||||
rescue LoadError
|
||||
end
|
||||
|
||||
begin
|
||||
require 'puppet_blacksmith/rake_tasks'
|
||||
rescue LoadError
|
||||
end
|
||||
|
||||
PuppetLint.configuration.send("disable_80chars")
|
||||
PuppetLint.configuration.log_format = "%{path}:%{linenumber}:%{check}:%{KIND}:%{message}"
|
||||
PuppetLint.configuration.fail_on_warnings = true
|
||||
PuppetLint.configuration.relative = true
|
||||
|
||||
# Forsake support for Puppet 2.6.2 for the benefit of cleaner code.
|
||||
# http://puppet-lint.com/checks/class_parameter_defaults/
|
||||
PuppetLint.configuration.send('disable_class_parameter_defaults')
|
||||
# http://puppet-lint.com/checks/class_inherits_from_params_class/
|
||||
PuppetLint.configuration.send('disable_class_inherits_from_params_class')
|
||||
|
||||
exclude_paths = [
|
||||
"pkg/**/*",
|
||||
"vendor/**/*",
|
||||
"spec/**/*",
|
||||
]
|
||||
PuppetLint.configuration.ignore_paths = exclude_paths
|
||||
PuppetSyntax.exclude_paths = exclude_paths
|
||||
|
||||
desc "Run syntax, lint, and spec tests."
|
||||
task :test => [
|
||||
:syntax,
|
||||
:lint,
|
||||
:spec,
|
||||
]
|
||||
|
||||
@@ -92,7 +92,10 @@ define fail2ban::filter (
|
||||
|
||||
$manage_file_content = $filtertemplate ? {
|
||||
'' => undef,
|
||||
default => template($filtertemplate),
|
||||
default => $filtersource ? {
|
||||
'' => template($filtertemplate),
|
||||
default => undef,
|
||||
}
|
||||
}
|
||||
|
||||
file { "${real_filtername}.local":
|
||||
|
||||
@@ -31,6 +31,14 @@
|
||||
# (source => $source_dir , recurse => true , purge => true)
|
||||
# Can be defined also by the (top scope) variable $fail2ban_source_dir_purge
|
||||
#
|
||||
# [*source_dir_owner*]
|
||||
# Configuration directory owner
|
||||
# Default: root
|
||||
#
|
||||
# [*source_dir_group*]
|
||||
# Configuration directory group
|
||||
# Default: root
|
||||
#
|
||||
# [*template*]
|
||||
# Sets the path to the template to use as content for main configuration file
|
||||
# If defined, fail2ban main config file has: content => content("$template")
|
||||
@@ -278,6 +286,8 @@ class fail2ban (
|
||||
$source = params_lookup( 'source' ),
|
||||
$source_dir = params_lookup( 'source_dir' ),
|
||||
$source_dir_purge = params_lookup( 'source_dir_purge' ),
|
||||
$source_dir_owner = params_lookup( 'source_dir_owner' ),
|
||||
$source_dir_group = params_lookup( 'source_dir_group' ),
|
||||
$template = params_lookup( 'template' ),
|
||||
$service_autorestart = params_lookup( 'service_autorestart' , 'global' ),
|
||||
$options = params_lookup( 'options' ),
|
||||
@@ -412,18 +422,18 @@ class fail2ban (
|
||||
|
||||
### Managed resources
|
||||
package { $fail2ban::package:
|
||||
ensure => $fail2ban::manage_package,
|
||||
noop => $fail2ban::noops,
|
||||
ensure => $fail2ban::manage_package,
|
||||
noop => $fail2ban::noops,
|
||||
}
|
||||
|
||||
service { 'fail2ban':
|
||||
ensure => $fail2ban::manage_service_ensure,
|
||||
name => $fail2ban::service,
|
||||
enable => $fail2ban::manage_service_enable,
|
||||
hasstatus => $fail2ban::service_status,
|
||||
pattern => $fail2ban::process,
|
||||
require => Package[$fail2ban::package],
|
||||
noop => $fail2ban::noops,
|
||||
ensure => $fail2ban::manage_service_ensure,
|
||||
name => $fail2ban::service,
|
||||
enable => $fail2ban::manage_service_enable,
|
||||
hasstatus => $fail2ban::service_status,
|
||||
pattern => $fail2ban::process,
|
||||
require => Package[$fail2ban::package],
|
||||
noop => $fail2ban::noops,
|
||||
}
|
||||
|
||||
if $fail2ban::manage_file_source
|
||||
@@ -497,6 +507,8 @@ class fail2ban (
|
||||
source => $fail2ban::source_dir,
|
||||
recurse => true,
|
||||
purge => $fail2ban::bool_source_dir_purge,
|
||||
owner => $fail2ban::source_dir_owner,
|
||||
group => $fail2ban::source_dir_group,
|
||||
force => $fail2ban::bool_source_dir_purge,
|
||||
replace => $fail2ban::manage_file_replace,
|
||||
audit => $fail2ban::manage_audit,
|
||||
|
||||
@@ -15,7 +15,9 @@
|
||||
# Defaults to true
|
||||
# $filter - The filter rule to use.
|
||||
# If empty, defaults to == $jailname.
|
||||
# $ignoreip - Don't ban a host which matches an address in this list.
|
||||
# $port - The port to filter. It can be an array of ports.
|
||||
# $protocol - The protocol for this jail's action.
|
||||
# $logpath - The log file to monitor
|
||||
# $maxretry - How many fails are acceptable
|
||||
# $action - The action to take when fail2ban finds $maxretry $filter-matching
|
||||
@@ -29,7 +31,9 @@ define fail2ban::jail (
|
||||
$order = '',
|
||||
$status = '',
|
||||
$filter = '',
|
||||
$ignoreip = '',
|
||||
$port = '',
|
||||
$protocol = '',
|
||||
$action = '',
|
||||
$logpath = '',
|
||||
$maxretry = '',
|
||||
@@ -62,6 +66,14 @@ define fail2ban::jail (
|
||||
default => $filter,
|
||||
}
|
||||
|
||||
$array_ignoreip = is_array($ignoreip) ? {
|
||||
false => $ignoreip ? {
|
||||
'' => [],
|
||||
default => [$ignoreip],
|
||||
},
|
||||
default => $ignoreip,
|
||||
}
|
||||
|
||||
$array_port = is_array($port) ? {
|
||||
false => $port ? {
|
||||
'' => [],
|
||||
@@ -70,6 +82,11 @@ define fail2ban::jail (
|
||||
default => $port,
|
||||
}
|
||||
|
||||
$real_protocol = $protocol ? {
|
||||
'' => undef,
|
||||
default => $protocol,
|
||||
}
|
||||
|
||||
$array_action = is_array($action) ? {
|
||||
false => $action ? {
|
||||
'' => [],
|
||||
|
||||
@@ -29,8 +29,9 @@ class fail2ban::params {
|
||||
}
|
||||
|
||||
$process = $::operatingsystem ? {
|
||||
/(?i:Debian|Ubuntu|Mint)/ => 'fail2ban-server',
|
||||
default => 'fail2ban',
|
||||
/(?i:Debian|Ubuntu|Mint)/ => 'fail2ban-server',
|
||||
/(?i:RedHat|Centos|Scientific|Fedora|OracleLinux)/ => 'fail2ban-server',
|
||||
default => 'fail2ban',
|
||||
}
|
||||
|
||||
$process_args = $::operatingsystem ? {
|
||||
@@ -132,6 +133,8 @@ class fail2ban::params {
|
||||
$template = ''
|
||||
$source_dir = ''
|
||||
$source_dir_purge = false
|
||||
$source_dir_owner = 'root'
|
||||
$source_dir_group = 'root'
|
||||
$options = ''
|
||||
$service_autorestart = true
|
||||
$version = 'present'
|
||||
|
||||
@@ -97,12 +97,10 @@ enabled = true/) }
|
||||
describe 'Test customizations - template' do
|
||||
let(:params) { {:template => "fail2ban/spec.erb" , :options => { 'opt_a' => 'value_a' } } }
|
||||
it 'should generate a valid template' do
|
||||
content = catalogue.resource('file', 'fail2ban.local').send(:parameters)[:content]
|
||||
content.should match "fqdn: rspec.example42.com"
|
||||
should contain_file('fail2ban.local').with_content(/fqdn: rspec.example42.com/)
|
||||
end
|
||||
it 'should generate a template that uses custom options' do
|
||||
content = catalogue.resource('file', 'fail2ban.local').send(:parameters)[:content]
|
||||
content.should match "value_a"
|
||||
should contain_file('fail2ban.local').with_content(/value_a/)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -136,8 +134,7 @@ enabled = true/) }
|
||||
}
|
||||
end
|
||||
it 'should not automatically restart the service, when service_autorestart => false' do
|
||||
content = catalogue.resource('file', 'fail2ban.local').send(:parameters)[:notify]
|
||||
content.should be_nil
|
||||
should contain_file('fail2ban.local').with_notify(nil)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ b = 2
|
||||
not c
|
||||
"
|
||||
end
|
||||
|
||||
|
||||
it { should contain_file('sample2.local').with_path('/etc/fail2ban/filter.d/sample2.local').with_content(expected) }
|
||||
it { should contain_file('sample2.local').without_source }
|
||||
end
|
||||
@@ -75,6 +75,7 @@ not c
|
||||
end
|
||||
|
||||
it { should contain_file('sample3.local').with_path('/etc/fail2ban/filter.d/sample3.local').with_source('puppet:///some/path/to/source') }
|
||||
it { should contain_file('sample3.local').with_content(nil) }
|
||||
it { should contain_file('sample3.local').without_template }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -37,8 +37,10 @@ filter = fail2ban::jail
|
||||
{
|
||||
:name => 'sample1',
|
||||
:port => ['42', '43'],
|
||||
:protocol => 'udp',
|
||||
:logpath => '/path/to/somelog',
|
||||
:enable => true,
|
||||
:ignoreip => [ '10.3.2.0/24', '192.168.56.0/24' ],
|
||||
:findtime => '9000',
|
||||
:maxretry => '5',
|
||||
:bantime => '3600',
|
||||
@@ -53,7 +55,9 @@ filter = fail2ban::jail
|
||||
[fail2ban::jail]
|
||||
enabled = true
|
||||
filter = fail2ban::jail
|
||||
ignoreip = 10.3.2.0/24 192.168.56.0/24
|
||||
port = 42,43
|
||||
protocol = udp
|
||||
action = iptables[name=SSH, port=ssh, protocol=tcp]
|
||||
mail-whois[name=SSH, dest=yourmail@mail.com]
|
||||
logpath = /path/to/somelog
|
||||
|
||||
@@ -4,9 +4,15 @@ enabled = <%= @real_status %>
|
||||
<% if @real_filter != '' -%>
|
||||
filter = <%= @real_filter %>
|
||||
<% end -%>
|
||||
<% if @array_ignoreip != [] -%>
|
||||
ignoreip = <%= @array_ignoreip * ' ' %>
|
||||
<% end -%>
|
||||
<% if @array_port != [] -%>
|
||||
port = <%= @array_port * ',' %>
|
||||
<% end -%>
|
||||
<% if @real_protocol -%>
|
||||
protocol = <%= @real_protocol %>
|
||||
<% end -%>
|
||||
<% if @array_action != [] -%>
|
||||
action = <%= @array_action.join("\n\t") %>
|
||||
<% end -%>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# This file is managed by Puppet. DO NOT EDIT.
|
||||
[DEFAULT]
|
||||
ignoreip = <%= scope.lookupvar('fail2ban::ignoreip') %>
|
||||
ignoreip = <%= scope.lookupvar('fail2ban::ignoreip') * ' ' %>
|
||||
bantime = <%= scope.lookupvar('fail2ban::bantime') %>
|
||||
findtime = <%= scope.lookupvar('fail2ban::findtime') %>
|
||||
maxretry = <%= scope.lookupvar('fail2ban::maxretry') %>
|
||||
|
||||
Reference in New Issue
Block a user