Skip to content

Commit

Permalink
Move ct rules from global to INPUT and OUTPUT
Browse files Browse the repository at this point in the history
  • Loading branch information
nbarrientos committed Nov 19, 2020
1 parent 9e5b8bf commit ea96d5d
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 3 deletions.
3 changes: 0 additions & 3 deletions files/config/puppet-inet-filter.nft
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@

# something we want for all
chain global {
ct state established,related accept
ct state invalid drop

ip protocol icmp icmp type { destination-unreachable, time-exceeded, parameter-problem } accept
ip6 nexthdr ipv6-icmp icmpv6 type { destination-unreachable, packet-too-big, time-exceeded, parameter-problem, mld-listener-query, mld-listener-report, mld-listener-done, nd-router-advert, nd-neighbor-solicit, nd-neighbor-advert, ind-neighbor-solicit, ind-neighbor-advert, mld2-listener-report } accept
ip protocol icmp icmp type echo-request limit rate 4/second accept
Expand Down
20 changes: 20 additions & 0 deletions manifests/inet_filter.pp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,16 @@
content => "reject with ${$nftables::reject_with}";
}
}
if $nftables::in_out_conntrack {
nftables::rule{
'INPUT-accept_established_related':
order => '05',
content => 'ct state established,related accept';
'INPUT-drop_invalid':
order => '06',
content => 'ct state invalid drop';
}
}

# inet-filter-chain-OUTPUT
nftables::rule{
Expand All @@ -76,6 +86,16 @@
content => "reject with ${$nftables::reject_with}";
}
}
if $nftables::in_out_conntrack {
nftables::rule{
'OUTPUT-accept_established_related':
order => '05',
content => 'ct state established,related accept';
'OUTPUT-drop_invalid':
order => '06',
content => 'ct state invalid drop';
}
}

# inet-filter-chain-FORWARD
nftables::rule{
Expand Down
5 changes: 5 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,18 @@
# drop), otherwise the packet will be rejected with the REJECT_WITH
# policy indicated by the value of this parameter.
#
# @param in_out_conntrack
# Adds INPUT and OUTPUT rules to allow traffic that's part of an
# established connection and also to drop invalid packets.
#
class nftables (
Boolean $in_ssh = true,
Boolean $out_ntp = true,
Boolean $out_dns = true,
Boolean $out_http = true,
Boolean $out_https = true,
Boolean $out_all = false,
Boolean $in_out_conntrack = true,
Hash $rules = {},
String $log_prefix = '[nftables] %<chain>s %<comment>s',
Variant[Boolean[false], Pattern[
Expand Down
61 changes: 61 additions & 0 deletions spec/classes/inet_filter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,20 @@
order: '04',
)
}
it {
is_expected.to contain_concat__fragment('nftables-inet-filter-chain-INPUT-rule-accept_established_related').with(
target: 'nftables-inet-filter-chain-INPUT',
content: %r{^ ct state established,related accept$},
order: '05',
)
}
it {
is_expected.to contain_concat__fragment('nftables-inet-filter-chain-INPUT-rule-drop_invalid').with(
target: 'nftables-inet-filter-chain-INPUT',
content: %r{^ ct state invalid drop$},
order: '06',
)
}
it {
is_expected.to contain_concat__fragment('nftables-inet-filter-chain-INPUT-rule-jump_default_in').with(
target: 'nftables-inet-filter-chain-INPUT',
Expand Down Expand Up @@ -193,6 +207,20 @@
order: '04',
)
}
it {
is_expected.to contain_concat__fragment('nftables-inet-filter-chain-OUTPUT-rule-accept_established_related').with(
target: 'nftables-inet-filter-chain-OUTPUT',
content: %r{^ ct state established,related accept$},
order: '05',
)
}
it {
is_expected.to contain_concat__fragment('nftables-inet-filter-chain-OUTPUT-rule-drop_invalid').with(
target: 'nftables-inet-filter-chain-OUTPUT',
content: %r{^ ct state invalid drop$},
order: '06',
)
}
it {
is_expected.to contain_concat__fragment('nftables-inet-filter-chain-OUTPUT-rule-jump_default_out').with(
target: 'nftables-inet-filter-chain-OUTPUT',
Expand Down Expand Up @@ -320,6 +348,12 @@
order: '03',
)
}
it {
is_expected.not_to contain_concat__fragment('nftables-inet-filter-chain-FORWARD-rule-accept_established_related')
}
it {
is_expected.not_to contain_concat__fragment('nftables-inet-filter-chain-FORWARD-rule-drop_invalid')
}
it {
is_expected.to contain_concat__fragment('nftables-inet-filter-chain-FORWARD-rule-jump_default_fwd').with(
target: 'nftables-inet-filter-chain-FORWARD',
Expand Down Expand Up @@ -500,6 +534,33 @@

it { is_expected.not_to compile }
end

context 'without conntrack rules' do
let(:params) do
{
'in_out_conntrack' => false,
}
end

it {
is_expected.not_to contain_concat__fragment('nftables-inet-filter-chain-INPUT-rule-accept_established_related')
}
it {
is_expected.not_to contain_concat__fragment('nftables-inet-filter-chain-INPUT-rule-drop_invalid')
}
it {
is_expected.not_to contain_concat__fragment('nftables-inet-filter-chain-OUTPUT-rule-accept_established_related')
}
it {
is_expected.not_to contain_concat__fragment('nftables-inet-filter-chain-OUTPUT-rule-drop_invalid')
}
it {
is_expected.not_to contain_concat__fragment('nftables-inet-filter-chain-FORWARD-rule-accept_established_related')
}
it {
is_expected.not_to contain_concat__fragment('nftables-inet-filter-chain-FORWARD-rule-drop_invalid')
}
end
end
end
end

0 comments on commit ea96d5d

Please sign in to comment.