├── .rubocop.yml
├── test
├── cookbooks
│ └── iptables_ng_test
│ │ ├── recipes
│ │ ├── recipe_default.rb
│ │ ├── recipe_install.rb
│ │ ├── attribute_enabled_tables.rb
│ │ ├── lwrp_chain_create_empty.rb
│ │ ├── lwrp_chain_create_default.rb
│ │ ├── lwrp_chain_create_if_missing.rb
│ │ ├── lwrp_chain_create_custom.rb
│ │ ├── lwrp_rule_create_default.rb
│ │ ├── lwrp_rule_create_custom.rb
│ │ ├── lwrp_rule_create_custom_chain.rb
│ │ ├── lwrp_rule_delete.rb
│ │ ├── lwrp_rule_create_if_missing.rb
│ │ └── lwrp_rule_check_order.rb
│ │ └── metadata.rb
├── nodes
│ └── test.json
└── integration
│ ├── lwrp_rule_check_order
│ └── lwrp_rule_check_order_test.rb
│ ├── lwrp_chain_create_empty
│ └── lwrp_chain_create_empty_test.rb
│ ├── lwrp_chain_create_default
│ └── lwrp_chain_create_default_test.rb
│ ├── lwrp_chain_create_if_missing
│ └── lwrp_chain_create_if_missing_test.rb
│ ├── lwrp_chain_create_custom
│ └── lwrp_chain_create_custom_test.rb
│ ├── lwrp_rule_delete
│ └── lwrp_rule_delete_test.rb
│ ├── lwrp_rule_create_custom
│ └── lwrp_rule_create_custom_test.rb
│ ├── lwrp_rule_create_default
│ └── lwrp_rule_create_default_test.rb
│ ├── lwrp_rule_create_custom_chain
│ └── lwrp_rule_create_custom_chain_test.rb
│ ├── lwrp_rule_create_if_missing
│ └── lwrp_rule_create_if_missing_test.rb
│ ├── attribute_enabled_tables
│ └── attribute_enabled_tables_test.rb
│ ├── default
│ └── default_test.rb
│ └── install
│ └── install_test.rb
├── .gitignore
├── Berksfile
├── spec
├── spec_helper.rb
├── default_spec.rb
└── install_spec.rb
├── metadata.rb
├── libraries
├── matchers.rb
├── restart_service.rb
└── create_iptables_rules.rb
├── resources
├── chain.rb
└── rule.rb
├── recipes
├── manage.rb
├── install.rb
└── default.rb
├── chefignore
├── .github
└── workflows
│ └── chef.yml
├── attributes
├── rules.rb
└── default.rb
├── providers
├── chain.rb
└── rule.rb
├── kitchen.yml
├── CHANGELOG.md
├── kitchen.dokken.yml
├── README.md
└── LICENSE
/.rubocop.yml:
--------------------------------------------------------------------------------
1 | Style/TrailingCommaInArguments:
2 | EnforcedStyleForMultiline: comma
3 |
--------------------------------------------------------------------------------
/test/cookbooks/iptables_ng_test/recipes/recipe_default.rb:
--------------------------------------------------------------------------------
1 | include_recipe 'iptables-ng::default'
2 |
--------------------------------------------------------------------------------
/test/cookbooks/iptables_ng_test/recipes/recipe_install.rb:
--------------------------------------------------------------------------------
1 | include_recipe 'iptables-ng::install'
2 |
--------------------------------------------------------------------------------
/test/cookbooks/iptables_ng_test/recipes/attribute_enabled_tables.rb:
--------------------------------------------------------------------------------
1 | include_recipe 'iptables-ng::default'
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .vagrant
2 | Berksfile.lock
3 | Gemfile.lock
4 | .bundle
5 | .cache
6 | .kitchen
7 | .kitchen.local.yml
8 | bin
9 |
--------------------------------------------------------------------------------
/test/cookbooks/iptables_ng_test/recipes/lwrp_chain_create_empty.rb:
--------------------------------------------------------------------------------
1 | include_recipe 'iptables-ng::install'
2 |
3 | iptables_ng_chain 'EMPTY'
4 |
--------------------------------------------------------------------------------
/Berksfile:
--------------------------------------------------------------------------------
1 | source 'https://supermarket.chef.io'
2 |
3 | metadata
4 |
5 | group :integration do
6 | cookbook 'iptables_ng_test', path: 'test/cookbooks/iptables_ng_test'
7 | end
8 |
--------------------------------------------------------------------------------
/test/cookbooks/iptables_ng_test/recipes/lwrp_chain_create_default.rb:
--------------------------------------------------------------------------------
1 | include_recipe 'iptables-ng::install'
2 |
3 | iptables_ng_chain 'FORWARD' do
4 | policy 'DROP [0:0]'
5 | action :create
6 | end
7 |
--------------------------------------------------------------------------------
/spec/spec_helper.rb:
--------------------------------------------------------------------------------
1 | require 'chefspec'
2 |
3 | RSpec.configure do |config|
4 | config.platform = 'ubuntu'
5 | config.version = '20.04'
6 | config.expect_with(:rspec) { |c| c.syntax = :expect }
7 | end
8 |
--------------------------------------------------------------------------------
/test/cookbooks/iptables_ng_test/recipes/lwrp_chain_create_if_missing.rb:
--------------------------------------------------------------------------------
1 | include_recipe 'iptables-ng::install'
2 |
3 | iptables_ng_chain 'FORWARD' do
4 | policy 'DROP [0:0]'
5 | action :create_if_missing
6 | end
7 |
--------------------------------------------------------------------------------
/test/cookbooks/iptables_ng_test/recipes/lwrp_chain_create_custom.rb:
--------------------------------------------------------------------------------
1 | include_recipe 'iptables-ng::install'
2 |
3 | iptables_ng_chain 'FORWARD' do
4 | table 'mangle'
5 | policy 'DROP [0:0]'
6 | action :create
7 | end
8 |
--------------------------------------------------------------------------------
/test/cookbooks/iptables_ng_test/recipes/lwrp_rule_create_default.rb:
--------------------------------------------------------------------------------
1 | include_recipe 'iptables-ng::install'
2 |
3 | iptables_ng_rule 'ssh' do
4 | # use defaults
5 | rule '--protocol tcp --dport 22 --match state --state NEW --jump ACCEPT'
6 | end
7 |
--------------------------------------------------------------------------------
/test/cookbooks/iptables_ng_test/recipes/lwrp_rule_create_custom.rb:
--------------------------------------------------------------------------------
1 | include_recipe 'iptables-ng::install'
2 |
3 | iptables_ng_rule 'custom-output' do
4 | chain 'OUTPUT'
5 | table 'nat'
6 | rule '--protocol icmp --jump ACCEPT'
7 | action :create
8 | end
9 |
--------------------------------------------------------------------------------
/test/cookbooks/iptables_ng_test/metadata.rb:
--------------------------------------------------------------------------------
1 | name 'iptables_ng_test'
2 | maintainer 'Chris Aumann'
3 | maintainer_email 'me@chr4.org'
4 | license 'GPL-3.0'
5 | description 'This cookbook is used with test-kitchen to test the parent, iptables cookbook'
6 | version '0.1.0'
7 | depends 'iptables-ng'
8 |
--------------------------------------------------------------------------------
/test/cookbooks/iptables_ng_test/recipes/lwrp_rule_create_custom_chain.rb:
--------------------------------------------------------------------------------
1 | include_recipe 'iptables-ng::install'
2 |
3 | # We need to create the custom chain first
4 | iptables_ng_chain 'FOO' do
5 | table 'nat'
6 | end
7 |
8 | iptables_ng_rule 'custom-chain-output' do
9 | chain 'FOO'
10 | table 'nat'
11 | rule '--protocol icmp --jump ACCEPT'
12 | action :create
13 | end
14 |
--------------------------------------------------------------------------------
/test/cookbooks/iptables_ng_test/recipes/lwrp_rule_delete.rb:
--------------------------------------------------------------------------------
1 | include_recipe 'iptables-ng::install'
2 |
3 | iptables_ng_rule 'http' do
4 | rule '--protocol tcp --dport 80 --match state --state NEW --jump ACCEPT'
5 | action :create
6 | end
7 |
8 | iptables_ng_rule 'http' do
9 | rule '--protocol tcp --dport 80 --match state --state NEW --jump ACCEPT'
10 | action :delete
11 | end
12 |
--------------------------------------------------------------------------------
/test/cookbooks/iptables_ng_test/recipes/lwrp_rule_create_if_missing.rb:
--------------------------------------------------------------------------------
1 | include_recipe 'iptables-ng::install'
2 |
3 | iptables_ng_rule 'ssh' do
4 | rule '--protocol tcp --dport 22 --match state --state NEW --jump ACCEPT'
5 | action :create
6 | end
7 |
8 | iptables_ng_rule 'ssh' do
9 | rule '--protocol tcp --dport 80 --match state --state NEW --jump ACCEPT'
10 | action :create_if_missing
11 | end
12 |
--------------------------------------------------------------------------------
/test/nodes/test.json:
--------------------------------------------------------------------------------
1 | {
2 | "iptables-ng": {
3 | "rules": {
4 | "filter": {
5 | "INPUT": {
6 | "default": "DROP [0:0]",
7 | "test1": {
8 | "rule": "--protocol tcp --dport 22 --match state --state NEW --jump ACCEPT"
9 | },
10 | "test2": {
11 | "rule": "--protocol tcp --dport 80 --match state --state NEW --jump DROP",
12 | "ip_version": 4
13 | }
14 | }
15 | }
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/metadata.rb:
--------------------------------------------------------------------------------
1 | name 'iptables-ng'
2 | maintainer 'Chris Aumann'
3 | maintainer_email 'me@chr4.org'
4 | license 'GPL-3.0-or-later'
5 | description 'Installs/Configures iptables-ng'
6 | source_url 'https://github.com/chr4-cookbooks/iptables-ng'
7 | issues_url 'https://github.com/chr4-cookbooks/iptables-ng/issues'
8 | version '4.1.0'
9 | chef_version '>= 15.3'
10 |
11 | %w(ubuntu debian
12 | redhat centos amazon suse scientific
13 | fedora gentoo arch).each do |os|
14 | supports os
15 | end
16 |
--------------------------------------------------------------------------------
/test/integration/lwrp_rule_check_order/lwrp_rule_check_order_test.rb:
--------------------------------------------------------------------------------
1 | script_ipv4 = case os.family
2 | when 'debian'
3 | '/etc/iptables/rules.v4'
4 | when 'redhat'
5 | '/etc/sysconfig/iptables'
6 | else
7 | '/etc/iptables-rules.ipt'
8 | end
9 |
10 | # Should concatinate iptables rules in specified order
11 | describe file(script_ipv4) do
12 | it { should exist }
13 | its('content') { should match(/--sport 110.*--dport 20.*--dport 50.*--dport 51.*--dport 998.*--dport 99/m) }
14 | end
15 |
--------------------------------------------------------------------------------
/test/cookbooks/iptables_ng_test/recipes/lwrp_rule_check_order.rb:
--------------------------------------------------------------------------------
1 | include_recipe 'iptables-ng::install'
2 |
3 | iptables_ng_rule '99-last' do
4 | rule '--protocol tcp --dport 99 --jump ACCEPT'
5 | end
6 |
7 | iptables_ng_rule '20-second' do
8 | rule '--jump ACCEPT --protocol udp --dport 20'
9 | end
10 |
11 | iptables_ng_rule '10-first' do
12 | rule '--protocol tcp --jump ACCEPT --sport 110'
13 | end
14 |
15 | iptables_ng_rule '51-medium-2' do
16 | rule '--jump ACCEPT --protocol tcp --dport 51'
17 | end
18 |
19 | iptables_ng_rule '50-medium-1' do
20 | rule '--protocol udp --dport 50 --jump ACCEPT'
21 | end
22 |
23 | iptables_ng_rule '98-almost-last' do
24 | rule '--jump ACCEPT --protocol tcp --dport 998'
25 | end
26 |
--------------------------------------------------------------------------------
/libraries/matchers.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook:: iptables-ng
3 | # Library:: matchers
4 | #
5 | # Copyright:: 2014, Dan Fruehauf
6 | #
7 | # This program is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # This program is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # You should have received a copy of the GNU General Public License
18 | # along with this program. If not, see .
19 | #
20 |
21 | # Matchers for chefspec
22 |
--------------------------------------------------------------------------------
/spec/default_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe 'iptables-ng::default' do
4 | let(:chef_run) do
5 | ChefSpec::ServerRunner.new do |node|
6 | node.automatic.merge!(JSON.parse(File.read('test/nodes/test.json')))
7 | end.converge(described_recipe)
8 | end
9 |
10 | it 'should include iptables-ng::install' do
11 | expect(chef_run).to include_recipe('iptables-ng::install')
12 | end
13 |
14 | it 'should apply rules from node definition' do
15 | expect(chef_run).to create_iptables_ng_rule('test1-filter-INPUT-attribute-rule')
16 | .with(
17 | chain: 'INPUT',
18 | table: 'filter',
19 | rule: '--protocol tcp --dport 22 --match state --state NEW --jump ACCEPT',
20 | ip_version: [4, 6],
21 | )
22 |
23 | expect(chef_run).to create_iptables_ng_rule('test2-filter-INPUT-attribute-rule')
24 | .with(
25 | chain: 'INPUT',
26 | table: 'filter',
27 | rule: '--protocol tcp --dport 80 --match state --state NEW --jump DROP',
28 | ip_version: 4,
29 | )
30 | end
31 | end
32 |
--------------------------------------------------------------------------------
/test/integration/lwrp_chain_create_empty/lwrp_chain_create_empty_test.rb:
--------------------------------------------------------------------------------
1 | # Should not default FORWARD policy to DROP
2 | describe file('/etc/iptables.d/filter/EMPTY/default') do
3 | it { should exist }
4 | its('content') { should match('\- \[0\:0\]') }
5 | end
6 |
7 | service_ipv4 = case os.family
8 | when 'debian'
9 | 'netfilter-persistent'
10 | else
11 | 'iptables'
12 | end
13 |
14 | service_ipv6 = case os.family
15 | when 'debian'
16 | 'netfilter-persistent'
17 | else
18 | 'ip6tables'
19 | end
20 |
21 | # Should enable iptables serices
22 | describe service(service_ipv4) do
23 | it { should be_enabled }
24 | end
25 |
26 | describe service(service_ipv6) do
27 | it { should be_enabled }
28 | end
29 |
30 | # Should apply the specified iptables rules
31 | describe command('iptables -L -n') do
32 | its('stdout') { should match('Chain EMPTY \(0 references\)') }
33 | its('exit_status') { should eq 0 }
34 | end
35 |
36 | describe command('ip6tables -L -n') do
37 | its('stdout') { should match('Chain EMPTY \(0 references\)') }
38 | its('exit_status') { should eq 0 }
39 | end
40 |
--------------------------------------------------------------------------------
/test/integration/lwrp_chain_create_default/lwrp_chain_create_default_test.rb:
--------------------------------------------------------------------------------
1 | # Should set default FORWARD policy to DROP
2 | describe file('/etc/iptables.d/filter/FORWARD/default') do
3 | it { should exist }
4 | its('content') { should match('DROP \[0\:0\]') }
5 | end
6 |
7 | service_ipv4 = case os.family
8 | when 'debian'
9 | 'netfilter-persistent'
10 | else
11 | 'iptables'
12 | end
13 |
14 | service_ipv6 = case os.family
15 | when 'debian'
16 | 'netfilter-persistent'
17 | else
18 | 'ip6tables'
19 | end
20 |
21 | # Should enable iptables serices
22 | describe service(service_ipv4) do
23 | it { should be_enabled }
24 | end
25 |
26 | describe service(service_ipv6) do
27 | it { should be_enabled }
28 | end
29 |
30 | # Should apply the specified iptables rules
31 | describe command('iptables -L -n') do
32 | its('stdout') { should match('Chain FORWARD \(policy DROP\)') }
33 | its('exit_status') { should eq 0 }
34 | end
35 |
36 | describe command('ip6tables -L -n') do
37 | its('stdout') { should match('Chain FORWARD \(policy DROP\)') }
38 | its('exit_status') { should eq 0 }
39 | end
40 |
--------------------------------------------------------------------------------
/test/integration/lwrp_chain_create_if_missing/lwrp_chain_create_if_missing_test.rb:
--------------------------------------------------------------------------------
1 | # Should not default FORWARD policy to DROP
2 | describe file('/etc/iptables.d/filter/FORWARD/default') do
3 | it { should exist }
4 | its('content') { should_not match('DROP \[0\:0\]') }
5 | end
6 |
7 | service_ipv4 = case os.family
8 | when 'debian'
9 | 'netfilter-persistent'
10 | else
11 | 'iptables'
12 | end
13 |
14 | service_ipv6 = case os.family
15 | when 'debian'
16 | 'netfilter-persistent'
17 | else
18 | 'ip6tables'
19 | end
20 |
21 | # Should enable iptables serices
22 | describe service(service_ipv4) do
23 | it { should be_enabled }
24 | end
25 |
26 | describe service(service_ipv6) do
27 | it { should be_enabled }
28 | end
29 |
30 | # Should apply the specified iptables rules
31 | describe command('iptables -L -n') do
32 | its('stdout') { should match('Chain FORWARD \(policy ACCEPT\)') }
33 | its('exit_status') { should eq 0 }
34 | end
35 |
36 | describe command('ip6tables -L -n') do
37 | its('stdout') { should match('Chain FORWARD \(policy ACCEPT\)') }
38 | its('exit_status') { should eq 0 }
39 | end
40 |
--------------------------------------------------------------------------------
/test/integration/lwrp_chain_create_custom/lwrp_chain_create_custom_test.rb:
--------------------------------------------------------------------------------
1 | # Should set mangle FORWARD policy to DROP
2 | describe file('/etc/iptables.d/mangle/FORWARD/default') do
3 | it { should exist }
4 | its('content') { should match('DROP \[0\:0\]') }
5 | end
6 |
7 | service_ipv4 = case os.family
8 | when 'debian'
9 | 'netfilter-persistent'
10 | else
11 | 'iptables'
12 | end
13 |
14 | service_ipv6 = case os.family
15 | when 'debian'
16 | 'netfilter-persistent'
17 | else
18 | 'ip6tables'
19 | end
20 |
21 | # Should enable iptables serices
22 | describe service(service_ipv4) do
23 | it { should be_enabled }
24 | end
25 |
26 | describe service(service_ipv6) do
27 | it { should be_enabled }
28 | end
29 |
30 | # Should apply the specified iptables rules
31 | describe command('iptables -t mangle -L -n') do
32 | its('stdout') { should match('Chain FORWARD \(policy DROP\)') }
33 | its('exit_status') { should eq 0 }
34 | end
35 |
36 | describe command('ip6tables -t mangle -L -n') do
37 | its('stdout') { should match('Chain FORWARD \(policy DROP\)') }
38 | its('exit_status') { should eq 0 }
39 | end
40 |
--------------------------------------------------------------------------------
/test/integration/lwrp_rule_delete/lwrp_rule_delete_test.rb:
--------------------------------------------------------------------------------
1 | # Should not set HTTP rule
2 | describe file('/etc/iptables.d/filter/INPUT/http.rule_v4') do
3 | it { should_not exist }
4 | end
5 |
6 | # Should not set HTTP ip6tables rule
7 | describe file('/etc/iptables.d/filter/INPUT/http.rule_v6') do
8 | it { should_not exist }
9 | end
10 |
11 | service_ipv4 = case os.family
12 | when 'debian'
13 | 'netfilter-persistent'
14 | else
15 | 'iptables'
16 | end
17 |
18 | service_ipv6 = case os.family
19 | when 'debian'
20 | 'netfilter-persistent'
21 | else
22 | 'ip6tables'
23 | end
24 |
25 | # Should enable iptables serices
26 | describe service(service_ipv4) do
27 | it { should be_enabled }
28 | end
29 |
30 | describe service(service_ipv6) do
31 | it { should be_enabled }
32 | end
33 |
34 | # Should apply the specified iptables rules
35 | describe command('iptables -L -n') do
36 | its('stdout') { should_not match('tcp dpt:80 state NEW') }
37 | its('exit_status') { should eq 0 }
38 | end
39 |
40 | describe command('ip6tables -L -n') do
41 | its('stdout') { should_not match('tcp dpt:80 state NEW') }
42 | its('exit_status') { should eq 0 }
43 | end
44 |
--------------------------------------------------------------------------------
/resources/chain.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook:: iptables
3 | # Resource:: chain
4 | #
5 | # Copyright:: 2012, Chris Aumann
6 | #
7 | # This program is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # This program is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # You should have received a copy of the GNU General Public License
18 | # along with this program. If not, see .
19 | #
20 |
21 | unified_mode true
22 |
23 | actions :create, :create_if_missing, :delete
24 | default_action :create
25 |
26 | # linux/netfilter/x_tables.h doesn't restrict chains very tightly. Just a string token
27 | # with a max length of XT_EXTENSION_MAXLEN (29 in all 3.x headers I could find)
28 | attribute :chain, kind_of: String, name_attribute: true, regex: /^[\w-]{1,29}$/
29 | attribute :table, kind_of: String, default: 'filter', equal_to: %w(filter nat mangle raw)
30 | attribute :policy, kind_of: String, default: 'ACCEPT [0:0]'
31 |
--------------------------------------------------------------------------------
/test/integration/lwrp_rule_create_custom/lwrp_rule_create_custom_test.rb:
--------------------------------------------------------------------------------
1 | # Should set custom iptables rule
2 | describe file('/etc/iptables.d/nat/OUTPUT/custom-output.rule_v4') do
3 | it { should exist }
4 | its('content') { should match('--protocol icmp --jump ACCEPT') }
5 | end
6 |
7 | # Should set custom ip6tables rule
8 | describe file('/etc/iptables.d/nat/OUTPUT/custom-output.rule_v6') do
9 | it { should exist }
10 | its('content') { should match('--protocol icmp --jump ACCEPT') }
11 | end
12 |
13 | service_ipv4 = case os.family
14 | when 'debian'
15 | 'netfilter-persistent'
16 | else
17 | 'iptables'
18 | end
19 |
20 | service_ipv6 = case os.family
21 | when 'debian'
22 | 'netfilter-persistent'
23 | else
24 | 'ip6tables'
25 | end
26 |
27 | # Should enable iptables serices
28 | describe service(service_ipv4) do
29 | it { should be_enabled }
30 | end
31 |
32 | describe service(service_ipv6) do
33 | it { should be_enabled }
34 | end
35 |
36 | # Should apply the specified iptables rules
37 | describe command('iptables -t nat -L -n') do
38 | its('stdout') { should match(/ACCEPT\s+icmp/) }
39 | its('exit_status') { should eq 0 }
40 | end
41 |
42 | describe command('ip6tables -t nat -L -n') do
43 | its('stdout') { should match(/ACCEPT\s+icmp/) }
44 | its('exit_status') { should eq 0 }
45 | end
46 |
--------------------------------------------------------------------------------
/test/integration/lwrp_rule_create_default/lwrp_rule_create_default_test.rb:
--------------------------------------------------------------------------------
1 | # Should set SSH iptables rule
2 | describe file('/etc/iptables.d/filter/INPUT/ssh.rule_v4') do
3 | it { should exist }
4 | its('content') { should match('--protocol tcp --dport 22 --match state --state NEW --jump ACCEPT') }
5 | end
6 |
7 | # Should set SSH ip6tables rule
8 | describe file('/etc/iptables.d/filter/INPUT/ssh.rule_v6') do
9 | it { should exist }
10 | its('content') { should match('--protocol tcp --dport 22 --match state --state NEW --jump ACCEPT') }
11 | end
12 |
13 | service_ipv4 = case os.family
14 | when 'debian'
15 | 'netfilter-persistent'
16 | else
17 | 'iptables'
18 | end
19 |
20 | service_ipv6 = case os.family
21 | when 'debian'
22 | 'netfilter-persistent'
23 | else
24 | 'ip6tables'
25 | end
26 |
27 | # Should enable iptables serices
28 | describe service(service_ipv4) do
29 | it { should be_enabled }
30 | end
31 |
32 | describe service(service_ipv6) do
33 | it { should be_enabled }
34 | end
35 |
36 | # Should apply the specified iptables rules
37 | describe command('iptables -L -n') do
38 | its('stdout') { should match('tcp dpt:22 state NEW') }
39 | its('exit_status') { should eq 0 }
40 | end
41 |
42 | describe command('ip6tables -L -n') do
43 | its('stdout') { should match('tcp dpt:22 state NEW') }
44 | its('exit_status') { should eq 0 }
45 | end
46 |
--------------------------------------------------------------------------------
/test/integration/lwrp_rule_create_custom_chain/lwrp_rule_create_custom_chain_test.rb:
--------------------------------------------------------------------------------
1 | # Should create the custom chain directory
2 | describe directory('/etc/iptables.d/nat/FOO') do
3 | it { should exist }
4 | end
5 |
6 | # Should set custom iptables rule
7 | describe file('/etc/iptables.d/nat/FOO/custom-chain-output.rule_v4') do
8 | it { should exist }
9 | its('content') { should match('--protocol icmp --jump ACCEPT') }
10 | end
11 |
12 | # Should set custom ip6tables rule
13 | describe file('/etc/iptables.d/nat/FOO/custom-chain-output.rule_v6') do
14 | it { should exist }
15 | its('content') { should match('--protocol icmp --jump ACCEPT') }
16 | end
17 |
18 | service_ipv4 = case os.family
19 | when 'debian'
20 | 'netfilter-persistent'
21 | else
22 | 'iptables'
23 | end
24 |
25 | service_ipv6 = case os.family
26 | when 'debian'
27 | 'netfilter-persistent'
28 | else
29 | 'ip6tables'
30 | end
31 |
32 | # Should enable iptables serices
33 | describe service(service_ipv4) do
34 | it { should be_enabled }
35 | end
36 |
37 | describe service(service_ipv6) do
38 | it { should be_enabled }
39 | end
40 |
41 | # Should apply the specified iptables rules
42 | describe command('iptables -t nat -L -n') do
43 | its('stdout') { should match(/ACCEPT\s+icmp/) }
44 | its('exit_status') { should eq 0 }
45 | end
46 |
47 | describe command('ip6tables -t nat -L -n') do
48 | its('stdout') { should match(/ACCEPT\s+icmp/) }
49 | its('exit_status') { should eq 0 }
50 | end
51 |
--------------------------------------------------------------------------------
/recipes/manage.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook:: iptables-ng
3 | # Recipe:: manage
4 | #
5 | # Copyright:: 2013, Chris Aumann
6 | #
7 | # This program is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # This program is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # You should have received a copy of the GNU General Public License
18 | # along with this program. If not, see .
19 | #
20 |
21 | # This recipe only creates ruby_blocks that are called later by the LWRPs
22 | # Do not use it by its own
23 |
24 | ruby_block 'create_rules' do
25 | block do
26 | class Chef::Resource::RubyBlock
27 | include Iptables::Manage
28 | end
29 |
30 | Array(node['iptables-ng']['enabled_ip_versions']).each do |ip_version|
31 | create_iptables_rules(ip_version)
32 | end
33 | end
34 |
35 | action :nothing
36 | end
37 |
38 | ruby_block 'restart_iptables' do
39 | block do
40 | class Chef::Resource::RubyBlock
41 | include Iptables::Manage
42 | end
43 |
44 | if node['iptables-ng']['managed_service']
45 | Array(node['iptables-ng']['enabled_ip_versions']).each do |ip_version|
46 | restart_service(ip_version)
47 | end
48 | end
49 | end
50 |
51 | action :nothing
52 | end
53 |
--------------------------------------------------------------------------------
/chefignore:
--------------------------------------------------------------------------------
1 | # Put files/directories that should be ignored in this file when uploading
2 | # or sharing to the community site.
3 | # Lines that start with '# ' are comments.
4 |
5 | # OS generated files #
6 | ######################
7 | .DS_Store
8 | Icon?
9 | nohup.out
10 | ehthumbs.db
11 | Thumbs.db
12 |
13 | # SASS #
14 | ########
15 | .sass-cache
16 |
17 | # EDITORS #
18 | ###########
19 | \#*
20 | .#*
21 | *~
22 | *.sw[a-z]
23 | *.bak
24 | REVISION
25 | TAGS*
26 | tmtags
27 | *_flymake.*
28 | *_flymake
29 | *.tmproj
30 | .project
31 | .settings
32 | mkmf.log
33 |
34 | ## COMPILED ##
35 | ##############
36 | a.out
37 | *.o
38 | *.pyc
39 | *.so
40 | *.com
41 | *.class
42 | *.dll
43 | *.exe
44 | */rdoc/
45 |
46 | # Testing #
47 | ###########
48 | .watchr
49 | .rspec
50 | spec/*
51 | spec/fixtures/*
52 | test/*
53 | features/*
54 | Guardfile
55 | Procfile
56 |
57 | # SCM #
58 | #######
59 | .git
60 | */.git
61 | .gitignore
62 | .gitmodules
63 | .gitconfig
64 | .gitattributes
65 | .svn
66 | */.bzr/*
67 | */.hg/*
68 | */.svn/*
69 |
70 | # Berkshelf #
71 | #############
72 | Berksfile
73 | Berksfile.lock
74 | cookbooks/*
75 | tmp
76 |
77 | # Cookbooks #
78 | #############
79 | CONTRIBUTING
80 | CHANGELOG*
81 |
82 | # Strainer #
83 | ############
84 | Colanderfile
85 | Strainerfile
86 | .colander
87 | .strainer
88 |
89 | # Vagrant #
90 | ###########
91 | .vagrant
92 | Vagrantfile
93 |
94 | # Travis #
95 | ##########
96 | .travis.yml
97 |
98 | .bundle
99 | .kitchen
100 | *~
101 | *#
102 | .#*
103 | \#*#
104 | .*.sw[a-z]
105 | *.un~
106 | .bundle
107 | .cache
108 | .kitchen
109 | bin
110 | .kitchen.local.yml
111 |
--------------------------------------------------------------------------------
/.github/workflows/chef.yml:
--------------------------------------------------------------------------------
1 | name: Chef
2 |
3 | on:
4 | push:
5 | branches: [ master ]
6 | pull_request:
7 | branches: [ master ]
8 |
9 | jobs:
10 | integration:
11 | runs-on: ubuntu-latest
12 | strategy:
13 | matrix:
14 | os:
15 | # NOTE: Commented out (older) versions do not work on Github Actions with this cookbook
16 | # - 'centos-7'
17 | - 'centos-8'
18 | - 'debian-10'
19 | - 'debian-11'
20 | # - 'ubuntu-1604'
21 | # - 'ubuntu-1804'
22 | # - 'ubuntu-2004'
23 | - 'ubuntu-2204'
24 | suite:
25 | - 'lwrp-chain-create-default'
26 | - 'lwrp-chain-create-custom'
27 | - 'lwrp-chain-create-if-missing'
28 | - 'lwrp-chain-create-empty'
29 | - 'lwrp-rule-create-default'
30 | - 'lwrp-rule-create-custom'
31 | - 'lwrp-rule-create-custom-chain'
32 | - 'lwrp-rule-create-if-missing'
33 | - 'lwrp-rule-delete'
34 | - 'lwrp-rule-check-order'
35 | - 'default'
36 | - 'install'
37 | - 'attribute-enabled-tables'
38 | fail-fast: false
39 | steps:
40 | - name: Check out code
41 | uses: actions/checkout@master
42 | - name: Install Chef
43 | uses: actionshub/chef-install@main
44 | - name: Linting
45 | run: cookstyle -f simple || (echo "Run 'cookstyle -a' to correct cookstyle errors." && exit 1)
46 | - name: test-kitchen
47 | uses: actionshub/test-kitchen@main
48 | with:
49 | suite: ${{ matrix.suite }}
50 | os: ${{ matrix.os }}
51 | env:
52 | CHEF_LICENSE: accept-no-persist
53 | KITCHEN_LOCAL_YAML: kitchen.dokken.yml
54 |
--------------------------------------------------------------------------------
/test/integration/lwrp_rule_create_if_missing/lwrp_rule_create_if_missing_test.rb:
--------------------------------------------------------------------------------
1 | # Should set SSH iptables rule
2 | describe file('/etc/iptables.d/filter/INPUT/ssh.rule_v4') do
3 | it { should exist }
4 | its('content') { should match('--protocol tcp --dport 22 --match state --state NEW --jump ACCEPT') }
5 | its('content') { should_not match('--protocol tcp --dport 80 --match state --state NEW --jump ACCEPT') }
6 | end
7 |
8 | # Should set SSH ip6tables rule
9 | describe file('/etc/iptables.d/filter/INPUT/ssh.rule_v6') do
10 | it { should exist }
11 | its('content') { should match('--protocol tcp --dport 22 --match state --state NEW --jump ACCEPT') }
12 | its('content') { should_not match('--protocol tcp --dport 80 --match state --state NEW --jump ACCEPT') }
13 | end
14 |
15 | service_ipv4 = case os.family
16 | when 'debian'
17 | 'netfilter-persistent'
18 | else
19 | 'iptables'
20 | end
21 |
22 | service_ipv6 = case os.family
23 | when 'debian'
24 | 'netfilter-persistent'
25 | else
26 | 'ip6tables'
27 | end
28 |
29 | # Should enable iptables serices
30 | describe service(service_ipv4) do
31 | it { should be_enabled }
32 | end
33 |
34 | describe service(service_ipv6) do
35 | it { should be_enabled }
36 | end
37 |
38 | # Should apply the specified iptables rules
39 | describe command('iptables -L -n') do
40 | its('stdout') { should match('tcp dpt:22 state NEW') }
41 | its('stdout') { should_not match('tcp dpt:80 state NEW') }
42 | its('exit_status') { should eq 0 }
43 | end
44 |
45 | describe command('ip6tables -L -n') do
46 | its('stdout') { should match('tcp dpt:22 state NEW') }
47 | its('stdout') { should_not match('tcp dpt:80 state NEW') }
48 | its('exit_status') { should eq 0 }
49 | end
50 |
--------------------------------------------------------------------------------
/attributes/rules.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook:: iptables-ng
3 | # Attributes:: default-rules
4 | #
5 | # Copyright:: 2012, Chris Aumann
6 | #
7 | # This program is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # This program is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # You should have received a copy of the GNU General Public License
18 | # along with this program. If not, see .
19 | #
20 |
21 | # Set up default policies
22 | default['iptables-ng']['rules']['filter']['INPUT']['default'] = 'ACCEPT [0:0]'
23 | default['iptables-ng']['rules']['filter']['OUTPUT']['default'] = 'ACCEPT [0:0]'
24 | default['iptables-ng']['rules']['filter']['FORWARD']['default'] = 'ACCEPT [0:0]'
25 |
26 | default['iptables-ng']['rules']['nat']['OUTPUT']['default'] = 'ACCEPT [0:0]'
27 | default['iptables-ng']['rules']['nat']['PREROUTING']['default'] = 'ACCEPT [0:0]'
28 | default['iptables-ng']['rules']['nat']['POSTROUTING']['default'] = 'ACCEPT [0:0]'
29 |
30 | default['iptables-ng']['rules']['mangle']['INPUT']['default'] = 'ACCEPT [0:0]'
31 | default['iptables-ng']['rules']['mangle']['OUTPUT']['default'] = 'ACCEPT [0:0]'
32 | default['iptables-ng']['rules']['mangle']['FORWARD']['default'] = 'ACCEPT [0:0]'
33 | default['iptables-ng']['rules']['mangle']['PREROUTING']['default'] = 'ACCEPT [0:0]'
34 | default['iptables-ng']['rules']['mangle']['POSTROUTING']['default'] = 'ACCEPT [0:0]'
35 |
36 | default['iptables-ng']['rules']['raw']['OUTPUT']['default'] = 'ACCEPT [0:0]'
37 | default['iptables-ng']['rules']['raw']['PREROUTING']['default'] = 'ACCEPT [0:0]'
38 |
--------------------------------------------------------------------------------
/resources/rule.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook:: iptables
3 | # Resource:: rule
4 | #
5 | # Copyright:: 2012, Chris Aumann
6 | #
7 | # This program is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # This program is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # You should have received a copy of the GNU General Public License
18 | # along with this program. If not, see .
19 | #
20 |
21 | unified_mode true
22 |
23 | actions :create, :create_if_missing, :delete
24 | default_action :create
25 |
26 | # Allow only dashes, underscores word characters and dots in rule name
27 | # As the name attribute will be used as a filename later
28 | attribute :name, kind_of: String, name_attribute: true, regex: /^[-\w\.]+$/
29 | # linux/netfilter/x_tables.h doesn't restrict chains very tightly. Just a string token
30 | # with a max length of XT_EXTENSION_MAXLEN (29 in all 3.x headers I could find)
31 | attribute :chain, kind_of: String, default: 'INPUT', regex: /^[\w-]{1,29}$/
32 | attribute :table, kind_of: String, default: 'filter', equal_to: %w(filter nat mangle raw)
33 | attribute :rule, kind_of: [Array, String], default: []
34 | attribute :ip_version, kind_of: [Array, Integer], default: lazy { node['iptables-ng']['enabled_ip_versions'] }, equal_to: [[4, 6], [4], [6], 4, 6]
35 |
36 | def path_for_chain
37 | "/etc/iptables.d/#{table}/#{chain}"
38 | end
39 |
40 | def path_for_ip_version(version)
41 | "#{path_for_chain}/#{name}.rule_v#{version}"
42 | end
43 |
44 | def paths
45 | Array(ip_version).map do |version|
46 | path_for_ip_version version
47 | end
48 | end
49 |
--------------------------------------------------------------------------------
/providers/chain.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook:: iptables-ng
3 | # Provider:: chain
4 | #
5 | # Copyright:: 2012, Chris Aumann
6 | #
7 | # This program is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # This program is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # You should have received a copy of the GNU General Public License
18 | # along with this program. If not, see .
19 | #
20 |
21 | require 'date'
22 |
23 | action :create do
24 | edit_chain(:create)
25 | end
26 |
27 | action :create_if_missing do
28 | edit_chain(:create_if_missing)
29 | end
30 |
31 | action :delete do
32 | edit_chain(:delete)
33 | end
34 |
35 | def edit_chain(exec_action)
36 | # Only default chains can have a policy
37 | policy =
38 | if %w(INPUT OUTPUT FORWARD PREROUTING POSTROUTING).include?(new_resource.chain)
39 | new_resource.policy
40 | else
41 | '- [0:0]'
42 | end
43 |
44 | chain_path = "/etc/iptables.d/#{new_resource.table}/#{new_resource.chain}/default"
45 |
46 | # Generate a random resource identifier to workaround Chef cloning issues
47 | rnd_resource = "#{chain_path}-#{DateTime.now.to_time.to_i}-#{rand(100_000)}"
48 |
49 | directory rnd_resource do
50 | path ::File.dirname(chain_path)
51 | owner 'root'
52 | group node['root_group']
53 | mode '700'
54 | not_if { exec_action == :delete }
55 | end
56 |
57 | file rnd_resource do
58 | path chain_path
59 | owner 'root'
60 | group node['root_group']
61 | mode '600'
62 | content "#{policy}\n"
63 | notifies :run, 'ruby_block[create_rules]', :delayed
64 | notifies :run, 'ruby_block[restart_iptables]', :delayed
65 | action exec_action
66 | end
67 | end
68 |
--------------------------------------------------------------------------------
/providers/rule.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook:: iptables-ng
3 | # Provider:: rule
4 | #
5 | # Copyright:: 2012, Chris Aumann
6 | #
7 | # This program is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # This program is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # You should have received a copy of the GNU General Public License
18 | # along with this program. If not, see .
19 | #
20 |
21 | action :create do
22 | edit_rule(:create)
23 | end
24 |
25 | action :create_if_missing do
26 | edit_rule(:create_if_missing)
27 | end
28 |
29 | action :delete do
30 | edit_rule(:delete)
31 | end
32 |
33 | def edit_rule(exec_action)
34 | # Create rule for given ip_versions
35 | Array(new_resource.ip_version).each do |ip_version|
36 | # Skip nat table if ip6tables doesn't support it
37 | next if new_resource.table == 'nat' &&
38 | node['iptables-ng']['ip6tables_nat_support'] == false &&
39 | ip_version == 6
40 |
41 | rule_path = new_resource.path_for_ip_version(ip_version)
42 |
43 | rule_content = Array(new_resource.rule).map do |rule|
44 | "--append #{new_resource.chain} #{rule.chomp}"
45 | end.join("\n")
46 |
47 | directory rule_path do
48 | path ::File.dirname(rule_path)
49 | owner 'root'
50 | group node['root_group']
51 | mode '700'
52 | not_if { exec_action == :delete }
53 | end
54 |
55 | file new_resource.path_for_ip_version(ip_version) do
56 | owner 'root'
57 | group node['root_group']
58 | mode '600'
59 | content rule_content
60 | notifies :run, 'ruby_block[create_rules]', :delayed
61 | notifies :run, 'ruby_block[restart_iptables]', :delayed
62 | action exec_action
63 | end
64 | end
65 |
66 | # TODO: Link to .rule for rhel compatibility?
67 | end
68 |
--------------------------------------------------------------------------------
/libraries/restart_service.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook:: iptables-ng
3 | # Recipe:: restart_service
4 | #
5 | # Copyright:: 2013, Chris Aumann
6 | #
7 | # This program is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # This program is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # You should have received a copy of the GNU General Public License
18 | # along with this program. If not, see .
19 | #
20 |
21 | # This was implemented as a internal-only provider.
22 | # Apparently, calling a LWRP from a LWRP doesnt' really work with
23 | # subscribes / notifies. Therefore, using this workaround.
24 |
25 | module Iptables
26 | module Manage
27 | def restart_service(ip_version)
28 | # Restart iptables service if available
29 | if node['iptables-ng']["service_ipv#{ip_version}"]
30 |
31 | # Do not restart twice if the command is the same for ipv4 and ipv6
32 | return if node['iptables-ng']['service_ipv4'] == node['iptables-ng']['service_ipv6'] && ip_version == 6
33 |
34 | Chef::Resource::Service.new(node['iptables-ng']["service_ipv#{ip_version}"], run_context).tap do |service|
35 | service.supports(status: true, restart: true)
36 | service.run_action(:enable)
37 | service.run_action(:restart)
38 | end
39 |
40 | # If no service is available, apply the rules manually
41 | else
42 | Chef::Log.info 'applying rules manually, as no service is specified'
43 | Chef::Resource::Execute.new("iptables-restore for ipv#{ip_version}", run_context).tap do |execute|
44 | execute.command("iptables-restore < #{node['iptables-ng']['script_ipv4']}") if ip_version == 4
45 | execute.command("ip6tables-restore < #{node['iptables-ng']['script_ipv6']}") if ip_version == 6
46 | execute.run_action(:run)
47 | end
48 | end
49 | end
50 | end
51 | end
52 |
--------------------------------------------------------------------------------
/recipes/install.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook:: iptables-ng
3 | # Recipe:: install
4 | #
5 | # Copyright:: 2013, Chris Aumann
6 | #
7 | # This program is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # This program is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # You should have received a copy of the GNU General Public License
18 | # along with this program. If not, see .
19 | #
20 |
21 | include_recipe 'iptables-ng::manage'
22 |
23 | # Make sure iptables is installed
24 | Array(node['iptables-ng']['packages']).each do |pkg|
25 | package "iptables-ng::install - #{pkg} package" do
26 | package_name pkg
27 | notifies :run, 'execute[iptables-ng::install - systemctl daemon-reload]', :immediately
28 | end
29 | end
30 |
31 | # Check to see if we're using systemd so we run systemctl daemon-reload to pick up new services
32 | execute 'iptables-ng::install - systemctl daemon-reload' do
33 | command 'systemctl daemon-reload'
34 | action :nothing
35 | only_if { systemd? }
36 | end
37 |
38 | # Make sure ufw is not installed on Ubuntu/Debian, as it might interfere
39 | package 'iptables-ng::install - ufw package' do
40 | package_name 'uwf'
41 | action :remove
42 | only_if { platform_family?('debian') }
43 | end
44 |
45 | # Create directories
46 | directory '/etc/iptables.d' do
47 | mode '700'
48 | end
49 |
50 | node['iptables-ng']['rules'].each do |table, chains|
51 | # Skip deactivated tables
52 | next unless node['iptables-ng']['enabled_tables'].include?(table)
53 |
54 | directory "/etc/iptables.d/#{table}" do
55 | mode '700'
56 | end
57 |
58 | # Create default policies unless they exist
59 | chains.each do |chain, policy|
60 | iptables_ng_chain "default-policy-#{table}-#{chain}" do
61 | chain chain
62 | table table
63 | policy policy['default']
64 | action :create_if_missing
65 | end
66 | end
67 | end
68 |
--------------------------------------------------------------------------------
/recipes/default.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook:: iptables-ng
3 | # Recipe:: default
4 | #
5 | # Copyright:: 2013, Chris Aumann
6 | #
7 | # This program is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # This program is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # You should have received a copy of the GNU General Public License
18 | # along with this program. If not, see .
19 | #
20 |
21 | include_recipe 'iptables-ng::install'
22 |
23 | # Apply rules from node attributes
24 | node['iptables-ng']['rules'].each do |table, chains|
25 | # Skip deactivated tables
26 | next unless node['iptables-ng']['enabled_tables'].include?(table)
27 |
28 | chains.each do |chain, p|
29 | # policy is read only, duplicate it
30 | policy = p.dup
31 |
32 | # Apply chain policy
33 | iptables_ng_chain "attribute-policy-#{chain}-#{table}" do
34 | chain chain
35 | table table
36 | policy policy.delete('default')
37 | end
38 |
39 | # Gather rules from filesystem to delete unused ones later
40 | unused = Dir["/etc/iptables.d/#{table}/#{chain}/*-#{table}-#{chain}-attribute-rule.*"]
41 |
42 | # Apply rules
43 | policy.each do |name, r|
44 | res = iptables_ng_rule "#{name}-#{table}-#{chain}-attribute-rule" do
45 | chain chain
46 | table table
47 | rule r['rule']
48 | ip_version r['ip_version'] if r['ip_version']
49 | action r['action'].to_sym if r['action']
50 | end
51 |
52 | # Remove from unused rules
53 | unused -= res.paths
54 | end
55 |
56 | # Delete unused rules now
57 | unused.each do |path|
58 | file path do
59 | notifies :run, 'ruby_block[create_rules]', :delayed
60 | notifies :run, 'ruby_block[restart_iptables]', :delayed
61 | action :delete
62 | only_if { node['iptables-ng']['auto_prune_attribute_rules'] }
63 | end
64 | end
65 | end
66 | end
67 |
--------------------------------------------------------------------------------
/spec/install_spec.rb:
--------------------------------------------------------------------------------
1 | require 'spec_helper'
2 |
3 | describe 'iptables-ng::install' do
4 | describe 'debian' do
5 | let(:chef_run) do
6 | ChefSpec::ServerRunner.new do |node|
7 | node.automatic['platform_family'] = 'debian'
8 | end.converge(described_recipe)
9 | end
10 |
11 | it 'should remove ufw' do
12 | expect(chef_run).to remove_package('iptables-ng::install - ufw package')
13 | end
14 | end
15 |
16 | let(:chef_run) do
17 | ChefSpec::ServerRunner.new do |node|
18 | node.automatic.merge!(JSON.parse(File.read('test/nodes/test.json')))
19 | end.converge(described_recipe)
20 | end
21 |
22 | it 'should include iptables-ng::manage' do
23 | expect(chef_run).to include_recipe('iptables-ng::manage')
24 | end
25 |
26 | it 'should create directory for chains' do
27 | expect(chef_run).to create_directory('/etc/iptables.d/filter')
28 | expect(chef_run).to create_directory('/etc/iptables.d/nat')
29 | expect(chef_run).to create_directory('/etc/iptables.d/mangle')
30 | expect(chef_run).to create_directory('/etc/iptables.d/raw')
31 | end
32 |
33 | it 'should apply default policies' do
34 | expect(chef_run).to create_if_missing_iptables_ng_chain('default-policy-filter-INPUT')
35 | expect(chef_run).to create_if_missing_iptables_ng_chain('default-policy-filter-OUTPUT')
36 | expect(chef_run).to create_if_missing_iptables_ng_chain('default-policy-filter-FORWARD')
37 | expect(chef_run).to create_if_missing_iptables_ng_chain('default-policy-nat-OUTPUT')
38 | expect(chef_run).to create_if_missing_iptables_ng_chain('default-policy-nat-PREROUTING')
39 | expect(chef_run).to create_if_missing_iptables_ng_chain('default-policy-nat-POSTROUTING')
40 | expect(chef_run).to create_if_missing_iptables_ng_chain('default-policy-mangle-INPUT')
41 | expect(chef_run).to create_if_missing_iptables_ng_chain('default-policy-mangle-OUTPUT')
42 | expect(chef_run).to create_if_missing_iptables_ng_chain('default-policy-mangle-FORWARD')
43 | expect(chef_run).to create_if_missing_iptables_ng_chain('default-policy-mangle-PREROUTING')
44 | expect(chef_run).to create_if_missing_iptables_ng_chain('default-policy-mangle-POSTROUTING')
45 | expect(chef_run).to create_if_missing_iptables_ng_chain('default-policy-raw-OUTPUT')
46 | expect(chef_run).to create_if_missing_iptables_ng_chain('default-policy-raw-PREROUTING')
47 | end
48 | end
49 |
--------------------------------------------------------------------------------
/test/integration/attribute_enabled_tables/attribute_enabled_tables_test.rb:
--------------------------------------------------------------------------------
1 | # Should not create default mangle FORWARD policy
2 | describe file('/etc/iptables.d/mangle/FORWARD/default4') do
3 | it { should_not exist }
4 | end
5 |
6 | # Should not create default nat FORWARD policy
7 | describe file('/etc/iptables.d/nat/FORWARD/default') do
8 | it { should_not exist }
9 | end
10 |
11 | # Should not create default raw FORARD policy
12 | describe file('/etc/iptables.d/raw/default') do
13 | it { should_not exist }
14 | end
15 |
16 | # Should not create iptables OUTPUT test_rule
17 | describe file('/etc/iptables.d/filter/OUTPUT/testrule-filter-OUTPUT-attribute-rule.rule_v4') do
18 | it { should_not exist }
19 | end
20 |
21 | # Should not create ip6tables OUTPUT test_rule
22 | describe file('/etc/iptables.d/filter/OUTPUT/testrule-filter-OUTPUT-attribute-rule.rule_v6') do
23 | it { should_not exist }
24 | end
25 |
26 | # Should create SSH iptables rule
27 | describe file('/etc/iptables.d/filter/INPUT/ssh-filter-INPUT-attribute-rule.rule_v4') do
28 | it { should exist }
29 | its('content') { should match('--protocol tcp --dport 22 --match state --state NEW --jump ACCEPT') }
30 | end
31 |
32 | # Should create SSH ip6tables rule
33 | describe file('/etc/iptables.d/filter/INPUT/ssh-filter-INPUT-attribute-rule.rule_v6') do
34 | it { should exist }
35 | its('content') { should match('--protocol tcp --dport 22 --match state --state NEW --jump ACCEPT') }
36 | end
37 |
38 | # Should apply SSH iptables rule
39 | describe command('iptables -L -n') do
40 | its('stdout') { should match('tcp dpt:22 state NEW') }
41 | its('exit_status') { should eq 0 }
42 | end
43 |
44 | describe command('ip6tables -L -n') do
45 | its('stdout') { should match('tcp dpt:22 state NEW') }
46 | its('exit_status') { should eq 0 }
47 | end
48 |
49 | # Should create ipv4_only iptables rule
50 | describe file('/etc/iptables.d/filter/INPUT/ipv4_only-filter-INPUT-attribute-rule.rule_v4') do
51 | it { should exist }
52 | its('content') { should match('--protocol tcp --source 1.2.3.4 --dport 123 --jump ACCEPT') }
53 | end
54 |
55 | # Should not create ipv4_only ip6tables rule
56 | describe file('/etc/iptables.d/filter/INPUT/ipv4_only-filter-INPUT-attribute-rule.rule_v6') do
57 | it { should_not exist }
58 | end
59 |
60 | # Should apply ipv4_only iptables rule
61 | describe command('iptables -L -n') do
62 | its('stdout') { should match('tcp dpt:123') }
63 | its('exit_status') { should eq 0 }
64 | end
65 |
66 | service_ipv4 = case os.family
67 | when 'debian'
68 | 'netfilter-persistent'
69 | else
70 | 'iptables'
71 | end
72 |
73 | service_ipv6 = case os.family
74 | when 'debian'
75 | 'netfilter-persistent'
76 | else
77 | 'ip6tables'
78 | end
79 |
80 | # Should enable iptables serices
81 | describe service(service_ipv4) do
82 | it { should be_enabled }
83 | end
84 |
85 | describe service(service_ipv6) do
86 | it { should be_enabled }
87 | end
88 |
--------------------------------------------------------------------------------
/libraries/create_iptables_rules.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook:: iptables-ng
3 | # Recipe:: manage
4 | #
5 | # Copyright:: 2013, Chris Aumann
6 | #
7 | # This program is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # This program is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # You should have received a copy of the GNU General Public License
18 | # along with this program. If not, see .
19 | #
20 |
21 | # This was implemented as a internal-only provider.
22 | # Apparently, calling a LWRP from a LWRP doesnt' really work with
23 | # subscribes / notifies. Therefore, using this workaround.
24 |
25 | module Iptables
26 | module Manage
27 | def create_iptables_rules(ip_version)
28 | rules = {}
29 |
30 | # Retrieve all iptables rules for this ip_version,
31 | # as well as default policies
32 | Dir["/etc/iptables.d/*/*/*.rule_v#{ip_version}",
33 | '/etc/iptables.d/*/*/default'].each do |path|
34 | # /etc/iptables.d/#{table}/#{chain}/#{rule}.rule_v#{ip_version}
35 | table, chain, filename = path.split('/')[3..5]
36 | rule = ::File.basename(filename)
37 |
38 | # Skip nat table if ip6tables doesn't support it
39 | next if table == 'nat' &&
40 | node['iptables-ng']['ip6tables_nat_support'] == false &&
41 | ip_version == 6
42 |
43 | # Skip deactivated tables
44 | next unless node['iptables-ng']['enabled_tables'].include?(table)
45 |
46 | # Create hashes unless they already exist, and add the rule
47 | rules[table] ||= {}
48 | rules[table][chain] ||= {}
49 | rules[table][chain][rule] = ::File.read(path)
50 | end
51 |
52 | iptables_restore = ''
53 | rules.each do |table, chains|
54 | iptables_restore << "*#{table}\n"
55 |
56 | # Get default policies and rules for this chain
57 | default_policies = chains.each_with_object({}) do |rule, new_chain|
58 | new_chain[rule[0]] = rule[1].select { |k, _| k == 'default' }
59 | end
60 |
61 | all_chain_rules = chains.each_with_object({}) do |rule, new_chain|
62 | new_chain[rule[0]] = rule[1].reject { |k, _| k == 'default' }
63 | end
64 |
65 | # Apply default policies first
66 | default_policies.each do |chain, policy|
67 | iptables_restore << ":#{chain} #{policy['default'].chomp}\n"
68 | end
69 |
70 | # Apply rules for this chain, but sort before adding
71 | all_chain_rules.each do |_chain, chain_rules|
72 | chain_rules.sort.each { |r| iptables_restore << "#{r.last.chomp}\n" }
73 | end
74 |
75 | iptables_restore << "COMMIT\n"
76 | end
77 |
78 | Chef::Resource::File.new(node['iptables-ng']["script_ipv#{ip_version}"], run_context).tap do |file|
79 | file.owner('root')
80 | file.group(node['root_group'])
81 | file.mode(0o600)
82 | file.content(iptables_restore)
83 | file.run_action(:create)
84 | end
85 | end
86 | end
87 | end
88 |
--------------------------------------------------------------------------------
/kitchen.yml:
--------------------------------------------------------------------------------
1 | ---
2 | driver:
3 | name: vagrant
4 |
5 | driver_config:
6 | customize:
7 | memory: 512
8 |
9 | provisioner:
10 | name: chef_zero
11 | product_name: chef
12 | # product_version: 13 # default is 'latest', uncomment to test old Chef version
13 |
14 | verifier:
15 | name: inspec
16 |
17 | platforms:
18 | - name: ubuntu-18.04
19 | - name: ubuntu-20.04
20 | - name: ubuntu-22.04
21 | - name: debian-10
22 | - name: debian-11
23 | - name: centos-7
24 | - name: centos-8
25 |
26 | suites:
27 | - name: lwrp_chain_create_default
28 | run_list:
29 | - recipe[iptables_ng_test::lwrp_chain_create_default]
30 | - name: lwrp_chain_create_custom
31 | run_list:
32 | - recipe[iptables_ng_test::lwrp_chain_create_custom]
33 | - name: lwrp_chain_create_if_missing
34 | run_list:
35 | - recipe[iptables_ng_test::lwrp_chain_create_if_missing]
36 | - name: lwrp_chain_create_empty
37 | run_list:
38 | - recipe[iptables_ng_test::lwrp_chain_create_empty]
39 |
40 | - name: lwrp_rule_create_default
41 | run_list:
42 | - recipe[iptables_ng_test::lwrp_rule_create_default]
43 | - name: lwrp_rule_create_custom
44 | run_list:
45 | - recipe[iptables_ng_test::lwrp_rule_create_custom]
46 | - name: lwrp_rule_create_custom_chain
47 | run_list:
48 | - recipe[iptables_ng_test::lwrp_rule_create_custom_chain]
49 | - name: lwrp_rule_create_if_missing
50 | run_list:
51 | - recipe[iptables_ng_test::lwrp_rule_create_if_missing]
52 | - name: lwrp_rule_delete
53 | run_list:
54 | - recipe[iptables_ng_test::lwrp_rule_delete]
55 | - name: lwrp_rule_check_order
56 | run_list:
57 | - recipe[iptables_ng_test::lwrp_rule_check_order]
58 |
59 | - name: default
60 | run_list:
61 | - recipe[iptables_ng_test::recipe_default]
62 | attributes:
63 | iptables-ng:
64 | rules:
65 | filter:
66 | INPUT:
67 | ssh:
68 | rule: '--protocol tcp --dport 22 --match state --state NEW --jump ACCEPT'
69 | ipv4_only:
70 | rule: '--protocol tcp --source 1.2.3.4 --dport 123 --jump ACCEPT'
71 | ip_version: 4
72 | OUTPUT:
73 | testrule:
74 | rule: '--protocol icmp --jump ACCEPT'
75 | FORWARD:
76 | default: 'DROP [0:0]'
77 | nat:
78 | POSTROUTING:
79 | nat_test:
80 | rule: '--protocol tcp -j ACCEPT'
81 | mangle:
82 | FORWARD:
83 | default: 'DROP [0:0]'
84 |
85 | - name: install
86 | run_list:
87 | - recipe[iptables_ng_test::recipe_install]
88 |
89 | - name: attribute_enabled_tables
90 | run_list:
91 | - recipe[iptables_ng_test::attribute_enabled_tables]
92 | attributes:
93 | iptables-ng:
94 | enabled_tables: [ 'filter' ]
95 | rules:
96 | filter:
97 | INPUT:
98 | ssh:
99 | rule: '--protocol tcp --dport 22 --match state --state NEW --jump ACCEPT'
100 | ipv4_only:
101 | rule: '--protocol tcp --source 1.2.3.4 --dport 123 --jump ACCEPT'
102 | ip_version: 4
103 | nat:
104 | POSTROUTING:
105 | nat_test:
106 | rule: '--protocol tcp -j ACCEPT'
107 | mangle:
108 | FORWARD:
109 | default: 'DROP [0:0]'
110 |
--------------------------------------------------------------------------------
/attributes/default.rb:
--------------------------------------------------------------------------------
1 | #
2 | # Cookbook:: iptables-ng
3 | # Attributes:: default
4 | #
5 | # Copyright:: 2012, Chris Aumann
6 | #
7 | # This program is free software: you can redistribute it and/or modify
8 | # it under the terms of the GNU General Public License as published by
9 | # the Free Software Foundation, either version 3 of the License, or
10 | # (at your option) any later version.
11 | #
12 | # This program is distributed in the hope that it will be useful,
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 | # GNU General Public License for more details.
16 | #
17 | # You should have received a copy of the GNU General Public License
18 | # along with this program. If not, see .
19 | #
20 |
21 | # Which IP versions to manage rules for
22 | default['iptables-ng']['enabled_ip_versions'] = [4, 6]
23 |
24 | # Which tables to manage:
25 | # When using containered setup (OpenVZ, Docker, LXC) it might might be
26 | # necessary to remove the "nat" and "raw" tables.
27 | default['iptables-ng']['enabled_tables'] = %w(nat filter mangle raw)
28 |
29 | # Configure whether the service should be managed by Chef
30 | # /!\ Be careful when using this feature as it might leave your server in an inconsistent state.
31 | # See https://github.com/chr4-cookbooks/iptables-ng/pull/42 for more details.
32 | default['iptables-ng']['managed_service'] = true
33 |
34 | # Configure whether to automatically clean up unused rules
35 | default['iptables-ng']['auto_prune_attribute_rules'] = false
36 |
37 | # Enable nat support for ipv6
38 | default['iptables-ng']['ip6tables_nat_support'] = true
39 |
40 | # Packages to install
41 | default['iptables-ng']['packages'] =
42 | case node['platform_family']
43 | when 'debian'
44 | %w(iptables iptables-persistent)
45 | when 'rhel'
46 | if platform?('amazon')
47 | # Amazon Linux doesn't include "iptables-services" or "iptables-ipv6"
48 | %w(iptables)
49 | elsif node['platform_version'].to_f >= 7.0
50 | %w(iptables iptables-services)
51 | else
52 | %w(iptables iptables-ipv6)
53 | end
54 | else
55 | %w(iptables)
56 | end
57 |
58 | # Where the rules are stored and how they are executed
59 | # rubocop:disable Style/IdenticalConditionalBranches
60 | case node['platform']
61 | when 'debian'
62 | default['iptables-ng']['service_ipv4'] = 'netfilter-persistent'
63 | default['iptables-ng']['service_ipv6'] = 'netfilter-persistent'
64 | default['iptables-ng']['script_ipv4'] = '/etc/iptables/rules.v4'
65 | default['iptables-ng']['script_ipv6'] = '/etc/iptables/rules.v6'
66 |
67 | when 'ubuntu'
68 | default['iptables-ng']['service_ipv4'] = 'netfilter-persistent'
69 | default['iptables-ng']['service_ipv6'] = 'netfilter-persistent'
70 | default['iptables-ng']['script_ipv4'] = '/etc/iptables/rules.v4'
71 | default['iptables-ng']['script_ipv6'] = '/etc/iptables/rules.v6'
72 |
73 | when 'redhat', 'centos', 'scientific', 'amazon', 'fedora'
74 | default['iptables-ng']['service_ipv4'] = 'iptables'
75 | default['iptables-ng']['service_ipv6'] = 'ip6tables'
76 | default['iptables-ng']['script_ipv4'] = '/etc/sysconfig/iptables'
77 | default['iptables-ng']['script_ipv6'] = '/etc/sysconfig/ip6tables'
78 |
79 | when 'gentoo'
80 | default['iptables-ng']['service_ipv4'] = 'iptables'
81 | default['iptables-ng']['service_ipv6'] = 'ip6tables'
82 | default['iptables-ng']['script_ipv4'] = '/var/lib/iptables/rules-save'
83 | default['iptables-ng']['script_ipv6'] = '/var/lib/ip6tables/rules-save'
84 |
85 | when 'arch'
86 | default['iptables-ng']['service_ipv4'] = 'iptables'
87 | default['iptables-ng']['service_ipv6'] = 'ip6tables'
88 | default['iptables-ng']['script_ipv4'] = '/etc/iptables/iptables.rules'
89 | default['iptables-ng']['script_ipv6'] = '/etc/iptables/ip6tables.rules'
90 |
91 | else
92 | default['iptables-ng']['script_ipv4'] = '/etc/iptables-rules.ipt'
93 | default['iptables-ng']['script_ipv6'] = '/etc/ip6tables-rules.ipt'
94 | end
95 | # rubocop:enable Style/IdenticalConditionalBranches
96 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | iptables-ng CHANGELOG
2 | =====================
3 |
4 | This file is used to list changes made in each version of the iptables-ng cookbook.
5 |
6 | 4.1.0
7 | -----
8 |
9 | - Remove deprecated foodcritic linting
10 | - Apply cookstyle linting fixes
11 | - Enable unified_mode
12 | - Rewrite tests to Inspec, remove deprecated minitest
13 | - Remove logic for EOL distros
14 | - Update kitchen test platforms
15 | - Support Github Actions for integration tests
16 |
17 |
18 | 4.0.0
19 | -----
20 |
21 | - Add support for Chef-13
22 |
23 | NOTE: If you want to continue using `iptables-ng` on Chef 12, version lock this cookbook to `3.0.1`. This can be achieved by putting the following in your `Berksfile`:
24 |
25 | ```ruby
26 | cookbook 'iptables-ng', '~> 3.0.1'
27 | ```
28 |
29 | 3.0.1
30 | -----
31 |
32 | - Fix issue with resource cloning in Chef 13
33 |
34 | 3.0.0
35 | -----
36 |
37 | Release to workaround cloning issues, for the upcoming Chef-13 release:
38 | - Removed the feature to automatically run `iptables-ng::install` upon LWRP
39 | usage. It's now required to manually run `iptables-ng::install` before using
40 | the LWRPs. This can be achieved by adding the following before using the
41 | LWRPs for the first time (also make sure it's only included once):
42 | ```ruby
43 | include_recipe 'iptables-ng::install'
44 | ```
45 | - Removed the feature to automatically create new custom chains when using the
46 | `iptables_ng_rule` provider. Custom chains are now required to be added
47 | manually before using them:
48 | ```ruby
49 | iptables_ng_chain 'CUSTOM'
50 | iptables_ng_rule 'rule-using-custom-chain'
51 | ```
52 |
53 | This release also fixes a bug previously introduced by trying to workaround the
54 | cloning issues, where a chain policy wasn't properly updated. See [this
55 | issue](https://github.com/chr4-cookbooks/iptables-ng/issues/63) for details.
56 |
57 | 2.3.1
58 | -----
59 |
60 | - Add compatibility fix for older chef-clients
61 |
62 | 2.3.0
63 | -----
64 |
65 | - Add workarounds for duplicate resource warnings
66 |
67 | 2.2.11
68 | ------
69 |
70 | - Add compatibility setting for `source_url` attribute in `metadata.rb`
71 |
72 | 2.2.10
73 | ------
74 |
75 | - Revert `use_inline_resources`, was causing trouble
76 |
77 | 2.2.9 (broken, do not use!)
78 | -----
79 |
80 | - Fix code linting complaints (rubocop, foodcritc)
81 | - Add `use_inline_resources` to providers
82 |
83 | 2.2.8
84 | -----
85 |
86 | - Add `node['iptables-ng']['auto_prune_attribute_rules']` attribute to remove unused/ old rules created by attributes automatically
87 |
88 | 2.2.7
89 | -----
90 |
91 | - Add support for Debian Jessie
92 |
93 | 2.2.6
94 | -----
95 |
96 | - Add possibility to disable the reload or restore of iptables at the end of a chef run
97 |
98 | 2.2.5
99 | -----
100 |
101 | - Only install `iptables` package on Amazon Linux
102 |
103 | 2.2.4
104 | -----
105 |
106 | - Check whether name attribute in rule provider is valid
107 | - Fix an issue with resource notification in rule provider
108 | - Fix an issue with nat table on ipv6 not properly skipped on systems without ip6tables nat support
109 | - Add `node['iptables-ng']['ip6tables_nat_support']` attribute, default to true on recent Ubuntu
110 | versions
111 |
112 | 2.2.3
113 | -----
114 |
115 | - Add posibility to add an "action" when configuring iptables rules via attributes. See README for
116 | details
117 |
118 | 2.2.2
119 | -----
120 |
121 | - Fix an issue with init-script name on Ubuntu >= 14.10 (was renamed to netfilter-persistent)
122 |
123 | 2.2.1
124 | -----
125 |
126 | - Add support for RHEL 7 compatible distributions
127 |
128 |
129 | 2.2.0
130 | -----
131 |
132 | - Add support for `node['iptables-ng']['enabled_tables']`
133 |
134 |
135 | 2.1.1
136 | -----
137 |
138 | - Fix an issue with `node['iptables-ng']['enabled_ip_versions']`, Thanks [Bob Ziuchkovski](https://github.com/ziuchkovski)
139 | - Add Travis with rubocup and foodcritic checks
140 |
141 | 2.1.0
142 | -----
143 |
144 | - Add rubocup
145 | - Add attribute `node['iptables-ng']['enabled_ip_versions']`
146 |
147 |
148 | 2.0.0
149 | -----
150 |
151 | - Support custom chains
152 | - Rename/Migrate iptables\_ng\_policy provider to iptables\_ng\_chain
153 |
154 | 1.1.1
155 | -----
156 |
157 | - Fixes duplicate resource name warnings [CHEF-3694], Thanks [James FitzGibbon](http://github.com/jf647)
158 |
159 | 1.1.0
160 | -----
161 |
162 | - Support for ip\_version parameter in attributes. See README for details.
163 |
164 | If you use attributes to configure iptables\_ng, you need to migrate
165 |
166 | ```node['iptables-ng']['rules']['filter']['INPUT']['rej'] = 'myrule'```
167 |
168 | to
169 |
170 | ```node['iptables-ng']['rules']['filter']['INPUT']['rej']['rule'] = 'myrule'```
171 |
172 |
173 | 1.0.0
174 | -----
175 | - [Chris Aumann] - Initial release of iptables-ng
176 |
--------------------------------------------------------------------------------
/kitchen.dokken.yml:
--------------------------------------------------------------------------------
1 | driver:
2 | name: dokken
3 | privileged: true # because Docker and SystemD/Upstart
4 | chef_version: current
5 |
6 | transport:
7 | name: dokken
8 |
9 | provisioner:
10 | name: dokken
11 | client_rb:
12 | chef_license: "accept-silent"
13 | deprecations_as_errors: false
14 |
15 | # NOTE: Commented out (older) versions do not work on Github Actions with this cookbook
16 | platforms:
17 | # - name: centos-7
18 | # driver:
19 | # image: dokken/centos-7
20 | # pid_one_command: /usr/lib/systemd/systemd
21 | - name: centos-8
22 | driver:
23 | image: dokken/centos-8
24 | pid_one_command: /usr/lib/systemd/systemd
25 |
26 | - name: debian-10
27 | driver:
28 | image: dokken/debian-10
29 | pid_one_command: /bin/systemd
30 | intermediate_instructions:
31 | - RUN /usr/bin/apt-get update
32 | - name: debian-11
33 | driver:
34 | image: dokken/debian-11
35 | pid_one_command: /bin/systemd
36 | intermediate_instructions:
37 | - RUN /usr/bin/apt-get update
38 |
39 | # - name: ubuntu-16.04
40 | # driver:
41 | # image: dokken/ubuntu-16.04
42 | # pid_one_command: /bin/systemd
43 | # intermediate_instructions:
44 | # - RUN /usr/bin/apt-get update
45 | # - name: ubuntu-18.04
46 | # driver:
47 | # image: dokken/ubuntu-18.04
48 | # pid_one_command: /bin/systemd
49 | # intermediate_instructions:
50 | # - RUN /usr/bin/apt-get update
51 | # - name: ubuntu-20.04
52 | # driver:
53 | # image: dokken/ubuntu-20.04
54 | # pid_one_command: /bin/systemd
55 | # intermediate_instructions:
56 | # - RUN /usr/bin/apt-get update
57 | - name: ubuntu-22.04
58 | driver:
59 | image: dokken/ubuntu-22.04
60 | pid_one_command: /bin/systemd
61 | intermediate_instructions:
62 | - RUN /usr/bin/apt-get update
63 |
64 | suites:
65 | - name: lwrp_chain_create_default
66 | run_list:
67 | - recipe[iptables_ng_test::lwrp_chain_create_default]
68 | - name: lwrp_chain_create_custom
69 | run_list:
70 | - recipe[iptables_ng_test::lwrp_chain_create_custom]
71 | - name: lwrp_chain_create_if_missing
72 | run_list:
73 | - recipe[iptables_ng_test::lwrp_chain_create_if_missing]
74 | - name: lwrp_chain_create_empty
75 | run_list:
76 | - recipe[iptables_ng_test::lwrp_chain_create_empty]
77 |
78 | - name: lwrp_rule_create_default
79 | run_list:
80 | - recipe[iptables_ng_test::lwrp_rule_create_default]
81 | - name: lwrp_rule_create_custom
82 | run_list:
83 | - recipe[iptables_ng_test::lwrp_rule_create_custom]
84 | - name: lwrp_rule_create_custom_chain
85 | run_list:
86 | - recipe[iptables_ng_test::lwrp_rule_create_custom_chain]
87 | - name: lwrp_rule_create_if_missing
88 | run_list:
89 | - recipe[iptables_ng_test::lwrp_rule_create_if_missing]
90 | - name: lwrp_rule_delete
91 | run_list:
92 | - recipe[iptables_ng_test::lwrp_rule_delete]
93 | - name: lwrp_rule_check_order
94 | run_list:
95 | - recipe[iptables_ng_test::lwrp_rule_check_order]
96 |
97 | - name: default
98 | run_list:
99 | - recipe[iptables_ng_test::recipe_default]
100 | attributes:
101 | iptables-ng:
102 | rules:
103 | filter:
104 | INPUT:
105 | ssh:
106 | rule: '--protocol tcp --dport 22 --match state --state NEW --jump ACCEPT'
107 | ipv4_only:
108 | rule: '--protocol tcp --source 1.2.3.4 --dport 123 --jump ACCEPT'
109 | ip_version: 4
110 | OUTPUT:
111 | testrule:
112 | rule: '--protocol icmp --jump ACCEPT'
113 | FORWARD:
114 | default: 'DROP [0:0]'
115 | nat:
116 | POSTROUTING:
117 | nat_test:
118 | rule: '--protocol tcp -j ACCEPT'
119 | mangle:
120 | FORWARD:
121 | default: 'DROP [0:0]'
122 |
123 | - name: install
124 | run_list:
125 | - recipe[iptables_ng_test::recipe_install]
126 |
127 | - name: attribute_enabled_tables
128 | run_list:
129 | - recipe[iptables_ng_test::attribute_enabled_tables]
130 | attributes:
131 | iptables-ng:
132 | enabled_tables: [ 'filter' ]
133 | rules:
134 | filter:
135 | INPUT:
136 | ssh:
137 | rule: '--protocol tcp --dport 22 --match state --state NEW --jump ACCEPT'
138 | ipv4_only:
139 | rule: '--protocol tcp --source 1.2.3.4 --dport 123 --jump ACCEPT'
140 | ip_version: 4
141 | nat:
142 | POSTROUTING:
143 | nat_test:
144 | rule: '--protocol tcp -j ACCEPT'
145 | mangle:
146 | FORWARD:
147 | default: 'DROP [0:0]'
148 |
--------------------------------------------------------------------------------
/test/integration/default/default_test.rb:
--------------------------------------------------------------------------------
1 | # Should set default filter FORWARD policy to DROP
2 | describe file('/etc/iptables.d/filter/FORWARD/default') do
3 | it { should exist }
4 | its('content') { should match('DROP \[0\:0\]') }
5 | end
6 |
7 | # Should apply default filter FORWARD policy
8 | describe command('iptables -L -n') do
9 | its('stdout') { should match('Chain FORWARD \(policy DROP\)') }
10 | its('exit_status') { should eq 0 }
11 | end
12 |
13 | describe command('ip6tables -L -n') do
14 | its('stdout') { should match('Chain FORWARD \(policy DROP\)') }
15 | its('exit_status') { should eq 0 }
16 | end
17 |
18 | # Should create iptables OUTPUT test_rule
19 | describe file('/etc/iptables.d/filter/OUTPUT/testrule-filter-OUTPUT-attribute-rule.rule_v4') do
20 | it { should exist }
21 | its('content') { should match('--protocol icmp --jump ACCEPT') }
22 | end
23 |
24 | # Should create ip6tables OUTPUT test_rule
25 | describe file('/etc/iptables.d/filter/OUTPUT/testrule-filter-OUTPUT-attribute-rule.rule_v6') do
26 | it { should exist }
27 | its('content') { should match('--protocol icmp --jump ACCEPT') }
28 | end
29 |
30 | # Should apply iptables OUTPUT test_rule
31 | describe command('iptables -L -n') do
32 | its('stdout') { should match(/ACCEPT\s+icmp/) }
33 | its('exit_status') { should eq 0 }
34 | end
35 |
36 | describe command('ip6tables -L -n') do
37 | its('stdout') { should match(/ACCEPT\s+(icmp|1)/) }
38 | its('exit_status') { should eq 0 }
39 | end
40 |
41 | # Should set default mangle FORARD policy to DROP
42 | describe file('/etc/iptables.d/mangle/FORWARD/default') do
43 | it { should exist }
44 | its('content') { should match('DROP \[0\:0\]') }
45 | end
46 |
47 | # Should apply default mangle FORWARD policy
48 | describe command('iptables -t mangle -L -n') do
49 | its('stdout') { should match('Chain FORWARD \(policy DROP\)') }
50 | its('exit_status') { should eq 0 }
51 | end
52 |
53 | describe command('ip6tables -t mangle -L -n') do
54 | its('stdout') { should match('Chain FORWARD \(policy DROP\)') }
55 | its('exit_status') { should eq 0 }
56 | end
57 |
58 | # Should create nat POSTROUTING iptables rule
59 | describe file('/etc/iptables.d/nat/POSTROUTING/nat_test-nat-POSTROUTING-attribute-rule.rule_v4') do
60 | it { should exist }
61 | its('content') { should match('--protocol tcp -j ACCEPT') }
62 | end
63 |
64 | # Should only set custom ip6tables rule for nat chain if ip6tables_nat_support attribute is enabled
65 | describe file('/etc/iptables.d/nat/POSTROUTING/nat_test-nat-POSTROUTING-attribute-rule.rule_v6') do
66 | it { should exist }
67 | its('content') { should match('--protocol tcp -j ACCEPT') }
68 | end
69 |
70 | # Should apply nat POSTROUTING iptables rule
71 | describe command('iptables -t nat -L -n') do
72 | its('stdout') { should match(/ACCEPT\s+tcp/) }
73 | its('exit_status') { should eq 0 }
74 | end
75 |
76 | # Should create SSH iptables rule
77 | describe file('/etc/iptables.d/filter/INPUT/ssh-filter-INPUT-attribute-rule.rule_v4') do
78 | it { should exist }
79 | its('content') { should match('--protocol tcp --dport 22 --match state --state NEW --jump ACCEPT') }
80 | end
81 |
82 | # Should create SSH ip6tables rule
83 | describe file('/etc/iptables.d/filter/INPUT/ssh-filter-INPUT-attribute-rule.rule_v6') do
84 | it { should exist }
85 | its('content') { should match('--protocol tcp --dport 22 --match state --state NEW --jump ACCEPT') }
86 | end
87 |
88 | # Should apply SSH iptables rule
89 | describe command('iptables -L -n') do
90 | its('stdout') { should match('tcp dpt:22 state NEW') }
91 | its('exit_status') { should eq 0 }
92 | end
93 |
94 | describe command('ip6tables -L -n') do
95 | its('stdout') { should match('tcp dpt:22 state NEW') }
96 | its('exit_status') { should eq 0 }
97 | end
98 |
99 | # Should create ipv4_only iptables rule
100 | describe file('/etc/iptables.d/filter/INPUT/ipv4_only-filter-INPUT-attribute-rule.rule_v4') do
101 | it { should exist }
102 | its('content') { should match('--protocol tcp --source 1.2.3.4 --dport 123 --jump ACCEPT') }
103 | end
104 |
105 | # Should not create ipv4_only ip6tables rule
106 | describe file('/etc/iptables.d/filter/INPUT/ipv4_only-filter-INPUT-attribute-rule.rule_v6') do
107 | it { should_not exist }
108 | end
109 |
110 | # Should apply ipv4_only iptables rule
111 | describe command('iptables -L -n') do
112 | its('stdout') { should match('tcp dpt:123') }
113 | its('exit_status') { should eq 0 }
114 | end
115 |
116 | service_ipv4 = case os.family
117 | when 'debian'
118 | 'netfilter-persistent'
119 | else
120 | 'iptables'
121 | end
122 |
123 | service_ipv6 = case os.family
124 | when 'debian'
125 | 'netfilter-persistent'
126 | else
127 | 'ip6tables'
128 | end
129 |
130 | # Should enable iptables serices
131 | describe service(service_ipv4) do
132 | it { should be_enabled }
133 | end
134 |
135 | describe service(service_ipv6) do
136 | it { should be_enabled }
137 | end
138 |
--------------------------------------------------------------------------------
/test/integration/install/install_test.rb:
--------------------------------------------------------------------------------
1 | # Should set all default policies to ACCEPT'
2 |
3 | # filter
4 | describe file('/etc/iptables.d/filter/INPUT/default') do
5 | it { should exist }
6 | its('content') { should match('ACCEPT \[0\:0\]') }
7 | end
8 | describe file('/etc/iptables.d/filter/OUTPUT/default') do
9 | it { should exist }
10 | its('content') { should match('ACCEPT \[0\:0\]') }
11 | end
12 | describe file('/etc/iptables.d/filter/FORWARD/default') do
13 | it { should exist }
14 | its('content') { should match('ACCEPT \[0\:0\]') }
15 | end
16 |
17 | # nat
18 | describe file('/etc/iptables.d/nat/OUTPUT/default') do
19 | it { should exist }
20 | its('content') { should match('ACCEPT \[0\:0\]') }
21 | end
22 | describe file('/etc/iptables.d/nat/PREROUTING/default') do
23 | it { should exist }
24 | its('content') { should match('ACCEPT \[0\:0\]') }
25 | end
26 | describe file('/etc/iptables.d/nat/POSTROUTING/default') do
27 | it { should exist }
28 | its('content') { should match('ACCEPT \[0\:0\]') }
29 | end
30 |
31 | # mangle
32 | describe file('/etc/iptables.d/mangle/INPUT/default') do
33 | it { should exist }
34 | its('content') { should match('ACCEPT \[0\:0\]') }
35 | end
36 | describe file('/etc/iptables.d/mangle/OUTPUT/default') do
37 | it { should exist }
38 | its('content') { should match('ACCEPT \[0\:0\]') }
39 | end
40 | describe file('/etc/iptables.d/mangle/FORWARD/default') do
41 | it { should exist }
42 | its('content') { should match('ACCEPT \[0\:0\]') }
43 | end
44 | describe file('/etc/iptables.d/mangle/PREROUTING/default') do
45 | it { should exist }
46 | its('content') { should match('ACCEPT \[0\:0\]') }
47 | end
48 | describe file('/etc/iptables.d/mangle/POSTROUTING/default') do
49 | it { should exist }
50 | its('content') { should match('ACCEPT \[0\:0\]') }
51 | end
52 |
53 | # raw
54 | describe file('/etc/iptables.d/raw/OUTPUT/default') do
55 | it { should exist }
56 | its('content') { should match('ACCEPT \[0\:0\]') }
57 | end
58 | describe file('/etc/iptables.d/raw/PREROUTING/default') do
59 | it { should exist }
60 | its('content') { should match('ACCEPT \[0\:0\]') }
61 | end
62 |
63 | # Should not apply other iptables rules
64 | describe command('iptables -L -n |wc -l') do
65 | its('stdout.strip') { should eq('8') }
66 | its('exit_status') { should eq 0 }
67 | end
68 |
69 | describe command('iptables -L -n -t nat |wc -l') do
70 | its('stdout.strip') { should eq('11') }
71 | its('exit_status') { should eq 0 }
72 | end
73 |
74 | describe command('iptables -L -n -t mangle |wc -l') do
75 | its('stdout.strip') { should eq('14') }
76 | its('exit_status') { should eq 0 }
77 | end
78 |
79 | describe command('iptables -L -n -t raw |wc -l') do
80 | its('stdout.strip') { should eq('5') }
81 | its('exit_status') { should eq 0 }
82 | end
83 |
84 | # Should not apply other ip6tables rules
85 | describe command('ip6tables -L -n |wc -l') do
86 | its('stdout.strip') { should eq('8') }
87 | its('exit_status') { should eq 0 }
88 | end
89 |
90 | describe command('ip6tables -L -n -t mangle |wc -l') do
91 | its('stdout.strip') { should eq('14') }
92 | its('exit_status') { should eq 0 }
93 | end
94 |
95 | describe command('ip6tables -L -n -t raw |wc -l') do
96 | its('stdout.strip') { should eq('5') }
97 | its('exit_status') { should eq 0 }
98 | end
99 |
100 | # Should apply default policies in filter table
101 | describe command('iptables -L -n') do
102 | its('stdout') { should match('Chain INPUT \(policy ACCEPT\)') }
103 | its('stdout') { should match('Chain OUTPUT \(policy ACCEPT\)') }
104 | its('stdout') { should match('Chain FORWARD \(policy ACCEPT\)') }
105 | its('exit_status') { should eq 0 }
106 | end
107 |
108 | describe command('ip6tables -L -n') do
109 | its('stdout') { should match('Chain INPUT \(policy ACCEPT\)') }
110 | its('stdout') { should match('Chain OUTPUT \(policy ACCEPT\)') }
111 | its('stdout') { should match('Chain FORWARD \(policy ACCEPT\)') }
112 | its('exit_status') { should eq 0 }
113 | end
114 |
115 | # Should apply default policies in nat table
116 | describe command('iptables -L -n -t nat') do
117 | its('stdout') { should match('Chain INPUT \(policy ACCEPT\)') }
118 | its('stdout') { should match('Chain OUTPUT \(policy ACCEPT\)') }
119 | its('stdout') { should match('Chain PREROUTING \(policy ACCEPT\)') }
120 | its('stdout') { should match('Chain POSTROUTING \(policy ACCEPT\)') }
121 | its('exit_status') { should eq 0 }
122 | end
123 |
124 | # Should apply default policies in mangle table
125 | describe command('iptables -L -n -t mangle') do
126 | its('stdout') { should match('Chain INPUT \(policy ACCEPT\)') }
127 | its('stdout') { should match('Chain OUTPUT \(policy ACCEPT\)') }
128 | its('stdout') { should match('Chain FORWARD \(policy ACCEPT\)') }
129 | its('stdout') { should match('Chain PREROUTING \(policy ACCEPT\)') }
130 | its('stdout') { should match('Chain POSTROUTING \(policy ACCEPT\)') }
131 | its('exit_status') { should eq 0 }
132 | end
133 |
134 | describe command('ip6tables -L -n -t mangle') do
135 | its('stdout') { should match('Chain INPUT \(policy ACCEPT\)') }
136 | its('stdout') { should match('Chain OUTPUT \(policy ACCEPT\)') }
137 | its('stdout') { should match('Chain FORWARD \(policy ACCEPT\)') }
138 | its('stdout') { should match('Chain PREROUTING \(policy ACCEPT\)') }
139 | its('stdout') { should match('Chain POSTROUTING \(policy ACCEPT\)') }
140 | its('exit_status') { should eq 0 }
141 | end
142 |
143 | # Should apply default policies in raw table
144 | describe command('iptables -L -n -t raw') do
145 | its('stdout') { should match('Chain OUTPUT \(policy ACCEPT\)') }
146 | its('stdout') { should match('Chain PREROUTING \(policy ACCEPT\)') }
147 | its('exit_status') { should eq 0 }
148 | end
149 |
150 | describe command('ip6tables -L -n -t raw') do
151 | its('stdout') { should match('Chain OUTPUT \(policy ACCEPT\)') }
152 | its('stdout') { should match('Chain PREROUTING \(policy ACCEPT\)') }
153 | its('exit_status') { should eq 0 }
154 | end
155 |
156 | service_ipv4 = case os.family
157 | when 'debian'
158 | 'netfilter-persistent'
159 | else
160 | 'iptables'
161 | end
162 |
163 | service_ipv6 = case os.family
164 | when 'debian'
165 | 'netfilter-persistent'
166 | else
167 | 'ip6tables'
168 | end
169 |
170 | # Should enable iptables serices
171 | describe service(service_ipv4) do
172 | it { should be_enabled }
173 | end
174 |
175 | describe service(service_ipv6) do
176 | it { should be_enabled }
177 | end
178 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # iptables-ng Cookbook
2 |
3 | 
4 |
5 | [](https://supermarket.chef.io/cookbooks/iptables-ng)
6 |
7 |
8 | This cookbook maintains and installs iptables and ip6tables rules, trying to keep as close to the way the used distribution maintains their rules.
9 |
10 | Contrary to other iptables cookbooks, this cookbook installs iptables and maintains rules using the distributions default configuration files and services (for Debian and Ubuntu, iptables-persistent is used). If the distribution has no service for iptables, it falls back to iptables-restore.
11 |
12 | It provides LWRPs as well as recipes which can handle iptables rules set in the nodes attributes.
13 |
14 | It uses the directory `/etc/iptables.d` to store and maintain its rules. I'm trying to be as compatible as much as possible to all distributions out there.
15 |
16 |
17 | This cookbook is supposed to be able to:
18 |
19 | - Configure iptables rules in a consistent and nice way for all distributions
20 | - Be configured by using LWRPs only
21 | - Be configured by using node attributes only
22 | - Respect the way the currently used distribution stores their rules
23 | - Provide a good-to-read and good-to-maintain way of deploying complex iptables rulesets
24 | - Provide a way of specifying the order of the iptables rules, in case needed
25 | - Only run iptables-restore once during a chef run, and only if something was actually changed
26 | - Support both, ipv6 as well as ipv4
27 | - Be able to assemble iptables rules from different recipes (and even cookbooks), so you can set your iptables rule where you actually configure the service
28 |
29 | I also wrote a [blog post](https://chr4.org/blog/2013/09/13/iptables-ng-cookbook-for-chef) providing further insights.
30 |
31 |
32 | ## Requirements
33 |
34 | The following distribution are best supported, but as this recipe falls back to a generic iptables restore script in case the system is unknown, it should work with every linux distribution supporting iptables.
35 |
36 | * Ubuntu
37 | * Debian
38 | * RHEL
39 | * Gentoo
40 | * Archlinux
41 |
42 | No external dependencies. Just add this line to your `metadata.rb` and you're good to go!
43 |
44 | ```ruby
45 | depends 'iptables-ng'
46 | ```
47 |
48 |
49 | ## Attributes
50 |
51 | ### General configuration (services, paths)
52 |
53 | While iptables-ng tries to automatically determine the correct settings and defaults for your distribution, it might be necessary to adapt them in certain cases. You can configure the behaviour of iptables-ng using the following attributes:
54 |
55 | ```ruby
56 | # The ip versions to manage iptables for
57 | node['iptables-ng']['enabled_ip_versions'] = [4, 6]
58 |
59 | # Which tables to manage:
60 | # When using a containered setup (OpenVZ, Docker, LXC) it might be
61 | # necessary to remove the "nat" and "raw" tables.
62 | node['iptables-ng']['enabled_tables'] = %w(nat filter mangle raw)
63 |
64 | # An array of packages to install.
65 | # This should install iptables and ip6tables,
66 | # as well as a system service that takes care of reloading the rules
67 | # On Debian and Ubuntu, iptables-persistent is used by default.
68 | node['iptables-ng']['packages'] = %w(iptables)
69 |
70 | # The name of the service that will be used to restart iptables
71 | # By default, the system service of your distribution is used, so don't worry about it unless you
72 | # have special requirements. If iptables-ng can't figure out the default service to use or these
73 | # attributes are set to nil, iptables-ng will fall back to "iptables-restore"
74 | node['iptables-ng']['service_ipv4'] = 'iptables-persistent'
75 | node['iptables-ng']['service_ipv6'] = 'iptables-persistent'
76 |
77 | # The location were the iptables-restore script will be written to
78 | node['iptables-ng']['script_ipv4'] = '/etc/iptables/rules.v4'
79 | node['iptables-ng']['script_ipv6'] = '/etc/iptables/rules.v6'
80 | ```
81 |
82 | ### Rule configuration
83 |
84 | The use of the LWRPs is recommended, but iptables-ng can be configured using attributes only.
85 |
86 | You can set the default policies of a chain like this
87 |
88 | ```ruby
89 | node['iptables-ng']['rules']['filter']['INPUT']['default'] = 'DROP [0:0]'
90 | ```
91 |
92 | And also add rules for a chain (this example allows SSH)
93 |
94 | ```ruby
95 | node['iptables-ng']['rules']['filter']['INPUT']['ssh']['rule'] = '--protocol tcp --dport 22 --match state --state NEW --jump ACCEPT'
96 | ```
97 |
98 | You can prioritize your rules, too. This example will make sure that the 'ssh' rule is created before the 'http' rule
99 |
100 | ```ruby
101 | node['iptables-ng']['rules']['filter']['INPUT']['10-ssh']['rule'] = 'this rule is first'
102 | node['iptables-ng']['rules']['filter']['INPUT']['90-http']['rule'] = 'this rule is applied later'
103 | ```
104 |
105 | Also, it's possible to only apply a rule for a certain ip version.
106 |
107 | ```ruby
108 | node['iptables-ng']['rules']['filter']['INPUT']['10-ssh']['rule'] = '--protocol tcp --source 1.2.3.4 --dport 22 --match state --state NEW --jump ACCEPT'
109 | node['iptables-ng']['rules']['filter']['INPUT']['10-ssh']['ip_version'] = 4
110 | ```
111 |
112 | ### Auto-pruning
113 |
114 | In Chef, it is generally accepted that removing node attributes does not result in their corresponding resources being proactively scrubbed from the system. However, this could be seen as irritating or even a security risk when dealing with firewall attribute rules in this cookbook. To automatically prune rules for attributes that have been removed, set the following attribute to true. This will not affect rules defined with the LWRP.
115 |
116 | ```ruby
117 | node['iptables-ng']['auto_prune_attribute_rules'] = true
118 | ```
119 |
120 | # Recipes
121 |
122 | ## default
123 |
124 | The default recipe calls the install recipe, and then configures all rules and policies given in the nodes attribute.
125 |
126 | Example:
127 |
128 | To allow only SSH for incoming connections, add this to your node configuration
129 |
130 | ```json
131 | {
132 | "name": "example.com",
133 | "chef_environment": "_default",
134 | "normal": {
135 | "iptables-ng": {
136 | "rules": {
137 | "filter": {
138 | "INPUT": {
139 | "default": "DROP [0:0]",
140 | "ssh": {
141 | "rule": "--protocol tcp --dport 22 --match state --state NEW --jump ACCEPT"
142 | }
143 | }
144 | }
145 | }
146 | }
147 | },
148 | "run_list": [
149 | "recipe[iptables-ng]"
150 | ]
151 | }
152 | ```
153 |
154 | In case you need a rule for one specific ip version, you can set the "ip_version" attribute.
155 |
156 | ```json
157 | "ssh": {
158 | "rule": "--protocol tcp --source 1.2.3.4 --dport 22 --match state --state NEW --jump ACCEPT",
159 | "ip_version": 4
160 | }
161 | ```
162 |
163 | You can also delete old rules by specifying a custom action.
164 |
165 | ```json
166 | "ssh": {
167 | "action": "delete"
168 | }
169 | ```
170 |
171 |
172 | ## install
173 |
174 | The installs recipe installs iptables packages, makes sure that `/etc/iptables.d` is created and sets all default policies to "ACCEPT", unless they are already configured.
175 |
176 | On Debian and Ubuntu systems, it also removes the "ufw" package, as it might interfere with this cookbook.
177 |
178 | *Note: This recipe needs to be run before the LWRPs are used!*
179 |
180 | ```ruby
181 | include_recipe 'iptables-ng::install'
182 | ```
183 |
184 |
185 | # Providers
186 |
187 | It's recommended to configure iptables-ng using LWRPs in your (wrapper) cookbook.
188 |
189 | All providers take care that iptables is installed (they include the install recipe before running), so you can just use them without worrying whether everything is installed correctly.
190 |
191 |
192 | ## iptables\_ng\_chain
193 |
194 | This provider creates chains and adds their default policies.
195 |
196 | Example: Set the default policy of the filter INPUT chain to ACCEPT:
197 |
198 | ```ruby
199 | iptables_ng_chain 'INPUT' do
200 | policy 'ACCEPT [0:0]'
201 | end
202 | ```
203 |
204 | Example: Create a custom chain:
205 |
206 | ```ruby
207 | iptables_ng_chain 'MYCHAIN'
208 | ```
209 |
210 | The following additional attributes are supported:
211 |
212 | ```ruby
213 | iptables_ng_chain 'name' do
214 | chain 'INPUT' # The chain to set the policy for (name_attribute)
215 | table 'filter' # The table to use (defaults to 'filter')
216 | policy 'DROP [0:0]' # The policy to use (defaults to 'ACCEPT [0:0]' for
217 | # build-in chains, to '- [0:0]' for custom ones
218 |
219 | action :create # Supported actions: :create, :create_if_missing, :delete
220 | # Default action: :create
221 | end
222 | ```
223 |
224 | ## iptables\_ng\_rule
225 |
226 | This provider adds iptables rules
227 |
228 | Example: Allow SSH on the INPUT filter chain
229 |
230 | ```ruby
231 | iptables_ng_rule 'ssh' do
232 | rule '--protocol tcp --dport 22 --match state --state NEW --jump ACCEPT'
233 | end
234 | ```
235 |
236 | The following additional attributes are supported:
237 |
238 | ```ruby
239 | iptables_ng_rule 'custom' do
240 | name 'my-rule' # Name of the rule. Use "xx-" to prioritize rules.
241 | chain 'INPUT' # Chain to use. Defaults to 'INPUT' (custom chains need to be created using iptables_ng_chain first!)
242 | table 'filter' # Table to use. Defaults to 'filter'
243 | ip_version 4 # Integer or Array of IP versions to create the rules for.
244 | # Defaults to node['iptables-ng']['enabled_ip_versions']
245 | rule '-j ACCEPT' # String or Array containing the rule(s). (Required)
246 |
247 | action :create # Supported actions: :create, :create_if_missing, :delete
248 | # Default action: :create
249 | end
250 | ```
251 |
252 | Example: Allow HTTP and HTTPS for a specific IP range only
253 |
254 | ```ruby
255 | iptables_ng_rule 'ssh' do
256 | rule ['--source 192.168.1.0/24 --protocol tcp --dport 80 --match state --state NEW --jump ACCEPT',
257 | '--source 192.168.1.0/24 --protocol tcp --dport 443 --match state --state NEW --jump ACCEPT']
258 |
259 | # As the source specified above is ipv4, this rule cannot be applied to ip6tables.
260 | # Therefore, setting ip_version to 4
261 | ip_version 4
262 | end
263 | ```
264 |
265 | Example: Use the same rule for an array of IPs
266 |
267 | ```ruby
268 | ips = %w(10.10.10.1 123.123.123.123 192.168.1.0/24)
269 |
270 | iptables_ng_rule 'multiple_source_addresses' do
271 | rule ips.map { |ip| "--source #{ip} --jump ACCEPT" }
272 |
273 | # As the source specified above is ipv4, this rule cannot be applied to ip6tables.
274 | # Therefore, setting ip_version to 4
275 | ip_version 4
276 | end
277 | ```
278 |
279 |
280 | # Known issues
281 |
282 | There are some issues with systemd support on Fedora systems. Also it might be required to install iptables-service on newer Fedora machines.
283 | Due to this issues, the tests for Fedora were removed until they are resolved.
284 | Furthermore, due to the lack of Opscode kitchen boxes, there are no tests for Archlinux.
285 |
286 |
287 | # Contributing
288 |
289 | You fixed a bug, or added a new feature? Yippie!
290 |
291 | 1. Fork the repository on Github
292 | 2. Create a named feature branch (like `add_component_x`)
293 | 3. Write you change
294 | 4. Write tests for your change (if applicable)
295 | 5. Run the tests, ensuring they all pass
296 | 6. Submit a Pull Request using Github
297 |
298 | Contributions of any sort are very welcome!
299 |
300 | # License and Authors
301 |
302 | Authors: Chris Aumann
303 |
304 | Contributors: Dan Fruehauf, Nathan Williams, Christian Graf, James Le Cuirot, Sten Spans, Cédric Félizard, Hans Rakers
305 |
306 |
307 | ## Other licenses than GPLv3
308 |
309 | In case you can't use the provided license for some reason, feel free to contact me.
310 |
311 |
312 | Copyright (C) 2013-2018 Chris Aumann
313 |
314 | This program is free software: you can redistribute it and/or modify
315 | it under the terms of the GNU General Public License as published by
316 | the Free Software Foundation, either version 3 of the License, or
317 | (at your option) any later version.
318 |
319 | This program is distributed in the hope that it will be useful,
320 | but WITHOUT ANY WARRANTY; without even the implied warranty of
321 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
322 | GNU General Public License for more details.
323 |
324 | You should have received a copy of the GNU General Public License
325 | along with this program. If not, see .
326 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 | iptables-ng, a Chef cookbook to maintain iptables rules and policies on
635 | different platforms, respecting the way the os handles these settings.
636 |
637 | Copyright (C) 2015 Chris Aumann
638 |
639 | This program is free software: you can redistribute it and/or modify
640 | it under the terms of the GNU General Public License as published by
641 | the Free Software Foundation, either version 3 of the License, or
642 | (at your option) any later version.
643 |
644 | This program is distributed in the hope that it will be useful,
645 | but WITHOUT ANY WARRANTY; without even the implied warranty of
646 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
647 | GNU General Public License for more details.
648 |
649 | You should have received a copy of the GNU General Public License
650 | along with this program. If not, see .
651 |
652 | Also add information on how to contact you by electronic and paper mail.
653 |
654 | If the program does terminal interaction, make it output a short
655 | notice like this when it starts in an interactive mode:
656 |
657 | iptables-ng Copyright (C) 2015 Chris Aumann
658 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
659 | This is free software, and you are welcome to redistribute it
660 | under certain conditions; type `show c' for details.
661 |
662 | The hypothetical commands `show w' and `show c' should show the appropriate
663 | parts of the General Public License. Of course, your program's commands
664 | might be different; for a GUI interface, you would use an "about box".
665 |
666 | You should also get your employer (if you work as a programmer) or school,
667 | if any, to sign a "copyright disclaimer" for the program, if necessary.
668 | For more information on this, and how to apply and follow the GNU GPL, see
669 | .
670 |
671 | The GNU General Public License does not permit incorporating your program
672 | into proprietary programs. If your program is a subroutine library, you
673 | may consider it more useful to permit linking proprietary applications with
674 | the library. If this is what you want to do, use the GNU Lesser General
675 | Public License instead of this License. But first, please read
676 | .
677 |
--------------------------------------------------------------------------------