Skip to content

Commit

Permalink
Make "dropping invalid packets" configureable
Browse files Browse the repository at this point in the history
It doesn't make sense to explicitly drop those pakets when the default
policy is already `DROP`. Also some applications, like ceph, are known
to send packets that might be marked as invalid.
  • Loading branch information
bastelfreak committed Dec 20, 2023
1 parent e5a1eb7 commit 0dc9677
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 5 deletions.
18 changes: 18 additions & 0 deletions REFERENCE.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,9 @@ The following parameters are available in the `nftables` class:
* [`log_limit`](#-nftables--log_limit)
* [`reject_with`](#-nftables--reject_with)
* [`in_out_conntrack`](#-nftables--in_out_conntrack)
* [`in_out_drop_invalid`](#-nftables--in_out_drop_invalid)
* [`fwd_conntrack`](#-nftables--fwd_conntrack)
* [`fwd_drop_invalid`](#-nftables--fwd_drop_invalid)
* [`firewalld_enable`](#-nftables--firewalld_enable)
* [`noflush_tables`](#-nftables--noflush_tables)
* [`rules`](#-nftables--rules)
Expand Down Expand Up @@ -324,6 +326,14 @@ established connection and also to drop invalid packets.

Default value: `true`

##### <a name="-nftables--in_out_drop_invalid"></a>`in_out_drop_invalid`

Data type: `Boolean`

Drops invalid packets in INPUT and OUTPUT

Default value: `$in_out_conntrack`

##### <a name="-nftables--fwd_conntrack"></a>`fwd_conntrack`

Data type: `Boolean`
Expand All @@ -333,6 +343,14 @@ established connection and also to drop invalid packets.

Default value: `false`

##### <a name="-nftables--fwd_drop_invalid"></a>`fwd_drop_invalid`

Data type: `Boolean`

Drops invalid packets in FORWARD

Default value: `$fwd_conntrack`

##### <a name="-nftables--firewalld_enable"></a>`firewalld_enable`

Data type: `Variant[Boolean[false], Enum['mask']]`
Expand Down
5 changes: 4 additions & 1 deletion manifests/inet_filter/fwd_conntrack.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
'FORWARD-accept_established_related':
order => '05',
content => 'ct state established,related accept';
'FORWARD-drop_invalid':
}
if $nftables::fwd_drop_invalid {
nftables::rule { 'FORWARD-drop_invalid':
order => '06',
content => 'ct state invalid drop';
}
}
}
5 changes: 4 additions & 1 deletion manifests/inet_filter/in_out_conntrack.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
'OUTPUT-accept_established_related':
order => '05',
content => 'ct state established,related accept';
'OUTPUT-drop_invalid':
}
if $nftables::in_out_drop_invalid {
nftables::rule { 'OUTPUT-drop_invalid':
order => '06',
content => 'ct state invalid drop';
}
}
}
8 changes: 8 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,16 @@
# Adds INPUT and OUTPUT rules to allow traffic that's part of an
# established connection and also to drop invalid packets.
#
# @param in_out_drop_invalid
# Drops invalid packets in INPUT and OUTPUT
#
# @param fwd_conntrack
# Adds FORWARD rules to allow traffic that's part of an
# established connection and also to drop invalid packets.
#
# @param fwd_drop_invalid
# Drops invalid packets in FORWARD
#
# @param firewalld_enable
# Configures how the firewalld systemd service unit is enabled. It might be
# useful to set this to false if you're externaly removing firewalld from
Expand Down Expand Up @@ -117,7 +123,9 @@
Boolean $out_icmp = true,
Boolean $out_all = false,
Boolean $in_out_conntrack = true,
Boolean $in_out_drop_invalid = $in_out_conntrack,
Boolean $fwd_conntrack = false,
Boolean $fwd_drop_invalid = $fwd_conntrack,
Boolean $inet_filter = true,
Boolean $nat = true,
Hash $rules = {},
Expand Down
21 changes: 18 additions & 3 deletions spec/classes/inet_filter/in_out_conntrack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
require 'spec_helper'

describe 'nftables::inet_filter::in_out_conntrack' do
let(:pre_condition) { 'Exec{path => "/bin"}' }

on_supported_os.each do |os, _os_facts|
on_supported_os.each do |os, os_facts|
let :pre_condition do
'include nftables'
end
context "on #{os}" do
let :facts do
os_facts
end

Check failure on line 13 in spec/classes/inet_filter/in_out_conntrack_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

RSpec/EmptyLineAfterFinalLet: Add an empty line after the last `let`. (https://rspec.rubystyle.guide/#empty-line-after-let, https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyLineAfterFinalLet)
it { is_expected.to compile.with_all_deps }

Check failure on line 14 in spec/classes/inet_filter/in_out_conntrack_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

RSpec/EmptyLineAfterExample: Add an empty line after `it`. (https://rspec.rubystyle.guide/#empty-lines-around-examples, https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyLineAfterExample)
it {
expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-INPUT-rule-accept_established_related').with(
target: 'nftables-inet-filter-chain-INPUT',
Expand Down Expand Up @@ -38,6 +43,16 @@
order: '06-nftables-inet-filter-chain-OUTPUT-rule-drop_invalid-b'
)
}

Check failure on line 45 in spec/classes/inet_filter/in_out_conntrack_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

RSpec/EmptyLineAfterExample: Add an empty line after `it`. (https://rspec.rubystyle.guide/#empty-lines-around-examples, https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyLineAfterExample)
context 'with in_out_drop_invalid=false' do
let :pre_condition do
'class { "nftables": in_out_drop_invalid => false}'
end

Check failure on line 49 in spec/classes/inet_filter/in_out_conntrack_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

RSpec/EmptyLineAfterFinalLet: Add an empty line after the last `let`. (https://rspec.rubystyle.guide/#empty-line-after-let, https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/EmptyLineAfterFinalLet)
it { is_expected.not_to contain_concat__fragment('nftables-inet-filter-chain-OUTPUT-rule-drop_invalid').with(

Check failure on line 50 in spec/classes/inet_filter/in_out_conntrack_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Layout/MultilineBlockLayout: Block body expression is on the same line as the block start.
target: 'nftables-inet-filter-chain-OUTPUT',

Check failure on line 51 in spec/classes/inet_filter/in_out_conntrack_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Layout/FirstArgumentIndentation: Indent the first argument one step more than the start of the previous line.
content: %r{^ ct state invalid drop$},

Check failure on line 52 in spec/classes/inet_filter/in_out_conntrack_spec.rb

View workflow job for this annotation

GitHub Actions / Puppet / Static validations

Style/TrailingCommaInArguments: Avoid comma after the last parameter of a method call. (https://rubystyle.guide#no-trailing-params-comma)
)
}
end
end
end
end

0 comments on commit 0dc9677

Please sign in to comment.