Révision 79e9a23f
Move ICMP stuff to separate classes
files/config/puppet-inet-filter.nft | ||
---|---|---|
2 | 2 |
|
3 | 3 |
# something we want for all |
4 | 4 |
chain global { |
5 |
ip protocol icmp icmp type { destination-unreachable, time-exceeded, parameter-problem } accept |
|
6 |
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 |
|
7 |
ip protocol icmp icmp type echo-request limit rate 4/second accept |
|
8 |
ip6 nexthdr ipv6-icmp icmpv6 type echo-request limit rate 4/second accept |
|
9 | 5 |
} |
manifests/inet_filter.pp | ||
---|---|---|
136 | 136 |
if $nftables::out_https { |
137 | 137 |
include nftables::rules::out::https |
138 | 138 |
} |
139 |
if $nftables::out_icmp { |
|
140 |
include nftables::rules::out::icmp |
|
141 |
} |
|
139 | 142 |
} |
140 | 143 |
|
141 | 144 |
# allow forwarding traffic on bridges |
... | ... | |
145 | 148 |
if $nftables::in_ssh { |
146 | 149 |
include nftables::rules::ssh |
147 | 150 |
} |
151 |
if $nftables::in_icmp { |
|
152 |
include nftables::rules::icmp |
|
153 |
} |
|
148 | 154 |
} |
manifests/init.pp | ||
---|---|---|
23 | 23 |
# @param out_https |
24 | 24 |
# Allow outbound to https servers. |
25 | 25 |
# |
26 |
# @param out_icmp |
|
27 |
# Allow outbound ICMPv4/v6 traffic. |
|
28 |
# |
|
26 | 29 |
# @param in_ssh |
27 | 30 |
# Allow inbound to ssh servers. |
28 | 31 |
# |
32 |
# @param in_icmp |
|
33 |
# Allow inbound ICMPv4/v6 traffic. |
|
34 |
# |
|
29 | 35 |
# @param log_prefix |
30 | 36 |
# String that will be used as prefix when logging packets. It can contain |
31 | 37 |
# two variables using standard sprintf() string-formatting: |
... | ... | |
44 | 50 |
# |
45 | 51 |
class nftables ( |
46 | 52 |
Boolean $in_ssh = true, |
53 |
Boolean $in_icmp = true, |
|
47 | 54 |
Boolean $out_ntp = true, |
48 | 55 |
Boolean $out_dns = true, |
49 | 56 |
Boolean $out_http = true, |
50 | 57 |
Boolean $out_https = true, |
58 |
Boolean $out_icmp = true, |
|
51 | 59 |
Boolean $out_all = false, |
52 | 60 |
Boolean $in_out_conntrack = true, |
53 | 61 |
Hash $rules = {}, |
manifests/rules/icmp.pp | ||
---|---|---|
1 |
class nftables::rules::icmp ( |
|
2 |
Optional[Array[String]] $v4_types = undef, |
|
3 |
Optional[Array[String]] $v6_types = undef, |
|
4 |
String $order = '10', |
|
5 |
) { |
|
6 |
if $v4_types { |
|
7 |
$v4_types.each | String $icmp_type | { |
|
8 |
nftables::rule{ |
|
9 |
"default_in-accept_icmpv4_${regsubst(split($icmp_type, ' ')[0], '-', '_', 'G')}": |
|
10 |
content => "ip protocol icmp icmp type ${icmp_type} accept", |
|
11 |
order => $order, |
|
12 |
} |
|
13 |
} |
|
14 |
} else { |
|
15 |
nftables::rule{ |
|
16 |
'default_in-accept_icmpv4': |
|
17 |
content => 'ip protocol icmp accept', |
|
18 |
order => $order, |
|
19 |
} |
|
20 |
} |
|
21 |
|
|
22 |
if $v6_types { |
|
23 |
$v6_types.each | String $icmp_type | { |
|
24 |
nftables::rule{ |
|
25 |
"default_in-accept_icmpv6_${regsubst(split($icmp_type, ' ')[0], '-', '_', 'G')}": |
|
26 |
content => "ip6 nexthdr ipv6-icmp icmpv6 type ${icmp_type} accept", |
|
27 |
order => $order, |
|
28 |
} |
|
29 |
} |
|
30 |
} else { |
|
31 |
nftables::rule{ |
|
32 |
'default_in-accept_icmpv6': |
|
33 |
content => 'ip6 nexthdr ipv6-icmp accept', |
|
34 |
order => $order, |
|
35 |
} |
|
36 |
} |
|
37 |
} |
manifests/rules/out/icmp.pp | ||
---|---|---|
1 |
class nftables::rules::out::icmp ( |
|
2 |
Optional[Array[String]] $v4_types = undef, |
|
3 |
Optional[Array[String]] $v6_types = undef, |
|
4 |
String $order = '10', |
|
5 |
) { |
|
6 |
if $v4_types { |
|
7 |
$v4_types.each | String $icmp_type | { |
|
8 |
nftables::rule{ |
|
9 |
'default_out-accept_icmpv4': |
|
10 |
content => "ip protocol icmp icmp type ${icmp_type} accept", |
|
11 |
order => $order, |
|
12 |
} |
|
13 |
} |
|
14 |
} else { |
|
15 |
nftables::rule{ |
|
16 |
'default_out-accept_icmpv4': |
|
17 |
content => 'ip protocol icmp accept', |
|
18 |
order => $order, |
|
19 |
} |
|
20 |
} |
|
21 |
|
|
22 |
if $v6_types { |
|
23 |
$v6_types.each | String $icmp_type | { |
|
24 |
nftables::rule{ |
|
25 |
'default_out-accept_icmpv6': |
|
26 |
content => "ip6 nexthdr ipv6-icmp icmpv6 type ${icmp_type} accept", |
|
27 |
order => $order, |
|
28 |
} |
|
29 |
} |
|
30 |
} else { |
|
31 |
nftables::rule{ |
|
32 |
'default_out-accept_icmpv6': |
|
33 |
content => 'ip6 nexthdr ipv6-icmp accept', |
|
34 |
order => $order, |
|
35 |
} |
|
36 |
} |
|
37 |
} |
spec/classes/inet_filter_spec.rb | ||
---|---|---|
160 | 160 |
order: '50-nftables-inet-filter-chain-default_in-rule-ssh-b', |
161 | 161 |
) |
162 | 162 |
} |
163 |
it { |
|
164 |
is_expected.to contain_class('nftables::rules::icmp') |
|
165 |
} |
|
163 | 166 |
end |
164 | 167 |
|
165 | 168 |
context 'chain output' do |
... | ... | |
308 | 311 |
order: '50-nftables-inet-filter-chain-default_out-rule-https-b', |
309 | 312 |
) |
310 | 313 |
} |
314 |
it { |
|
315 |
is_expected.to contain_class('nftables::rules::out::icmp') |
|
316 |
} |
|
311 | 317 |
end |
312 | 318 |
|
313 | 319 |
context 'chain forward' do |
... | ... | |
553 | 559 |
is_expected.not_to contain_concat__fragment('nftables-inet-filter-chain-FORWARD-rule-drop_invalid') |
554 | 560 |
} |
555 | 561 |
end |
562 |
|
|
563 |
context 'without ICMP configuration' do |
|
564 |
let(:params) do |
|
565 |
{ |
|
566 |
'in_icmp' => false, |
|
567 |
'out_icmp' => false, |
|
568 |
} |
|
569 |
end |
|
570 |
|
|
571 |
it { |
|
572 |
is_expected.not_to contain_class('nftables::rules::icmp') |
|
573 |
} |
|
574 |
it { |
|
575 |
is_expected.not_to contain_class('nftables::rules::out::icmp') |
|
576 |
} |
|
577 |
end |
|
556 | 578 |
end |
557 | 579 |
end |
558 | 580 |
end |
spec/classes/rules/icmp_spec.rb | ||
---|---|---|
1 |
require 'spec_helper' |
|
2 |
|
|
3 |
describe 'nftables::rules::icmp' do |
|
4 |
on_supported_os.each do |os, os_facts| |
|
5 |
context "on #{os}" do |
|
6 |
let(:facts) { os_facts } |
|
7 |
|
|
8 |
context 'default options' do |
|
9 |
it { is_expected.to compile } |
|
10 |
it { |
|
11 |
is_expected.to contain_nftables__rule('default_in-accept_icmpv4').with( |
|
12 |
content: 'ip protocol icmp accept', |
|
13 |
order: '10', |
|
14 |
) |
|
15 |
} |
|
16 |
it { |
|
17 |
is_expected.to contain_nftables__rule('default_in-accept_icmpv6').with( |
|
18 |
content: 'ip6 nexthdr ipv6-icmp accept', |
|
19 |
order: '10', |
|
20 |
) |
|
21 |
} |
|
22 |
end |
|
23 |
|
|
24 |
context 'with custom ICMP types (v4 only)' do |
|
25 |
let(:params) do |
|
26 |
{ |
|
27 |
v4_types: ['echo-request limit rate 4/second', 'echo-reply'], |
|
28 |
} |
|
29 |
end |
|
30 |
|
|
31 |
it { is_expected.to compile } |
|
32 |
it { |
|
33 |
is_expected.to contain_nftables__rule('default_in-accept_icmpv4_echo_request').with( |
|
34 |
content: 'ip protocol icmp icmp type echo-request limit rate 4/second accept', |
|
35 |
order: '10', |
|
36 |
) |
|
37 |
} |
|
38 |
it { |
|
39 |
is_expected.to contain_nftables__rule('default_in-accept_icmpv4_echo_reply').with( |
|
40 |
content: 'ip protocol icmp icmp type echo-reply accept', |
|
41 |
order: '10', |
|
42 |
) |
|
43 |
} |
|
44 |
it { |
|
45 |
is_expected.to contain_nftables__rule('default_in-accept_icmpv6').with( |
|
46 |
content: 'ip6 nexthdr ipv6-icmp accept', |
|
47 |
order: '10', |
|
48 |
) |
|
49 |
} |
|
50 |
end |
|
51 |
|
|
52 |
context 'with custom ICMP types (both v4 and v6)' do |
|
53 |
let(:params) do |
|
54 |
{ |
|
55 |
v4_types: ['echo-request limit rate 4/second', 'echo-reply'], |
|
56 |
v6_types: ['echo-reply', 'nd-router-advert'], |
|
57 |
} |
|
58 |
end |
|
59 |
|
|
60 |
it { is_expected.to compile } |
|
61 |
it { |
|
62 |
is_expected.to contain_nftables__rule('default_in-accept_icmpv4_echo_request').with( |
|
63 |
content: 'ip protocol icmp icmp type echo-request limit rate 4/second accept', |
|
64 |
order: '10', |
|
65 |
) |
|
66 |
} |
|
67 |
it { |
|
68 |
is_expected.to contain_nftables__rule('default_in-accept_icmpv4_echo_reply').with( |
|
69 |
content: 'ip protocol icmp icmp type echo-reply accept', |
|
70 |
order: '10', |
|
71 |
) |
|
72 |
} |
|
73 |
it { |
|
74 |
is_expected.to contain_nftables__rule('default_in-accept_icmpv6_echo_reply').with( |
|
75 |
content: 'ip6 nexthdr ipv6-icmp icmpv6 type echo-reply accept', |
|
76 |
order: '10', |
|
77 |
) |
|
78 |
} |
|
79 |
it { |
|
80 |
is_expected.to contain_nftables__rule('default_in-accept_icmpv6_nd_router_advert').with( |
|
81 |
content: 'ip6 nexthdr ipv6-icmp icmpv6 type nd-router-advert accept', |
|
82 |
order: '10', |
|
83 |
) |
|
84 |
} |
|
85 |
end |
|
86 |
end |
|
87 |
end |
|
88 |
end |
Formats disponibles : Unified diff