Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / spec / classes / router_spec.rb @ 351a88fb

Historique | Voir | Annoter | Télécharger (8,94 ko)

1 d78c1613 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 8f5d09ec tr
      context 'as router' do
11
        let(:pre_condition) do
12 d78c1613 tr
          """
13 af544fea tr
          # inet-filter-chain-ingoing
14
          nftables::chain{ 'ingoing':
15
            inject     => '20-default_fwd',
16
            inject_iif => 'eth0',
17
            inject_oif => 'eth1';
18
          }
19

20 d78c1613 tr
          # inet-filter-chain-default_fwd
21 351a88fb tr
          nftables::rules::dnat4{
22
            'http':
23
              order => '10',
24
              chain => 'ingoing',
25
              daddr => '192.0.2.2',
26
              port  => 'http';
27
            'https':
28
              order => '10',
29
              chain => 'ingoing',
30
              daddr => '192.0.2.2',
31
              port  => 'https';
32
            'http_alt':
33
              order => '10',
34
              chain => 'ingoing',
35
              iif   => 'eth0',
36
              daddr => '192.0.2.2',
37
              proto => 'tcp',
38
              port  => 8080,
39
              dport => 80;
40
            'wireguard':
41
              order => '10',
42
              chain => 'ingoing',
43
              iif   => 'eth0',
44
              daddr => '192.0.2.3',
45
              proto => 'udp',
46
              port  => '51820';
47
          }
48

49
          # inet-filter-chain-default_fwd
50 d78c1613 tr
          nftables::rule{
51
            'default_fwd-out':
52
              order   => '20',
53
              content => 'iifname eth1 oifname eth0 accept';
54
            'default_fwd-drop':
55
              order   => '90',
56
              content => 'iifname eth0 drop';
57 af544fea tr

58 d78c1613 tr
            'POSTROUTING-masquerade':
59
              table   => 'ip-nat',
60
              order   => '20',
61
              content => 'oifname eth0 masquerade';
62
          }
63
          """
64 8f5d09ec tr
        end
65 d78c1613 tr
66
        it { is_expected.to compile }
67
68
        it { is_expected.to contain_concat('nftables-inet-filter-chain-default_fwd').with(
69
          :path           => '/etc/nftables/puppet/inet-filter-chain-default_fwd.nft',
70
          :owner          => 'root',
71
          :group          => 'root',
72
          :mode           => '0640',
73
          :ensure_newline => true,
74
        )}
75
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-header').with(
76
          :target  => 'nftables-inet-filter-chain-default_fwd',
77
          :content => /^chain default_fwd {$/,
78
          :order   => '00',
79
        )}
80
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-rule-out').with(
81
          :target  => 'nftables-inet-filter-chain-default_fwd',
82
          :content => /^  iifname eth1 oifname eth0 accept$/,
83
          :order   => '20',
84
        )}
85 af544fea tr
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-rule-jump_ingoing').with(
86 9ae64df9 tr
          :target  => 'nftables-inet-filter-chain-default_fwd',
87 af544fea tr
          :content => /^  iifname eth0 oifname eth1 jump ingoing$/,
88
          :order   => '20',
89 9ae64df9 tr
        )}
90 d78c1613 tr
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-rule-drop').with(
91
          :target  => 'nftables-inet-filter-chain-default_fwd',
92
          :content => /^  iifname eth0 drop$/,
93
          :order   => '90',
94
        )}
95
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-footer').with(
96
          :target  => 'nftables-inet-filter-chain-default_fwd',
97
          :content => /^}$/,
98
          :order   => '99',
99
        )}
100
101 af544fea tr
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-ingoing-header').with(
102
          :target  => 'nftables-inet-filter-chain-ingoing',
103
          :content => /^chain ingoing {$/,
104
          :order   => '00',
105
        )}
106 351a88fb tr
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-ingoing-rule-http').with(
107
          :target  => 'nftables-inet-filter-chain-ingoing',
108
          :content => /^  ip daddr 192.0.2.2 tcp dport http accept$/,
109
          :order   => '10',
110
        )}
111
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-ingoing-rule-https').with(
112
          :target  => 'nftables-inet-filter-chain-ingoing',
113
          :content => /^  ip daddr 192.0.2.2 tcp dport https accept$/,
114
          :order   => '10',
115
        )}
116
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-ingoing-rule-http_alt').with(
117 af544fea tr
          :target  => 'nftables-inet-filter-chain-ingoing',
118 351a88fb tr
          :content => /^  iifname eth0 ip daddr 192.0.2.2 tcp dport 80 accept$/,
119
          :order   => '10',
120
        )}
121
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-ingoing-rule-wireguard').with(
122
          :target  => 'nftables-inet-filter-chain-ingoing',
123
          :content => /^  iifname eth0 ip daddr 192.0.2.3 udp dport 51820 accept$/,
124 af544fea tr
          :order   => '10',
125
        )}
126
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-ingoing-footer').with(
127
          :target  => 'nftables-inet-filter-chain-ingoing',
128
          :content => /^}$/,
129
          :order   => '99',
130
        )}
131
132 95b1259b tr
        it { is_expected.to contain_concat('nftables-ip-nat-chain-PREROUTING').with(
133
          :path           => '/etc/nftables/puppet/ip-nat-chain-PREROUTING.nft',
134
          :owner          => 'root',
135
          :group          => 'root',
136
          :mode           => '0640',
137
          :ensure_newline => true,
138
        )}
139
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-header').with(
140
          :target  => 'nftables-ip-nat-chain-PREROUTING',
141
          :content => /^chain PREROUTING {$/,
142
          :order   => '00',
143
        )}
144
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-type').with(
145
          :target  => 'nftables-ip-nat-chain-PREROUTING',
146
          :content => /^  type nat hook prerouting priority -100$/,
147
          :order   => '01',
148
        )}
149
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-policy').with(
150
          :target  => 'nftables-ip-nat-chain-PREROUTING',
151
          :content => /^  policy accept$/,
152
          :order   => '02',
153
        )}
154 351a88fb tr
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-http').with(
155
          :target  => 'nftables-ip-nat-chain-PREROUTING',
156
          :content => /^  tcp dport http dnat to 192.0.2.2$/,
157
          :order   => '10',
158
        )}
159
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-https').with(
160 9ae64df9 tr
          :target  => 'nftables-ip-nat-chain-PREROUTING',
161 351a88fb tr
          :content => /^  tcp dport https dnat to 192.0.2.2$/,
162
          :order   => '10',
163
        )}
164
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-http_alt').with(
165
          :target  => 'nftables-ip-nat-chain-PREROUTING',
166
          :content => /^  iifname eth0 tcp dport 8080 dnat to 192.0.2.2:80$/,
167
          :order   => '10',
168
        )}
169
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-wireguard').with(
170
          :target  => 'nftables-ip-nat-chain-PREROUTING',
171
          :content => /^  iifname eth0 udp dport 51820 dnat to 192.0.2.3$/,
172
          :order   => '10',
173 9ae64df9 tr
        )}
174 95b1259b tr
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-footer').with(
175
          :target  => 'nftables-ip-nat-chain-PREROUTING',
176
          :content => /^}$/,
177
          :order   => '99',
178
        )}
179
180 d78c1613 tr
        it { is_expected.to contain_concat('nftables-ip-nat-chain-POSTROUTING').with(
181
          :path           => '/etc/nftables/puppet/ip-nat-chain-POSTROUTING.nft',
182
          :owner          => 'root',
183
          :group          => 'root',
184
          :mode           => '0640',
185
          :ensure_newline => true,
186
        )}
187
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-header').with(
188
          :target  => 'nftables-ip-nat-chain-POSTROUTING',
189
          :content => /^chain POSTROUTING {$/,
190
          :order   => '00',
191
        )}
192
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-type').with(
193
          :target  => 'nftables-ip-nat-chain-POSTROUTING',
194
          :content => /^  type nat hook postrouting priority 100$/,
195
          :order   => '01',
196
        )}
197
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-policy').with(
198
          :target  => 'nftables-ip-nat-chain-POSTROUTING',
199
          :content => /^  policy accept$/,
200
          :order   => '02',
201
        )}
202
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-masquerade').with(
203
          :target  => 'nftables-ip-nat-chain-POSTROUTING',
204
          :content => /^  oifname eth0 masquerade$/,
205
          :order   => '20',
206
        )}
207
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-footer').with(
208
          :target  => 'nftables-ip-nat-chain-POSTROUTING',
209
          :content => /^}$/,
210
          :order   => '99',
211
        )}
212
      end
213
    end
214
  end
215
end