Added puppetlabs-firewall (required by puppetlabs-postgresql), updated the other modules.
This commit is contained in:
parent
5f4b7a3b72
commit
dee66abcdd
137 changed files with 11118 additions and 419 deletions
77
modules/firewall/spec/acceptance/change_source_spec.rb
Normal file
77
modules/firewall/spec/acceptance/change_source_spec.rb
Normal file
|
@ -0,0 +1,77 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'firewall type', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
describe 'reset' do
|
||||
it 'deletes all rules' do
|
||||
shell('iptables --flush; iptables -t nat --flush; iptables -t mangle --flush')
|
||||
end
|
||||
end
|
||||
|
||||
describe 'when unmanaged rules exist' do
|
||||
it 'applies with 8.0.0.1 first' do
|
||||
pp = <<-EOS
|
||||
class { '::firewall': }
|
||||
firewall { '101 test source changes':
|
||||
proto => tcp,
|
||||
port => '101',
|
||||
action => accept,
|
||||
source => '8.0.0.1',
|
||||
}
|
||||
firewall { '100 test source static':
|
||||
proto => tcp,
|
||||
port => '100',
|
||||
action => accept,
|
||||
source => '8.0.0.2',
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'adds a unmanaged rule without a comment' do
|
||||
shell('iptables -A INPUT -t filter -s 8.0.0.3/32 -p tcp -m multiport --ports 102 -j ACCEPT')
|
||||
expect(shell('iptables-save').stdout).to match(/-A INPUT -s 8\.0\.0\.3(\/32)? -p tcp -m multiport --ports 102 -j ACCEPT/)
|
||||
end
|
||||
|
||||
it 'contains the changable 8.0.0.1 rule' do
|
||||
shell('iptables-save') do |r|
|
||||
expect(r.stdout).to match(/-A INPUT -s 8\.0\.0\.1(\/32)? -p tcp -m multiport --ports 101 -m comment --comment "101 test source changes" -j ACCEPT/)
|
||||
end
|
||||
end
|
||||
it 'contains the static 8.0.0.2 rule' do
|
||||
shell('iptables-save') do |r|
|
||||
expect(r.stdout).to match(/-A INPUT -s 8\.0\.0\.2(\/32)? -p tcp -m multiport --ports 100 -m comment --comment "100 test source static" -j ACCEPT/)
|
||||
end
|
||||
end
|
||||
|
||||
it 'changes to 8.0.0.4 second' do
|
||||
pp = <<-EOS
|
||||
class { '::firewall': }
|
||||
firewall { '101 test source changes':
|
||||
proto => tcp,
|
||||
port => '101',
|
||||
action => accept,
|
||||
source => '8.0.0.4',
|
||||
}
|
||||
EOS
|
||||
|
||||
expect(apply_manifest(pp, :catch_failures => true).stdout).to match(/Notice: \/Stage\[main\]\/Main\/Firewall\[101 test source changes\]\/source: source changed '8\.0\.0\.1\/32' to '8\.0\.0\.4\/32'/)
|
||||
end
|
||||
|
||||
it 'does not contain the old changing 8.0.0.1 rule' do
|
||||
shell('iptables-save') do |r|
|
||||
expect(r.stdout).to_not match(/8\.0\.0\.1/)
|
||||
end
|
||||
end
|
||||
it 'contains the staic 8.0.0.2 rule' do
|
||||
shell('iptables-save') do |r|
|
||||
expect(r.stdout).to match(/-A INPUT -s 8\.0\.0\.2(\/32)? -p tcp -m multiport --ports 100 -m comment --comment "100 test source static" -j ACCEPT/)
|
||||
end
|
||||
end
|
||||
it 'contains the changing new 8.0.0.4 rule' do
|
||||
shell('iptables-save') do |r|
|
||||
expect(r.stdout).to match(/-A INPUT -s 8\.0\.0\.4(\/32)? -p tcp -m multiport --ports 101 -m comment --comment "101 test source changes" -j ACCEPT/)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
27
modules/firewall/spec/acceptance/class_spec.rb
Normal file
27
modules/firewall/spec/acceptance/class_spec.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe "firewall class:", :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
it 'should run successfully' do
|
||||
pp = "class { 'firewall': }"
|
||||
|
||||
# Run it twice and test for idempotency
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
|
||||
end
|
||||
|
||||
it 'ensure => stopped:' do
|
||||
pp = "class { 'firewall': ensure => stopped }"
|
||||
|
||||
# Run it twice and test for idempotency
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
|
||||
end
|
||||
|
||||
it 'ensure => running:' do
|
||||
pp = "class { 'firewall': ensure => running }"
|
||||
|
||||
# Run it twice and test for idempotency
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
|
||||
end
|
||||
end
|
55
modules/firewall/spec/acceptance/connlimit_spec.rb
Normal file
55
modules/firewall/spec/acceptance/connlimit_spec.rb
Normal file
|
@ -0,0 +1,55 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'firewall type', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
|
||||
describe 'connlimit_above' do
|
||||
context '10' do
|
||||
it 'applies' do
|
||||
pp = <<-EOS
|
||||
class { '::firewall': }
|
||||
firewall { '500 - test':
|
||||
proto => tcp,
|
||||
dport => '22',
|
||||
connlimit_above => '10',
|
||||
action => reject,
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should contain the rule' do
|
||||
shell('iptables-save') do |r|
|
||||
#connlimit-saddr is added in Ubuntu 14.04.
|
||||
expect(r.stdout).to match(/-A INPUT -p tcp -m multiport --dports 22 -m comment --comment "500 - test" -m connlimit --connlimit-above 10 --connlimit-mask 32 (--connlimit-saddr )?-j REJECT --reject-with icmp-port-unreachable/)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'connlimit_mask' do
|
||||
context '24' do
|
||||
it 'applies' do
|
||||
pp = <<-EOS
|
||||
class { '::firewall': }
|
||||
firewall { '501 - test':
|
||||
proto => tcp,
|
||||
dport => '22',
|
||||
connlimit_above => '10',
|
||||
connlimit_mask => '24',
|
||||
action => reject,
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should contain the rule' do
|
||||
shell('iptables-save') do |r|
|
||||
#connlimit-saddr is added in Ubuntu 14.04.
|
||||
expect(r.stdout).to match(/-A INPUT -p tcp -m multiport --dports 22 -m comment --comment "501 - test" -m connlimit --connlimit-above 10 --connlimit-mask 24 (--connlimit-saddr )?-j REJECT --reject-with icmp-port-unreachable/)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
27
modules/firewall/spec/acceptance/connmark_spec.rb
Normal file
27
modules/firewall/spec/acceptance/connmark_spec.rb
Normal file
|
@ -0,0 +1,27 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'firewall type', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
|
||||
describe 'connmark' do
|
||||
context '50' do
|
||||
it 'applies' do
|
||||
pp = <<-EOS
|
||||
class { '::firewall': }
|
||||
firewall { '502 - test':
|
||||
proto => 'all',
|
||||
connmark => '0x1',
|
||||
action => reject,
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
end
|
||||
|
||||
it 'should contain the rule' do
|
||||
shell('iptables-save') do |r|
|
||||
expect(r.stdout).to match(/-A INPUT -m comment --comment "502 - test" -m connmark --mark 0x1 -j REJECT --reject-with icmp-port-unreachable/)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
1618
modules/firewall/spec/acceptance/firewall_spec.rb
Normal file
1618
modules/firewall/spec/acceptance/firewall_spec.rb
Normal file
File diff suppressed because it is too large
Load diff
125
modules/firewall/spec/acceptance/firewallchain_spec.rb
Normal file
125
modules/firewall/spec/acceptance/firewallchain_spec.rb
Normal file
|
@ -0,0 +1,125 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'puppet resource firewallchain command:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
before :all do
|
||||
iptables_flush_all_tables
|
||||
end
|
||||
describe 'ensure' do
|
||||
context 'present' do
|
||||
it 'applies cleanly' do
|
||||
pp = <<-EOS
|
||||
firewallchain { 'MY_CHAIN:filter:IPv4':
|
||||
ensure => present,
|
||||
}
|
||||
EOS
|
||||
# Run it twice and test for idempotency
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
|
||||
it 'finds the chain' do
|
||||
shell('iptables-save') do |r|
|
||||
expect(r.stdout).to match(/MY_CHAIN/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'absent' do
|
||||
it 'applies cleanly' do
|
||||
pp = <<-EOS
|
||||
firewallchain { 'MY_CHAIN:filter:IPv4':
|
||||
ensure => absent,
|
||||
}
|
||||
EOS
|
||||
# Run it twice and test for idempotency
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
|
||||
it 'fails to find the chain' do
|
||||
shell('iptables-save') do |r|
|
||||
expect(r.stdout).to_not match(/MY_CHAIN/)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# XXX purge => false is not yet implemented
|
||||
#context 'adding a firewall rule to a chain:' do
|
||||
# it 'applies cleanly' do
|
||||
# pp = <<-EOS
|
||||
# firewallchain { 'MY_CHAIN:filter:IPv4':
|
||||
# ensure => present,
|
||||
# }
|
||||
# firewall { '100 my rule':
|
||||
# chain => 'MY_CHAIN',
|
||||
# action => 'accept',
|
||||
# proto => 'tcp',
|
||||
# dport => 5000,
|
||||
# }
|
||||
# EOS
|
||||
# # Run it twice and test for idempotency
|
||||
# apply_manifest(pp, :catch_failures => true)
|
||||
# apply_manifest(pp, :catch_changes => true)
|
||||
# end
|
||||
#end
|
||||
|
||||
#context 'not purge firewallchain chains:' do
|
||||
# it 'does not purge the rule' do
|
||||
# pp = <<-EOS
|
||||
# firewallchain { 'MY_CHAIN:filter:IPv4':
|
||||
# ensure => present,
|
||||
# purge => false,
|
||||
# before => Resources['firewall'],
|
||||
# }
|
||||
# resources { 'firewall':
|
||||
# purge => true,
|
||||
# }
|
||||
# EOS
|
||||
# # Run it twice and test for idempotency
|
||||
# apply_manifest(pp, :catch_failures => true) do |r|
|
||||
# expect(r.stdout).to_not match(/removed/)
|
||||
# expect(r.stderr).to eq('')
|
||||
# end
|
||||
# apply_manifest(pp, :catch_changes => true)
|
||||
# end
|
||||
|
||||
# it 'still has the rule' do
|
||||
# pp = <<-EOS
|
||||
# firewall { '100 my rule':
|
||||
# chain => 'MY_CHAIN',
|
||||
# action => 'accept',
|
||||
# proto => 'tcp',
|
||||
# dport => 5000,
|
||||
# }
|
||||
# EOS
|
||||
# # Run it twice and test for idempotency
|
||||
# apply_manifest(pp, :catch_changes => true)
|
||||
# end
|
||||
#end
|
||||
|
||||
describe 'policy' do
|
||||
after :all do
|
||||
shell('iptables -t filter -P FORWARD ACCEPT')
|
||||
end
|
||||
|
||||
context 'DROP' do
|
||||
it 'applies cleanly' do
|
||||
pp = <<-EOS
|
||||
firewallchain { 'FORWARD:filter:IPv4':
|
||||
policy => 'drop',
|
||||
}
|
||||
EOS
|
||||
# Run it twice and test for idempotency
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
|
||||
it 'finds the chain' do
|
||||
shell('iptables-save') do |r|
|
||||
expect(r.stdout).to match(/FORWARD DROP/)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
114
modules/firewall/spec/acceptance/ip6_fragment_spec.rb
Normal file
114
modules/firewall/spec/acceptance/ip6_fragment_spec.rb
Normal file
|
@ -0,0 +1,114 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
if default['platform'] =~ /el-5/
|
||||
describe "firewall ip6tables doesn't work on 1.3.5 because --comment is missing", :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
before :all do
|
||||
ip6tables_flush_all_tables
|
||||
end
|
||||
|
||||
it "can't use ip6tables" do
|
||||
pp = <<-EOS
|
||||
class { '::firewall': }
|
||||
firewall { '599 - test':
|
||||
ensure => present,
|
||||
proto => 'tcp',
|
||||
provider => 'ip6tables',
|
||||
}
|
||||
EOS
|
||||
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/ip6tables provider is not supported/)
|
||||
end
|
||||
end
|
||||
else
|
||||
describe 'firewall ishasmorefrags/islastfrag/isfirstfrag properties', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
before :all do
|
||||
ip6tables_flush_all_tables
|
||||
end
|
||||
|
||||
shared_examples "is idempotent" do |values, line_match|
|
||||
it "changes the values to #{values}" do
|
||||
pp = <<-EOS
|
||||
class { '::firewall': }
|
||||
firewall { '599 - test':
|
||||
ensure => present,
|
||||
proto => 'tcp',
|
||||
provider => 'ip6tables',
|
||||
#{values}
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
shell('ip6tables-save') do |r|
|
||||
expect(r.stdout).to match(/#{line_match}/)
|
||||
end
|
||||
end
|
||||
end
|
||||
shared_examples "doesn't change" do |values, line_match|
|
||||
it "doesn't change the values to #{values}" do
|
||||
pp = <<-EOS
|
||||
class { '::firewall': }
|
||||
firewall { '599 - test':
|
||||
ensure => present,
|
||||
proto => 'tcp',
|
||||
provider => 'ip6tables',
|
||||
#{values}
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
shell('ip6tables-save') do |r|
|
||||
expect(r.stdout).to match(/#{line_match}/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'adding a rule' do
|
||||
context 'when unset' do
|
||||
before :all do
|
||||
ip6tables_flush_all_tables
|
||||
end
|
||||
it_behaves_like 'is idempotent', '', /-A INPUT -p tcp -m comment --comment "599 - test"/
|
||||
end
|
||||
context 'when set to true' do
|
||||
before :all do
|
||||
ip6tables_flush_all_tables
|
||||
end
|
||||
it_behaves_like "is idempotent", 'ishasmorefrags => true, islastfrag => true, isfirstfrag => true', /-A INPUT -p tcp -m frag --fragid 0 --fragmore -m frag --fragid 0 --fraglast -m frag --fragid 0 --fragfirst -m comment --comment "599 - test"/
|
||||
end
|
||||
context 'when set to false' do
|
||||
before :all do
|
||||
ip6tables_flush_all_tables
|
||||
end
|
||||
it_behaves_like "is idempotent", 'ishasmorefrags => false, islastfrag => false, isfirstfrag => false', /-A INPUT -p tcp -m comment --comment "599 - test"/
|
||||
end
|
||||
end
|
||||
describe 'editing a rule' do
|
||||
context 'when unset or false' do
|
||||
before :each do
|
||||
ip6tables_flush_all_tables
|
||||
shell('ip6tables -A INPUT -p tcp -m comment --comment "599 - test"')
|
||||
end
|
||||
context 'and current value is false' do
|
||||
it_behaves_like "doesn't change", 'ishasmorefrags => false, islastfrag => false, isfirstfrag => false', /-A INPUT -p tcp -m comment --comment "599 - test"/
|
||||
end
|
||||
context 'and current value is true' do
|
||||
it_behaves_like "is idempotent", 'ishasmorefrags => true, islastfrag => true, isfirstfrag => true', /-A INPUT -p tcp -m frag --fragid 0 --fragmore -m frag --fragid 0 --fraglast -m frag --fragid 0 --fragfirst -m comment --comment "599 - test"/
|
||||
end
|
||||
end
|
||||
context 'when set to true' do
|
||||
before :each do
|
||||
ip6tables_flush_all_tables
|
||||
shell('ip6tables -A INPUT -p tcp -m frag --fragid 0 --fragmore -m frag --fragid 0 --fraglast -m frag --fragid 0 --fragfirst -m comment --comment "599 - test"')
|
||||
end
|
||||
context 'and current value is false' do
|
||||
it_behaves_like "is idempotent", 'ishasmorefrags => false, islastfrag => false, isfirstfrag => false', /-A INPUT -p tcp -m comment --comment "599 - test"/
|
||||
end
|
||||
context 'and current value is true' do
|
||||
it_behaves_like "doesn't change", 'ishasmorefrags => true, islastfrag => true, isfirstfrag => true', /-A INPUT -p tcp -m frag --fragid 0 --fragmore -m frag --fragid 0 --fraglast -m frag --fragid 0 --fragfirst -m comment --comment "599 - test"/
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
92
modules/firewall/spec/acceptance/isfragment_spec.rb
Normal file
92
modules/firewall/spec/acceptance/isfragment_spec.rb
Normal file
|
@ -0,0 +1,92 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'firewall isfragment property', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
before :all do
|
||||
iptables_flush_all_tables
|
||||
end
|
||||
|
||||
shared_examples "is idempotent" do |value, line_match|
|
||||
it "changes the value to #{value}" do
|
||||
pp = <<-EOS
|
||||
class { '::firewall': }
|
||||
firewall { '597 - test':
|
||||
ensure => present,
|
||||
proto => 'tcp',
|
||||
#{value}
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
shell('iptables-save') do |r|
|
||||
expect(r.stdout).to match(/#{line_match}/)
|
||||
end
|
||||
end
|
||||
end
|
||||
shared_examples "doesn't change" do |value, line_match|
|
||||
it "doesn't change the value to #{value}" do
|
||||
pp = <<-EOS
|
||||
class { '::firewall': }
|
||||
firewall { '597 - test':
|
||||
ensure => present,
|
||||
proto => 'tcp',
|
||||
#{value}
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
shell('iptables-save') do |r|
|
||||
expect(r.stdout).to match(/#{line_match}/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'adding a rule' do
|
||||
context 'when unset' do
|
||||
before :all do
|
||||
iptables_flush_all_tables
|
||||
end
|
||||
it_behaves_like 'is idempotent', '', /-A INPUT -p tcp -m comment --comment "597 - test"/
|
||||
end
|
||||
context 'when set to true' do
|
||||
before :all do
|
||||
iptables_flush_all_tables
|
||||
end
|
||||
it_behaves_like 'is idempotent', 'isfragment => true,', /-A INPUT -p tcp -f -m comment --comment "597 - test"/
|
||||
end
|
||||
context 'when set to false' do
|
||||
before :all do
|
||||
iptables_flush_all_tables
|
||||
end
|
||||
it_behaves_like "is idempotent", 'isfragment => false,', /-A INPUT -p tcp -m comment --comment "597 - test"/
|
||||
end
|
||||
end
|
||||
describe 'editing a rule' do
|
||||
context 'when unset or false' do
|
||||
before :each do
|
||||
iptables_flush_all_tables
|
||||
shell('iptables -A INPUT -p tcp -m comment --comment "597 - test"')
|
||||
end
|
||||
context 'and current value is false' do
|
||||
it_behaves_like "doesn't change", 'isfragment => false,', /-A INPUT -p tcp -m comment --comment "597 - test"/
|
||||
end
|
||||
context 'and current value is true' do
|
||||
it_behaves_like "is idempotent", 'isfragment => true,', /-A INPUT -p tcp -f -m comment --comment "597 - test"/
|
||||
end
|
||||
end
|
||||
context 'when set to true' do
|
||||
before :each do
|
||||
iptables_flush_all_tables
|
||||
shell('iptables -A INPUT -p tcp -f -m comment --comment "597 - test"')
|
||||
end
|
||||
context 'and current value is false' do
|
||||
it_behaves_like "is idempotent", 'isfragment => false,', /-A INPUT -p tcp -m comment --comment "597 - test"/
|
||||
end
|
||||
context 'and current value is true' do
|
||||
it_behaves_like "doesn't change", 'isfragment => true,', /-A INPUT -p tcp -f -m comment --comment "597 - test"/
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,12 @@
|
|||
HOSTS:
|
||||
centos-59-x64:
|
||||
roles:
|
||||
- master
|
||||
- database
|
||||
- console
|
||||
platform: el-5-x86_64
|
||||
box : centos-59-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-59-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: pe
|
10
modules/firewall/spec/acceptance/nodesets/centos-59-x64.yml
Normal file
10
modules/firewall/spec/acceptance/nodesets/centos-59-x64.yml
Normal file
|
@ -0,0 +1,10 @@
|
|||
HOSTS:
|
||||
centos-59-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: el-5-x86_64
|
||||
box : centos-59-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-59-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: foss
|
|
@ -0,0 +1,10 @@
|
|||
HOSTS:
|
||||
centos-64-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: el-6-x86_64
|
||||
box : centos-64-x64-fusion503-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-fusion503-nocm.box
|
||||
hypervisor : fusion
|
||||
CONFIG:
|
||||
type: foss
|
|
@ -0,0 +1,12 @@
|
|||
HOSTS:
|
||||
centos-64-x64:
|
||||
roles:
|
||||
- master
|
||||
- database
|
||||
- dashboard
|
||||
platform: el-6-x86_64
|
||||
box : centos-64-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: pe
|
10
modules/firewall/spec/acceptance/nodesets/centos-64-x64.yml
Normal file
10
modules/firewall/spec/acceptance/nodesets/centos-64-x64.yml
Normal file
|
@ -0,0 +1,10 @@
|
|||
HOSTS:
|
||||
centos-64-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: el-6-x86_64
|
||||
box : centos-64-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: foss
|
10
modules/firewall/spec/acceptance/nodesets/debian-607-x64.yml
Normal file
10
modules/firewall/spec/acceptance/nodesets/debian-607-x64.yml
Normal file
|
@ -0,0 +1,10 @@
|
|||
HOSTS:
|
||||
debian-607-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: debian-6-amd64
|
||||
box : debian-607-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/debian-607-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: git
|
|
@ -0,0 +1,10 @@
|
|||
HOSTS:
|
||||
debian-70rc1-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: debian-7-amd64
|
||||
box : debian-70rc1-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/debian-70rc1-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: git
|
10
modules/firewall/spec/acceptance/nodesets/default.yml
Normal file
10
modules/firewall/spec/acceptance/nodesets/default.yml
Normal file
|
@ -0,0 +1,10 @@
|
|||
HOSTS:
|
||||
centos-64-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: el-6-x86_64
|
||||
box : centos-64-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: foss
|
10
modules/firewall/spec/acceptance/nodesets/fedora-18-x64.yml
Normal file
10
modules/firewall/spec/acceptance/nodesets/fedora-18-x64.yml
Normal file
|
@ -0,0 +1,10 @@
|
|||
HOSTS:
|
||||
fedora-18-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: fedora-18-x86_64
|
||||
box : fedora-18-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/fedora-18-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: git
|
10
modules/firewall/spec/acceptance/nodesets/sles-11sp1-x64.yml
Normal file
10
modules/firewall/spec/acceptance/nodesets/sles-11sp1-x64.yml
Normal file
|
@ -0,0 +1,10 @@
|
|||
HOSTS:
|
||||
sles-11sp1-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: sles-11-x86_64
|
||||
box : sles-11sp1-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/sles-11sp1-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: git
|
|
@ -0,0 +1,10 @@
|
|||
HOSTS:
|
||||
ubuntu-server-10044-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: ubuntu-10.04-amd64
|
||||
box : ubuntu-server-10044-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-10044-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: git
|
|
@ -0,0 +1,10 @@
|
|||
HOSTS:
|
||||
ubuntu-server-12042-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: ubuntu-12.04-amd64
|
||||
box : ubuntu-server-12042-x64-vbox4210-nocm
|
||||
box_url : http://puppet-vagrant-boxes.puppetlabs.com/ubuntu-server-12042-x64-vbox4210-nocm.box
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: foss
|
|
@ -0,0 +1,9 @@
|
|||
HOSTS:
|
||||
ubuntu-server-1404-x64:
|
||||
roles:
|
||||
- master
|
||||
platform: ubuntu-14.04-64
|
||||
box: puppetlabs/ubuntu-14.04-64-nocm
|
||||
hypervisor : vagrant
|
||||
CONFIG:
|
||||
type: foss
|
154
modules/firewall/spec/acceptance/params_spec.rb
Normal file
154
modules/firewall/spec/acceptance/params_spec.rb
Normal file
|
@ -0,0 +1,154 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe "param based tests:", :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
# Takes a hash and converts it into a firewall resource
|
||||
def pp(params)
|
||||
name = params.delete('name') || '100 test'
|
||||
pm = <<-EOS
|
||||
firewall { '#{name}':
|
||||
EOS
|
||||
|
||||
params.each do |k,v|
|
||||
pm += <<-EOS
|
||||
#{k} => #{v},
|
||||
EOS
|
||||
end
|
||||
|
||||
pm += <<-EOS
|
||||
}
|
||||
EOS
|
||||
pm
|
||||
end
|
||||
|
||||
it 'test various params', :unless => (default['platform'].match(/el-5/) || fact('operatingsystem') == 'SLES') do
|
||||
iptables_flush_all_tables
|
||||
|
||||
ppm = pp({
|
||||
'table' => "'raw'",
|
||||
'socket' => 'true',
|
||||
'chain' => "'PREROUTING'",
|
||||
'jump' => 'LOG',
|
||||
'log_level' => 'debug',
|
||||
})
|
||||
|
||||
expect(apply_manifest(ppm, :catch_failures => true).exit_code).to eq(2)
|
||||
expect(apply_manifest(ppm, :catch_failures => true).exit_code).to be_zero
|
||||
end
|
||||
|
||||
it 'test log rule' do
|
||||
iptables_flush_all_tables
|
||||
|
||||
ppm = pp({
|
||||
'name' => '998 log all',
|
||||
'proto' => 'all',
|
||||
'jump' => 'LOG',
|
||||
'log_level' => 'debug',
|
||||
})
|
||||
expect(apply_manifest(ppm, :catch_failures => true).exit_code).to eq(2)
|
||||
expect(apply_manifest(ppm, :catch_failures => true).exit_code).to be_zero
|
||||
end
|
||||
|
||||
it 'test log rule - changing names' do
|
||||
iptables_flush_all_tables
|
||||
|
||||
ppm1 = pp({
|
||||
'name' => '004 log all INVALID packets',
|
||||
'chain' => 'INPUT',
|
||||
'proto' => 'all',
|
||||
'ctstate' => 'INVALID',
|
||||
'jump' => 'LOG',
|
||||
'log_level' => '3',
|
||||
'log_prefix' => '"IPTABLES dropped invalid: "',
|
||||
})
|
||||
|
||||
ppm2 = pp({
|
||||
'name' => '003 log all INVALID packets',
|
||||
'chain' => 'INPUT',
|
||||
'proto' => 'all',
|
||||
'ctstate' => 'INVALID',
|
||||
'jump' => 'LOG',
|
||||
'log_level' => '3',
|
||||
'log_prefix' => '"IPTABLES dropped invalid: "',
|
||||
})
|
||||
|
||||
expect(apply_manifest(ppm1, :catch_failures => true).exit_code).to eq(2)
|
||||
|
||||
ppm = <<-EOS + "\n" + ppm2
|
||||
resources { 'firewall':
|
||||
purge => true,
|
||||
}
|
||||
EOS
|
||||
expect(apply_manifest(ppm, :catch_failures => true).exit_code).to eq(2)
|
||||
end
|
||||
|
||||
it 'test chain - changing names' do
|
||||
iptables_flush_all_tables
|
||||
|
||||
ppm1 = pp({
|
||||
'name' => '004 with a chain',
|
||||
'chain' => 'INPUT',
|
||||
'proto' => 'all',
|
||||
})
|
||||
|
||||
ppm2 = pp({
|
||||
'name' => '004 with a chain',
|
||||
'chain' => 'OUTPUT',
|
||||
'proto' => 'all',
|
||||
})
|
||||
|
||||
apply_manifest(ppm1, :expect_changes => true)
|
||||
|
||||
ppm = <<-EOS + "\n" + ppm2
|
||||
resources { 'firewall':
|
||||
purge => true,
|
||||
}
|
||||
EOS
|
||||
expect(apply_manifest(ppm2, :expect_failures => true).stderr).to match(/is not supported/)
|
||||
end
|
||||
|
||||
it 'test log rule - idempotent' do
|
||||
iptables_flush_all_tables
|
||||
|
||||
ppm1 = pp({
|
||||
'name' => '004 log all INVALID packets',
|
||||
'chain' => 'INPUT',
|
||||
'proto' => 'all',
|
||||
'ctstate' => 'INVALID',
|
||||
'jump' => 'LOG',
|
||||
'log_level' => '3',
|
||||
'log_prefix' => '"IPTABLES dropped invalid: "',
|
||||
})
|
||||
|
||||
expect(apply_manifest(ppm1, :catch_failures => true).exit_code).to eq(2)
|
||||
expect(apply_manifest(ppm1, :catch_failures => true).exit_code).to be_zero
|
||||
end
|
||||
|
||||
it 'test src_range rule' do
|
||||
iptables_flush_all_tables
|
||||
|
||||
ppm = pp({
|
||||
'name' => '997 block src ip range',
|
||||
'chain' => 'INPUT',
|
||||
'proto' => 'all',
|
||||
'action' => 'drop',
|
||||
'src_range' => '"10.0.0.1-10.0.0.10"',
|
||||
})
|
||||
expect(apply_manifest(ppm, :catch_failures => true).exit_code).to eq(2)
|
||||
expect(apply_manifest(ppm, :catch_failures => true).exit_code).to be_zero
|
||||
end
|
||||
|
||||
it 'test dst_range rule' do
|
||||
iptables_flush_all_tables
|
||||
|
||||
ppm = pp({
|
||||
'name' => '998 block dst ip range',
|
||||
'chain' => 'INPUT',
|
||||
'proto' => 'all',
|
||||
'action' => 'drop',
|
||||
'dst_range' => '"10.0.0.2-10.0.0.20"',
|
||||
})
|
||||
expect(apply_manifest(ppm, :catch_failures => true).exit_code).to eq(2)
|
||||
expect(apply_manifest(ppm, :catch_failures => true).exit_code).to be_zero
|
||||
end
|
||||
|
||||
end
|
124
modules/firewall/spec/acceptance/purge_spec.rb
Normal file
124
modules/firewall/spec/acceptance/purge_spec.rb
Normal file
|
@ -0,0 +1,124 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe "purge tests:", :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
context('resources purge') do
|
||||
before(:all) do
|
||||
iptables_flush_all_tables
|
||||
|
||||
shell('iptables -A INPUT -s 1.2.1.2')
|
||||
shell('iptables -A INPUT -s 1.2.1.2')
|
||||
end
|
||||
|
||||
it 'make sure duplicate existing rules get purged' do
|
||||
|
||||
pp = <<-EOS
|
||||
class { 'firewall': }
|
||||
resources { 'firewall':
|
||||
purge => true,
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :expect_changes => true)
|
||||
end
|
||||
|
||||
it 'saves' do
|
||||
shell('iptables-save') do |r|
|
||||
expect(r.stdout).to_not match(/1\.2\.1\.2/)
|
||||
expect(r.stderr).to eq("")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context('chain purge') do
|
||||
before(:each) do
|
||||
iptables_flush_all_tables
|
||||
|
||||
shell('iptables -A INPUT -p tcp -s 1.2.1.1')
|
||||
shell('iptables -A INPUT -p udp -s 1.2.1.1')
|
||||
shell('iptables -A OUTPUT -s 1.2.1.2 -m comment --comment "010 output-1.2.1.2"')
|
||||
end
|
||||
|
||||
it 'purges only the specified chain' do
|
||||
pp = <<-EOS
|
||||
class { 'firewall': }
|
||||
firewallchain { 'INPUT:filter:IPv4':
|
||||
purge => true,
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :expect_changes => true)
|
||||
|
||||
shell('iptables-save') do |r|
|
||||
expect(r.stdout).to match(/010 output-1\.2\.1\.2/)
|
||||
expect(r.stdout).to_not match(/1\.2\.1\.1/)
|
||||
expect(r.stderr).to eq("")
|
||||
end
|
||||
end
|
||||
|
||||
it 'ignores managed rules' do
|
||||
pp = <<-EOS
|
||||
class { 'firewall': }
|
||||
firewallchain { 'OUTPUT:filter:IPv4':
|
||||
purge => true,
|
||||
}
|
||||
firewall { '010 output-1.2.1.2':
|
||||
chain => 'OUTPUT',
|
||||
proto => 'all',
|
||||
source => '1.2.1.2',
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
|
||||
it 'ignores specified rules' do
|
||||
pp = <<-EOS
|
||||
class { 'firewall': }
|
||||
firewallchain { 'INPUT:filter:IPv4':
|
||||
purge => true,
|
||||
ignore => [
|
||||
'-s 1\.2\.1\.1',
|
||||
],
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
|
||||
it 'adds managed rules with ignored rules' do
|
||||
pp = <<-EOS
|
||||
class { 'firewall': }
|
||||
firewallchain { 'INPUT:filter:IPv4':
|
||||
purge => true,
|
||||
ignore => [
|
||||
'-s 1\.2\.1\.1',
|
||||
],
|
||||
}
|
||||
firewall { '014 input-1.2.1.6':
|
||||
chain => 'INPUT',
|
||||
proto => 'all',
|
||||
source => '1.2.1.6',
|
||||
}
|
||||
-> firewall { '013 input-1.2.1.5':
|
||||
chain => 'INPUT',
|
||||
proto => 'all',
|
||||
source => '1.2.1.5',
|
||||
}
|
||||
-> firewall { '012 input-1.2.1.4':
|
||||
chain => 'INPUT',
|
||||
proto => 'all',
|
||||
source => '1.2.1.4',
|
||||
}
|
||||
-> firewall { '011 input-1.2.1.3':
|
||||
chain => 'INPUT',
|
||||
proto => 'all',
|
||||
source => '1.2.1.3',
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
|
||||
expect(shell('iptables-save').stdout).to match(/-A INPUT -s 1\.2\.1\.1(\/32)? -p tcp\s?\n-A INPUT -s 1\.2\.1\.1(\/32)? -p udp/)
|
||||
end
|
||||
end
|
||||
end
|
92
modules/firewall/spec/acceptance/resource_cmd_spec.rb
Normal file
92
modules/firewall/spec/acceptance/resource_cmd_spec.rb
Normal file
|
@ -0,0 +1,92 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
# Here we want to test the the resource commands ability to work with different
|
||||
# existing ruleset scenarios. This will give the parsing capabilities of the
|
||||
# code a good work out.
|
||||
describe 'puppet resource firewall command:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
context 'make sure it returns no errors when executed on a clean machine' do
|
||||
it do
|
||||
shell('puppet resource firewall') do |r|
|
||||
r.exit_code.should be_zero
|
||||
# don't check stdout, some boxes come with rules, that is normal
|
||||
# don't check stderr, puppet throws deprecation warnings
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'flush iptables and make sure it returns nothing afterwards' do
|
||||
before(:all) do
|
||||
iptables_flush_all_tables
|
||||
end
|
||||
|
||||
# No rules, means no output thanks. And no errors as well.
|
||||
it do
|
||||
shell('puppet resource firewall') do |r|
|
||||
r.exit_code.should be_zero
|
||||
r.stdout.should == "\n"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'accepts rules without comments' do
|
||||
before(:all) do
|
||||
iptables_flush_all_tables
|
||||
shell('iptables -A INPUT -j ACCEPT -p tcp --dport 80')
|
||||
end
|
||||
|
||||
it do
|
||||
shell('puppet resource firewall') do |r|
|
||||
r.exit_code.should be_zero
|
||||
# don't check stdout, testing preexisting rules, output is normal
|
||||
# don't check stderr, puppet throws deprecation warnings
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'accepts rules with invalid comments' do
|
||||
before(:all) do
|
||||
iptables_flush_all_tables
|
||||
shell('iptables -A INPUT -j ACCEPT -p tcp --dport 80 -m comment --comment "http"')
|
||||
end
|
||||
|
||||
it do
|
||||
shell('puppet resource firewall') do |r|
|
||||
r.exit_code.should be_zero
|
||||
# don't check stdout, testing preexisting rules, output is normal
|
||||
# don't check stderr, puppet throws deprecation warnings
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'accepts rules with negation' do
|
||||
before :all do
|
||||
iptables_flush_all_tables
|
||||
shell('iptables -t nat -A POSTROUTING -s 192.168.122.0/24 ! -d 192.168.122.0/24 -p tcp -j MASQUERADE --to-ports 1024-65535')
|
||||
shell('iptables -t nat -A POSTROUTING -s 192.168.122.0/24 ! -d 192.168.122.0/24 -p udp -j MASQUERADE --to-ports 1024-65535')
|
||||
shell('iptables -t nat -A POSTROUTING -s 192.168.122.0/24 ! -d 192.168.122.0/24 -j MASQUERADE')
|
||||
end
|
||||
|
||||
it do
|
||||
shell('puppet resource firewall') do |r|
|
||||
r.exit_code.should be_zero
|
||||
# don't check stdout, testing preexisting rules, output is normal
|
||||
# don't check stderr, puppet throws deprecation warnings
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'accepts rules with match extension tcp flag' do
|
||||
before :all do
|
||||
iptables_flush_all_tables
|
||||
shell('iptables -t mangle -A PREROUTING -d 1.2.3.4 -p tcp -m tcp -m multiport --dports 80,443,8140 -j MARK --set-mark 42')
|
||||
end
|
||||
|
||||
it do
|
||||
shell('puppet resource firewall') do |r|
|
||||
r.exit_code.should be_zero
|
||||
# don't check stdout, testing preexisting rules, output is normal
|
||||
# don't check stderr, puppet throws deprecation warnings
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
252
modules/firewall/spec/acceptance/rules_spec.rb
Normal file
252
modules/firewall/spec/acceptance/rules_spec.rb
Normal file
|
@ -0,0 +1,252 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'complex ruleset 1', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
before :all do
|
||||
iptables_flush_all_tables
|
||||
end
|
||||
|
||||
after :all do
|
||||
shell('iptables -t filter -P INPUT ACCEPT')
|
||||
shell('iptables -t filter -P FORWARD ACCEPT')
|
||||
shell('iptables -t filter -P OUTPUT ACCEPT')
|
||||
shell('iptables -t filter --flush')
|
||||
end
|
||||
|
||||
it 'applies cleanly' do
|
||||
pp = <<-EOS
|
||||
firewall { '090 forward allow local':
|
||||
chain => 'FORWARD',
|
||||
proto => 'all',
|
||||
source => '10.0.0.0/8',
|
||||
destination => '10.0.0.0/8',
|
||||
action => 'accept',
|
||||
}
|
||||
firewall { '100 forward standard allow tcp':
|
||||
chain => 'FORWARD',
|
||||
source => '10.0.0.0/8',
|
||||
destination => '!10.0.0.0/8',
|
||||
proto => 'tcp',
|
||||
state => 'NEW',
|
||||
port => [80,443,21,20,22,53,123,43,873,25,465],
|
||||
action => 'accept',
|
||||
}
|
||||
firewall { '100 forward standard allow udp':
|
||||
chain => 'FORWARD',
|
||||
source => '10.0.0.0/8',
|
||||
destination => '!10.0.0.0/8',
|
||||
proto => 'udp',
|
||||
port => [53,123],
|
||||
action => 'accept',
|
||||
}
|
||||
firewall { '100 forward standard allow icmp':
|
||||
chain => 'FORWARD',
|
||||
source => '10.0.0.0/8',
|
||||
destination => '!10.0.0.0/8',
|
||||
proto => 'icmp',
|
||||
action => 'accept',
|
||||
}
|
||||
|
||||
firewall { '090 ignore ipsec':
|
||||
table => 'nat',
|
||||
chain => 'POSTROUTING',
|
||||
outiface => 'eth0',
|
||||
ipsec_policy => 'ipsec',
|
||||
ipsec_dir => 'out',
|
||||
action => 'accept',
|
||||
}
|
||||
firewall { '093 ignore 10.0.0.0/8':
|
||||
table => 'nat',
|
||||
chain => 'POSTROUTING',
|
||||
outiface => 'eth0',
|
||||
destination => '10.0.0.0/8',
|
||||
action => 'accept',
|
||||
}
|
||||
firewall { '093 ignore 172.16.0.0/12':
|
||||
table => 'nat',
|
||||
chain => 'POSTROUTING',
|
||||
outiface => 'eth0',
|
||||
destination => '172.16.0.0/12',
|
||||
action => 'accept',
|
||||
}
|
||||
firewall { '093 ignore 192.168.0.0/16':
|
||||
table => 'nat',
|
||||
chain => 'POSTROUTING',
|
||||
outiface => 'eth0',
|
||||
destination => '192.168.0.0/16',
|
||||
action => 'accept',
|
||||
}
|
||||
firewall { '100 masq outbound':
|
||||
table => 'nat',
|
||||
chain => 'POSTROUTING',
|
||||
outiface => 'eth0',
|
||||
jump => 'MASQUERADE',
|
||||
}
|
||||
firewall { '101 redirect port 1':
|
||||
table => 'nat',
|
||||
chain => 'PREROUTING',
|
||||
iniface => 'eth0',
|
||||
proto => 'tcp',
|
||||
dport => '1',
|
||||
toports => '22',
|
||||
jump => 'REDIRECT',
|
||||
}
|
||||
EOS
|
||||
|
||||
# Run it twice and test for idempotency
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
|
||||
end
|
||||
|
||||
it 'contains appropriate rules' do
|
||||
shell('iptables-save') do |r|
|
||||
[
|
||||
/INPUT ACCEPT/,
|
||||
/FORWARD ACCEPT/,
|
||||
/OUTPUT ACCEPT/,
|
||||
/-A FORWARD -s 10.0.0.0\/(8|255\.0\.0\.0) -d 10.0.0.0\/(8|255\.0\.0\.0) -m comment --comment \"090 forward allow local\" -j ACCEPT/,
|
||||
/-A FORWARD -s 10.0.0.0\/(8|255\.0\.0\.0) (! -d|-d !) 10.0.0.0\/(8|255\.0\.0\.0) -p icmp -m comment --comment \"100 forward standard allow icmp\" -j ACCEPT/,
|
||||
/-A FORWARD -s 10.0.0.0\/(8|255\.0\.0\.0) (! -d|-d !) 10.0.0.0\/(8|255\.0\.0\.0) -p tcp -m multiport --ports 80,443,21,20,22,53,123,43,873,25,465 -m comment --comment \"100 forward standard allow tcp\" -m state --state NEW -j ACCEPT/,
|
||||
/-A FORWARD -s 10.0.0.0\/(8|255\.0\.0\.0) (! -d|-d !) 10.0.0.0\/(8|255\.0\.0\.0) -p udp -m multiport --ports 53,123 -m comment --comment \"100 forward standard allow udp\" -j ACCEPT/
|
||||
].each do |line|
|
||||
expect(r.stdout).to match(line)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'complex ruleset 2' do
|
||||
after :all do
|
||||
shell('iptables -t filter -P INPUT ACCEPT')
|
||||
shell('iptables -t filter -P FORWARD ACCEPT')
|
||||
shell('iptables -t filter -P OUTPUT ACCEPT')
|
||||
shell('iptables -t filter --flush')
|
||||
expect(shell('iptables -t filter -X LOCAL_INPUT').stderr).to eq("")
|
||||
expect(shell('iptables -t filter -X LOCAL_INPUT_PRE').stderr).to eq("")
|
||||
end
|
||||
|
||||
it 'applies cleanly' do
|
||||
pp = <<-EOS
|
||||
class { '::firewall': }
|
||||
|
||||
Firewall {
|
||||
proto => 'all',
|
||||
stage => 'pre',
|
||||
}
|
||||
Firewallchain {
|
||||
stage => 'pre',
|
||||
purge => 'true',
|
||||
ignore => [
|
||||
'--comment "[^"]*(?i:ignore)[^"]*"',
|
||||
],
|
||||
}
|
||||
|
||||
firewall { '010 INPUT allow established and related':
|
||||
proto => 'all',
|
||||
state => ['ESTABLISHED', 'RELATED'],
|
||||
action => 'accept',
|
||||
before => Firewallchain['INPUT:filter:IPv4'],
|
||||
}
|
||||
firewall { '012 accept loopback':
|
||||
iniface => 'lo',
|
||||
action => 'accept',
|
||||
before => Firewallchain['INPUT:filter:IPv4'],
|
||||
}
|
||||
firewall { '020 ssh':
|
||||
proto => 'tcp',
|
||||
dport => '22',
|
||||
state => 'NEW',
|
||||
action => 'accept',
|
||||
before => Firewallchain['INPUT:filter:IPv4'],
|
||||
}
|
||||
|
||||
firewall { '013 icmp echo-request':
|
||||
proto => 'icmp',
|
||||
icmp => 'echo-request',
|
||||
action => 'accept',
|
||||
source => '10.0.0.0/8',
|
||||
}
|
||||
firewall { '013 icmp destination-unreachable':
|
||||
proto => 'icmp',
|
||||
icmp => 'destination-unreachable',
|
||||
action => 'accept',
|
||||
}
|
||||
firewall { '013 icmp time-exceeded':
|
||||
proto => 'icmp',
|
||||
icmp => 'time-exceeded',
|
||||
action => 'accept',
|
||||
}
|
||||
firewall { '999 reject':
|
||||
action => 'reject',
|
||||
reject => 'icmp-host-prohibited',
|
||||
}
|
||||
|
||||
|
||||
firewallchain { 'LOCAL_INPUT_PRE:filter:IPv4': }
|
||||
firewall { '001 LOCAL_INPUT_PRE':
|
||||
jump => 'LOCAL_INPUT_PRE',
|
||||
require => Firewallchain['LOCAL_INPUT_PRE:filter:IPv4'],
|
||||
}
|
||||
firewallchain { 'LOCAL_INPUT:filter:IPv4': }
|
||||
firewall { '900 LOCAL_INPUT':
|
||||
jump => 'LOCAL_INPUT',
|
||||
require => Firewallchain['LOCAL_INPUT:filter:IPv4'],
|
||||
}
|
||||
firewallchain { 'INPUT:filter:IPv4':
|
||||
policy => 'drop',
|
||||
ignore => [
|
||||
'-j fail2ban-ssh',
|
||||
'--comment "[^"]*(?i:ignore)[^"]*"',
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
firewall { '010 allow established and related':
|
||||
chain => 'FORWARD',
|
||||
proto => 'all',
|
||||
state => ['ESTABLISHED','RELATED'],
|
||||
action => 'accept',
|
||||
before => Firewallchain['FORWARD:filter:IPv4'],
|
||||
}
|
||||
firewallchain { 'FORWARD:filter:IPv4':
|
||||
policy => 'drop',
|
||||
}
|
||||
|
||||
firewallchain { 'OUTPUT:filter:IPv4': }
|
||||
|
||||
|
||||
# purge unknown rules from mangle table
|
||||
firewallchain { ['PREROUTING:mangle:IPv4', 'INPUT:mangle:IPv4', 'FORWARD:mangle:IPv4', 'OUTPUT:mangle:IPv4', 'POSTROUTING:mangle:IPv4']: }
|
||||
|
||||
# and the nat table
|
||||
firewallchain { ['PREROUTING:nat:IPv4', 'INPUT:nat:IPv4', 'OUTPUT:nat:IPv4', 'POSTROUTING:nat:IPv4']: }
|
||||
EOS
|
||||
|
||||
# Run it twice and test for idempotency
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
end
|
||||
|
||||
it 'contains appropriate rules' do
|
||||
shell('iptables-save') do |r|
|
||||
[
|
||||
/INPUT DROP/,
|
||||
/FORWARD DROP/,
|
||||
/OUTPUT ACCEPT/,
|
||||
/LOCAL_INPUT/,
|
||||
/LOCAL_INPUT_PRE/,
|
||||
/-A INPUT -m comment --comment \"001 LOCAL_INPUT_PRE\" -j LOCAL_INPUT_PRE/,
|
||||
/-A INPUT -m comment --comment \"010 INPUT allow established and related\" -m state --state RELATED,ESTABLISHED -j ACCEPT/,
|
||||
/-A INPUT -i lo -m comment --comment \"012 accept loopback\" -j ACCEPT/,
|
||||
/-A INPUT -p icmp -m comment --comment \"013 icmp destination-unreachable\" -m icmp --icmp-type 3 -j ACCEPT/,
|
||||
/-A INPUT -s 10.0.0.0\/(8|255\.0\.0\.0) -p icmp -m comment --comment \"013 icmp echo-request\" -m icmp --icmp-type 8 -j ACCEPT/,
|
||||
/-A INPUT -p icmp -m comment --comment \"013 icmp time-exceeded\" -m icmp --icmp-type 11 -j ACCEPT/,
|
||||
/-A INPUT -p tcp -m multiport --dports 22 -m comment --comment \"020 ssh\" -m state --state NEW -j ACCEPT/,
|
||||
/-A INPUT -m comment --comment \"900 LOCAL_INPUT\" -j LOCAL_INPUT/,
|
||||
/-A INPUT -m comment --comment \"999 reject\" -j REJECT --reject-with icmp-host-prohibited/,
|
||||
/-A FORWARD -m comment --comment \"010 allow established and related\" -m state --state RELATED,ESTABLISHED -j ACCEPT/
|
||||
].each do |line|
|
||||
expect(r.stdout).to match(line)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
97
modules/firewall/spec/acceptance/socket_spec.rb
Normal file
97
modules/firewall/spec/acceptance/socket_spec.rb
Normal file
|
@ -0,0 +1,97 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
# RHEL5 does not support -m socket
|
||||
describe 'firewall socket property', :unless => (UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) || default['platform'] =~ /el-5/ || fact('operatingsystem') == 'SLES') do
|
||||
before :all do
|
||||
iptables_flush_all_tables
|
||||
end
|
||||
|
||||
shared_examples "is idempotent" do |value, line_match|
|
||||
it "changes the value to #{value}" do
|
||||
pp = <<-EOS
|
||||
class { '::firewall': }
|
||||
firewall { '598 - test':
|
||||
ensure => present,
|
||||
proto => 'tcp',
|
||||
chain => 'PREROUTING',
|
||||
table => 'raw',
|
||||
#{value}
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
shell('iptables-save -t raw') do |r|
|
||||
expect(r.stdout).to match(/#{line_match}/)
|
||||
end
|
||||
end
|
||||
end
|
||||
shared_examples "doesn't change" do |value, line_match|
|
||||
it "doesn't change the value to #{value}" do
|
||||
pp = <<-EOS
|
||||
class { '::firewall': }
|
||||
firewall { '598 - test':
|
||||
ensure => present,
|
||||
proto => 'tcp',
|
||||
chain => 'PREROUTING',
|
||||
table => 'raw',
|
||||
#{value}
|
||||
}
|
||||
EOS
|
||||
|
||||
apply_manifest(pp, :catch_changes => true)
|
||||
|
||||
shell('iptables-save -t raw') do |r|
|
||||
expect(r.stdout).to match(/#{line_match}/)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe 'adding a rule' do
|
||||
context 'when unset' do
|
||||
before :all do
|
||||
iptables_flush_all_tables
|
||||
end
|
||||
it_behaves_like 'is idempotent', '', /-A PREROUTING -p tcp -m comment --comment "598 - test"/
|
||||
end
|
||||
context 'when set to true' do
|
||||
before :all do
|
||||
iptables_flush_all_tables
|
||||
end
|
||||
it_behaves_like 'is idempotent', 'socket => true,', /-A PREROUTING -p tcp -m socket -m comment --comment "598 - test"/
|
||||
end
|
||||
context 'when set to false' do
|
||||
before :all do
|
||||
iptables_flush_all_tables
|
||||
end
|
||||
it_behaves_like "is idempotent", 'socket => false,', /-A PREROUTING -p tcp -m comment --comment "598 - test"/
|
||||
end
|
||||
end
|
||||
describe 'editing a rule' do
|
||||
context 'when unset or false' do
|
||||
before :each do
|
||||
iptables_flush_all_tables
|
||||
shell('iptables -t raw -A PREROUTING -p tcp -m comment --comment "598 - test"')
|
||||
end
|
||||
context 'and current value is false' do
|
||||
it_behaves_like "doesn't change", 'socket => false,', /-A PREROUTING -p tcp -m comment --comment "598 - test"/
|
||||
end
|
||||
context 'and current value is true' do
|
||||
it_behaves_like "is idempotent", 'socket => true,', /-A PREROUTING -p tcp -m socket -m comment --comment "598 - test"/
|
||||
end
|
||||
end
|
||||
context 'when set to true' do
|
||||
before :each do
|
||||
iptables_flush_all_tables
|
||||
shell('iptables -t raw -A PREROUTING -p tcp -m socket -m comment --comment "598 - test"')
|
||||
end
|
||||
context 'and current value is false' do
|
||||
it_behaves_like "is idempotent", 'socket => false,', /-A PREROUTING -p tcp -m comment --comment "598 - test"/
|
||||
end
|
||||
context 'and current value is true' do
|
||||
it_behaves_like "doesn't change", 'socket => true,', /-A PREROUTING -p tcp -m socket -m comment --comment "598 - test"/
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
55
modules/firewall/spec/acceptance/standard_usage_spec.rb
Normal file
55
modules/firewall/spec/acceptance/standard_usage_spec.rb
Normal file
|
@ -0,0 +1,55 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
# Some tests for the standard recommended usage
|
||||
describe 'standard usage tests:', :unless => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
it 'applies twice' do
|
||||
pp = <<-EOS
|
||||
class my_fw::pre {
|
||||
Firewall {
|
||||
require => undef,
|
||||
}
|
||||
|
||||
# Default firewall rules
|
||||
firewall { '000 accept all icmp':
|
||||
proto => 'icmp',
|
||||
action => 'accept',
|
||||
}->
|
||||
firewall { '001 accept all to lo interface':
|
||||
proto => 'all',
|
||||
iniface => 'lo',
|
||||
action => 'accept',
|
||||
}->
|
||||
firewall { '002 accept related established rules':
|
||||
proto => 'all',
|
||||
ctstate => ['RELATED', 'ESTABLISHED'],
|
||||
action => 'accept',
|
||||
}
|
||||
}
|
||||
class my_fw::post {
|
||||
firewall { '999 drop all':
|
||||
proto => 'all',
|
||||
action => 'drop',
|
||||
before => undef,
|
||||
}
|
||||
}
|
||||
resources { "firewall":
|
||||
purge => true
|
||||
}
|
||||
Firewall {
|
||||
before => Class['my_fw::post'],
|
||||
require => Class['my_fw::pre'],
|
||||
}
|
||||
class { ['my_fw::pre', 'my_fw::post']: }
|
||||
class { 'firewall': }
|
||||
firewall { '500 open up port 22':
|
||||
action => 'accept',
|
||||
proto => 'tcp',
|
||||
dport => 22,
|
||||
}
|
||||
EOS
|
||||
|
||||
# Run it twice and test for idempotency
|
||||
apply_manifest(pp, :catch_failures => true)
|
||||
expect(apply_manifest(pp, :catch_failures => true).exit_code).to be_zero
|
||||
end
|
||||
end
|
10
modules/firewall/spec/acceptance/unsupported_spec.rb
Normal file
10
modules/firewall/spec/acceptance/unsupported_spec.rb
Normal file
|
@ -0,0 +1,10 @@
|
|||
require 'spec_helper_acceptance'
|
||||
|
||||
describe 'unsupported distributions and OSes', :if => UNSUPPORTED_PLATFORMS.include?(fact('osfamily')) do
|
||||
it 'should fail' do
|
||||
pp = <<-EOS
|
||||
class { 'firewall': }
|
||||
EOS
|
||||
expect(apply_manifest(pp, :expect_failures => true).stderr).to match(/not currently supported/i)
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue