root / spec / classes / dnat4_spec.rb @ 3b26826f
Historique | Voir | Annoter | Télécharger (7,53 ko)
1 |
# frozen_string_literal: true
|
---|---|
2 |
|
3 |
require 'spec_helper'
|
4 |
|
5 |
describe 'nftables' do |
6 |
let(:pre_condition) { 'Exec{path => "/bin"}' } |
7 |
|
8 |
on_supported_os.each do |os, os_facts|
|
9 |
context "on #{os}" do |
10 |
let(:facts) { os_facts }
|
11 |
|
12 |
nft_mode = case os_facts[:os]['family'] |
13 |
when 'RedHat' |
14 |
'0600'
|
15 |
else
|
16 |
'0640'
|
17 |
end
|
18 |
|
19 |
context 'with dnat' do |
20 |
let(:pre_condition) do |
21 |
'
|
22 |
# inet-filter-chain-ingoing
|
23 |
nftables::chain{ \'ingoing\':
|
24 |
inject => \'20-default_fwd\',
|
25 |
inject_iif => \'eth0\',
|
26 |
inject_oif => \'eth1\';
|
27 |
}
|
28 |
|
29 |
# inet-filter-chain-default_fwd
|
30 |
nftables::rules::dnat4{
|
31 |
\'http\':
|
32 |
order => \'10\',
|
33 |
chain => \'ingoing\',
|
34 |
daddr => \'192.0.2.2\',
|
35 |
port => \'http\';
|
36 |
\'https\':
|
37 |
order => \'10\',
|
38 |
chain => \'ingoing\',
|
39 |
daddr => \'192.0.2.2\',
|
40 |
port => \'https\';
|
41 |
\'http_alt\':
|
42 |
order => \'10\',
|
43 |
chain => \'ingoing\',
|
44 |
iif => \'eth0\',
|
45 |
daddr => \'192.0.2.2\',
|
46 |
proto => \'tcp\',
|
47 |
port => 8080,
|
48 |
dport => 8000;
|
49 |
\'wireguard\':
|
50 |
order => \'10\',
|
51 |
chain => \'ingoing\',
|
52 |
iif => \'eth0\',
|
53 |
daddr => \'192.0.2.3\',
|
54 |
proto => \'udp\',
|
55 |
port => \'51820\';
|
56 |
}
|
57 |
'
|
58 |
end
|
59 |
|
60 |
it { is_expected.to compile } |
61 |
|
62 |
it { |
63 |
expect(subject).to contain_concat('nftables-inet-filter-chain-default_fwd').with(
|
64 |
path: '/etc/nftables/puppet-preflight/inet-filter-chain-default_fwd.nft', |
65 |
owner: 'root', |
66 |
group: 'root', |
67 |
mode: nft_mode,
|
68 |
ensure_newline: true |
69 |
) |
70 |
} |
71 |
|
72 |
it { |
73 |
expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-header').with(
|
74 |
target: 'nftables-inet-filter-chain-default_fwd', |
75 |
content: %r{^chain default_fwd \{$}, |
76 |
order: '00' |
77 |
) |
78 |
} |
79 |
|
80 |
it { |
81 |
expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-rule-jump_ingoing').with(
|
82 |
target: 'nftables-inet-filter-chain-default_fwd', |
83 |
content: %r{^ iifname eth0 oifname eth1 jump ingoing$}, |
84 |
order: '20-nftables-inet-filter-chain-default_fwd-rule-jump_ingoing-b' |
85 |
) |
86 |
} |
87 |
|
88 |
it { |
89 |
expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-footer').with(
|
90 |
target: 'nftables-inet-filter-chain-default_fwd', |
91 |
content: %r{^\}$}, |
92 |
order: '99' |
93 |
) |
94 |
} |
95 |
|
96 |
it { |
97 |
expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-ingoing-header').with(
|
98 |
target: 'nftables-inet-filter-chain-ingoing', |
99 |
content: %r{^chain ingoing \{$}, |
100 |
order: '00' |
101 |
) |
102 |
} |
103 |
|
104 |
it { |
105 |
expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-ingoing-rule-http').with(
|
106 |
target: 'nftables-inet-filter-chain-ingoing', |
107 |
content: %r{^ ip daddr 192.0.2.2 tcp dport http accept$}, |
108 |
order: '10-nftables-inet-filter-chain-ingoing-rule-http-b' |
109 |
) |
110 |
} |
111 |
|
112 |
it { |
113 |
expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-ingoing-rule-https').with(
|
114 |
target: 'nftables-inet-filter-chain-ingoing', |
115 |
content: %r{^ ip daddr 192.0.2.2 tcp dport https accept$}, |
116 |
order: '10-nftables-inet-filter-chain-ingoing-rule-https-b' |
117 |
) |
118 |
} |
119 |
|
120 |
it { |
121 |
expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-ingoing-rule-http_alt').with(
|
122 |
target: 'nftables-inet-filter-chain-ingoing', |
123 |
content: %r{^ iifname eth0 ip daddr 192.0.2.2 tcp dport 8000 accept$}, |
124 |
order: '10-nftables-inet-filter-chain-ingoing-rule-http_alt-b' |
125 |
) |
126 |
} |
127 |
|
128 |
it { |
129 |
expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-ingoing-rule-wireguard').with(
|
130 |
target: 'nftables-inet-filter-chain-ingoing', |
131 |
content: %r{^ iifname eth0 ip daddr 192.0.2.3 udp dport 51820 accept$}, |
132 |
order: '10-nftables-inet-filter-chain-ingoing-rule-wireguard-b' |
133 |
) |
134 |
} |
135 |
|
136 |
it { |
137 |
expect(subject).to contain_concat__fragment('nftables-inet-filter-chain-ingoing-footer').with(
|
138 |
target: 'nftables-inet-filter-chain-ingoing', |
139 |
content: %r{^\}$}, |
140 |
order: '99' |
141 |
) |
142 |
} |
143 |
|
144 |
it { |
145 |
expect(subject).to contain_concat('nftables-ip-nat-chain-PREROUTING').with(
|
146 |
path: '/etc/nftables/puppet-preflight/ip-nat-chain-PREROUTING.nft', |
147 |
owner: 'root', |
148 |
group: 'root', |
149 |
mode: nft_mode,
|
150 |
ensure_newline: true |
151 |
) |
152 |
} |
153 |
|
154 |
it { |
155 |
expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-header').with(
|
156 |
target: 'nftables-ip-nat-chain-PREROUTING', |
157 |
content: %r{^chain PREROUTING \{$}, |
158 |
order: '00' |
159 |
) |
160 |
} |
161 |
|
162 |
it { |
163 |
expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-type').with(
|
164 |
target: 'nftables-ip-nat-chain-PREROUTING', |
165 |
content: %r{^ type nat hook prerouting priority -100$}, |
166 |
order: '01-nftables-ip-nat-chain-PREROUTING-rule-type-b' |
167 |
) |
168 |
} |
169 |
|
170 |
it { |
171 |
expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-policy').with(
|
172 |
target: 'nftables-ip-nat-chain-PREROUTING', |
173 |
content: %r{^ policy accept$}, |
174 |
order: '02-nftables-ip-nat-chain-PREROUTING-rule-policy-b' |
175 |
) |
176 |
} |
177 |
|
178 |
it { |
179 |
expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-http').with(
|
180 |
target: 'nftables-ip-nat-chain-PREROUTING', |
181 |
content: %r{^ tcp dport http dnat to 192.0.2.2$}, |
182 |
order: '10-nftables-ip-nat-chain-PREROUTING-rule-http-b' |
183 |
) |
184 |
} |
185 |
|
186 |
it { |
187 |
expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-https').with(
|
188 |
target: 'nftables-ip-nat-chain-PREROUTING', |
189 |
content: %r{^ tcp dport https dnat to 192.0.2.2$}, |
190 |
order: '10-nftables-ip-nat-chain-PREROUTING-rule-https-b' |
191 |
) |
192 |
} |
193 |
|
194 |
it { |
195 |
expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-http_alt').with(
|
196 |
target: 'nftables-ip-nat-chain-PREROUTING', |
197 |
content: %r{^ iifname eth0 tcp dport 8080 dnat to 192.0.2.2:8000$}, |
198 |
order: '10-nftables-ip-nat-chain-PREROUTING-rule-http_alt-b' |
199 |
) |
200 |
} |
201 |
|
202 |
it { |
203 |
expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-wireguard').with(
|
204 |
target: 'nftables-ip-nat-chain-PREROUTING', |
205 |
content: %r{^ iifname eth0 udp dport 51820 dnat to 192.0.2.3$}, |
206 |
order: '10-nftables-ip-nat-chain-PREROUTING-rule-wireguard-b' |
207 |
) |
208 |
} |
209 |
|
210 |
it { |
211 |
expect(subject).to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-footer').with(
|
212 |
target: 'nftables-ip-nat-chain-PREROUTING', |
213 |
content: %r{^\}$}, |
214 |
order: '99' |
215 |
) |
216 |
} |
217 |
end
|
218 |
end
|
219 |
end
|
220 |
end
|