Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GH-253] Add filepath selection based on OS for nftables.conf #255

Merged
merged 4 commits into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ This file is used to list changes made in each version of the firewall cookbook.

## Unreleased

- Add filepath selection based on OS for nftables.conf

## 6.0.2 - *2022-05-15*

Standardise files with files in sous-chefs/repo-management
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Tested on:
- Debian 11 with new resources for firewalld
- CentOS 6 with iptables
- CentOS 7.1 with firewalld
- Oracle 8 with nftables
- Windows Server 2012r2 with Windows Advanced Firewall

By default, Ubuntu chooses ufw. To switch to iptables, set this in an attribute file:
Expand Down
5 changes: 5 additions & 0 deletions kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ platforms:
- name: freebsd-11
- name: freebsd-12
- name: opensuse-leap-15
- name: oracle-8
- name: ubuntu-18.04
- name: ubuntu-20.04
- name: windows-2016
Expand All @@ -54,6 +55,7 @@ suites:
- centos-8
- debian-9
- debian-10
- oracle-8
- ubuntu-18.04
- ubuntu-20.04
- windows-2016
Expand All @@ -72,6 +74,7 @@ suites:
- freebsd-11
- freebsd-12
- opensuse-leap-15
- oracle-8
- windows-2016
- windows-2019
run_list:
Expand All @@ -82,6 +85,7 @@ suites:
excludes:
- debian-9
- debian-10
- oracle-8
- ubuntu-18.04
- ubuntu-20.04
- windows-2016
Expand All @@ -97,6 +101,7 @@ suites:
- name: nftables
includes:
- debian-11
- oracle-8
run_list:
- recipe[nftables-test]

Expand Down
11 changes: 11 additions & 0 deletions libraries/helpers_nftables.rb
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,17 @@ def ensure_default_rules_exist(new_resource)
input = new_resource.rules || {}
input.merge!(default_ruleset(new_resource))
end

def default_nftables_conf_path
case node['platform_family']
when 'rhel'
'/etc/sysconfig/nftables.conf'
when 'debian'
'/etc/nftables.conf'
else
raise "default_nftables_conf_path: Unsupported platform_family #{node['platform_family']}."
end
end
end
end
end
11 changes: 6 additions & 5 deletions resources/nftables.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
unified_mode true

action_class do
include FirewallCookbook::Helpers
include FirewallCookbook::Helpers::Nftables
end
include FirewallCookbook::Helpers
include FirewallCookbook::Helpers::Nftables
Stromweld marked this conversation as resolved.
Show resolved Hide resolved

provides :nftables,
os: 'linux'
Expand All @@ -29,6 +27,9 @@
property :table_ip6_nat,
[true, false],
default: false
property :nftables_conf_path, String,
description: 'nftables.conf filepath',
default: lazy { default_nftables_conf_path }

action :install do
package 'nftables' do
Expand All @@ -40,7 +41,7 @@
action :rebuild do
ensure_default_rules_exist(new_resource)

file '/etc/nftables.conf' do
file new_resource.nftables_conf_path do
content <<~NFT
#!/usr/sbin/nft -f
flush ruleset
Expand Down
8 changes: 8 additions & 0 deletions test/integration/nftables/inspec/nftables_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,11 @@
it { should be_enabled }
it { should be_running }
end

describe file('/etc/sysconfig/nftables.conf') do
it { should exist }
end if os.redhat?

describe file('/etc/nftables.conf') do
it { should exist }
end if os.debian?