root / spec / classes / nftables_spec.rb @ f1ef02c5
Historique | Voir | Annoter | Télécharger (6,01 ko)
1 | 64134e4e | tr | require 'spec_helper'
|
---|---|---|---|
2 | |||
3 | describe 'nftables' do |
||
4 | let(:pre_condition) { 'Exec{path => "/bin"}' } |
||
5 | |||
6 | on_supported_os.each do |os, os_facts|
|
||
7 | context "on #{os}" do |
||
8 | let(:facts) { os_facts }
|
||
9 | |||
10 | it { is_expected.to compile } |
||
11 | 5acb554a | tr | |
12 | it { is_expected.to contain_package('nftables') }
|
||
13 | |||
14 | 01d8a819 | tr | it { |
15 | is_expected.to contain_file('/etc/nftables/puppet.nft').with(
|
||
16 | ensure: 'file', |
||
17 | owner: 'root', |
||
18 | group: 'root', |
||
19 | mode: '0640', |
||
20 | 82d10659 | Nacho Barrientos | content: %r{flush ruleset}, |
21 | 01d8a819 | tr | ) |
22 | } |
||
23 | |||
24 | it { |
||
25 | is_expected.to contain_file('/etc/nftables/puppet').with(
|
||
26 | ensure: 'directory', |
||
27 | owner: 'root', |
||
28 | group: 'root', |
||
29 | mode: '0750', |
||
30 | purge: true, |
||
31 | force: true, |
||
32 | recurse: true, |
||
33 | ) |
||
34 | } |
||
35 | |||
36 | it { |
||
37 | 30462da1 | Steve Traylen | is_expected.to contain_file('/etc/nftables/puppet-preflight.nft').with(
|
38 | ensure: 'file', |
||
39 | owner: 'root', |
||
40 | group: 'root', |
||
41 | mode: '0640', |
||
42 | 82d10659 | Nacho Barrientos | content: %r{flush ruleset}, |
43 | 30462da1 | Steve Traylen | ) |
44 | } |
||
45 | |||
46 | it { |
||
47 | is_expected.to contain_file('/etc/nftables/puppet-preflight').with(
|
||
48 | ensure: 'directory', |
||
49 | owner: 'root', |
||
50 | group: 'root', |
||
51 | mode: '0750', |
||
52 | purge: true, |
||
53 | force: true, |
||
54 | recurse: true, |
||
55 | ) |
||
56 | } |
||
57 | |||
58 | it { |
||
59 | is_expected.to contain_exec('nft validate').with(
|
||
60 | refreshonly: true, |
||
61 | command: %r{^/usr/sbin/nft -I /etc/nftables/puppet-preflight -c -f /etc/nftables/puppet-preflight.nft.*}, |
||
62 | ) |
||
63 | } |
||
64 | |||
65 | it { |
||
66 | 01d8a819 | tr | is_expected.to contain_service('nftables').with(
|
67 | ensure: 'running', |
||
68 | enable: true, |
||
69 | 30462da1 | Steve Traylen | hasrestart: true, |
70 | restart: %r{/usr/bin/systemctl reload nft.*}, |
||
71 | 01d8a819 | tr | ) |
72 | } |
||
73 | |||
74 | it { |
||
75 | ce22630b | Steve Traylen | is_expected.to contain_systemd__dropin_file('puppet_nft.conf').with(
|
76 | content: %r{^ExecReload=/sbin/nft -I /etc/nftables/puppet -f /etc/sysconfig/nftables.conf$}, |
||
77 | ) |
||
78 | } |
||
79 | |||
80 | it { |
||
81 | 01d8a819 | tr | is_expected.to contain_service('firewalld').with(
|
82 | ensure: 'stopped', |
||
83 | enable: 'mask', |
||
84 | ) |
||
85 | } |
||
86 | e17693e3 | Steve Traylen | it { is_expected.to contain_class('nftables::rules::out::http') }
|
87 | it { is_expected.to contain_class('nftables::rules::out::https') }
|
||
88 | it { is_expected.to contain_class('nftables::rules::out::dns') }
|
||
89 | it { is_expected.to contain_class('nftables::rules::out::chrony') }
|
||
90 | it { is_expected.not_to contain_class('nftables::rules::out::all') }
|
||
91 | it { is_expected.not_to contain_nftables__rule('default_out-all') }
|
||
92 | |||
93 | context 'with out_all set true' do |
||
94 | b171ac7f | mh | let(:params) do |
95 | { |
||
96 | out_all: true, |
||
97 | } |
||
98 | e17693e3 | Steve Traylen | end
|
99 | |||
100 | it { is_expected.to contain_class('nftables::rules::out::all') }
|
||
101 | it { is_expected.not_to contain_class('nftables::rules::out::http') }
|
||
102 | it { is_expected.not_to contain_class('nftables::rules::out::https') }
|
||
103 | it { is_expected.not_to contain_class('nftables::rules::out::dns') }
|
||
104 | it { is_expected.not_to contain_class('nftables::rules::out::chrony') }
|
||
105 | it { is_expected.to contain_nftables__rule('default_out-all').with_content('accept') } |
||
106 | it { is_expected.to contain_nftables__rule('default_out-all').with_order('90') } |
||
107 | end
|
||
108 | b3a7a6dd | tr | |
109 | context 'with custom rules' do |
||
110 | let(:params) do |
||
111 | { |
||
112 | rules: {
|
||
113 | 'INPUT-web_accept' => {
|
||
114 | order: '50', |
||
115 | content: 'iifname eth0 tcp dport { 80, 443 } accept', |
||
116 | }, |
||
117 | }, |
||
118 | } |
||
119 | end
|
||
120 | |||
121 | it { |
||
122 | is_expected.to contain_concat__fragment('nftables-inet-filter-chain-INPUT-rule-web_accept').with(
|
||
123 | target: 'nftables-inet-filter-chain-INPUT', |
||
124 | content: %r{^ iifname eth0 tcp dport \{ 80, 443 \} accept$}, |
||
125 | 61f03b47 | Steve Traylen | order: '50-nftables-inet-filter-chain-INPUT-rule-web_accept-b', |
126 | b3a7a6dd | tr | ) |
127 | } |
||
128 | end
|
||
129 | ae9872e2 | Nacho Barrientos | |
130 | 802d80d1 | Nacho Barrientos | context 'with custom sets' do |
131 | let(:params) do |
||
132 | { |
||
133 | sets: {
|
||
134 | 'testset1' => {
|
||
135 | type: 'ipv4_addr', |
||
136 | gc_interval: 2, |
||
137 | }, |
||
138 | 'testset2' => {
|
||
139 | type: 'ipv6_addr', |
||
140 | elements: ['2a02:62:c601::dead:beef'], |
||
141 | }, |
||
142 | }, |
||
143 | } |
||
144 | end
|
||
145 | |||
146 | it { |
||
147 | is_expected.to contain_nftables__set('testset1').with(
|
||
148 | type: 'ipv4_addr', |
||
149 | gc_interval: 2, |
||
150 | table: 'inet-filter', |
||
151 | ) |
||
152 | } |
||
153 | it { |
||
154 | is_expected.to contain_nftables__set('testset2').with(
|
||
155 | type: 'ipv6_addr', |
||
156 | elements: ['2a02:62:c601::dead:beef'], |
||
157 | table: 'inet-filter', |
||
158 | ) |
||
159 | } |
||
160 | end
|
||
161 | |||
162 | ae9872e2 | Nacho Barrientos | context 'without masking firewalld' do |
163 | let(:params) do |
||
164 | { |
||
165 | 'firewalld_enable' => false, |
||
166 | } |
||
167 | end
|
||
168 | |||
169 | it { |
||
170 | is_expected.to contain_service('firewalld').with(
|
||
171 | ensure: 'stopped', |
||
172 | enable: false, |
||
173 | ) |
||
174 | } |
||
175 | end
|
||
176 | 03d9e7da | Steve Traylen | |
177 | context 'with with noflush_tables parameter' do |
||
178 | let(:params) do |
||
179 | { |
||
180 | noflush_tables: ['inet-f2b-table'], |
||
181 | } |
||
182 | end
|
||
183 | |||
184 | context 'with no nftables fact' do |
||
185 | it { is_expected.to contain_file('/etc/nftables/puppet-preflight.nft').with_content(%r{^flush ruleset$}) } |
||
186 | end
|
||
187 | |||
188 | context 'with nftables fact matching' do |
||
189 | let(:facts) do |
||
190 | super().merge(nftables: { tables: ['inet-abc', 'inet-f2b-table'] }) |
||
191 | end
|
||
192 | |||
193 | it { |
||
194 | 7e5b657a | Steve Traylen | is_expected.to contain_file('/etc/nftables/puppet-preflight.nft').
|
195 | with_content(%r{^flush table inet abc$})
|
||
196 | 03d9e7da | Steve Traylen | } |
197 | end
|
||
198 | context 'with nftables fact not matching' do |
||
199 | let(:facts) do |
||
200 | super().merge(nftables: { tables: ['inet-abc', 'inet-ijk'] }) |
||
201 | end
|
||
202 | |||
203 | it { |
||
204 | 7e5b657a | Steve Traylen | is_expected.to contain_file('/etc/nftables/puppet-preflight.nft').
|
205 | with_content(%r{^flush table inet abc; flush table inet ijk$})
|
||
206 | 03d9e7da | Steve Traylen | } |
207 | end
|
||
208 | end
|
||
209 | 64134e4e | tr | end
|
210 | end
|
||
211 | end |