Projet

Général

Profil

Révision 01d8a819

ID01d8a819a56fcaf14e4b7b73774a6ed4dc30635a
Parent 705bb26f
Enfant 9d7d63a6

Ajouté par tr il y a plus de 4 ans

Styling to make tests green

Voir les différences:

spec/classes/dnat4_spec.rb
9 9

  
10 10
      context 'with dnat' do
11 11
        let(:pre_condition) do
12
          """
12
          '
13 13
          # inet-filter-chain-ingoing
14
          nftables::chain{ 'ingoing':
15
            inject     => '20-default_fwd',
16
            inject_iif => 'eth0',
17
            inject_oif => 'eth1';
14
          nftables::chain{ \'ingoing\':
15
            inject     => \'20-default_fwd\',
16
            inject_iif => \'eth0\',
17
            inject_oif => \'eth1\';
18 18
          }
19 19

  
20 20
          # inet-filter-chain-default_fwd
21 21
          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',
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 38
              port  => 8080,
39 39
              dport => 8000;
40
            'wireguard':
41
              order => '10',
42
              chain => 'ingoing',
43
              iif   => 'eth0',
44
              daddr => '192.0.2.3',
45
              proto => 'udp',
46
              port  => '51820';
40
            \'wireguard\':
41
              order => \'10\',
42
              chain => \'ingoing\',
43
              iif   => \'eth0\',
44
              daddr => \'192.0.2.3\',
45
              proto => \'udp\',
46
              port  => \'51820\';
47 47
          }
48
          """
48
          '
49 49
        end
50 50

  
51 51
        it { is_expected.to compile }
52 52

  
53
        it { is_expected.to contain_concat('nftables-inet-filter-chain-default_fwd').with(
54
          :path           => '/etc/nftables/puppet/inet-filter-chain-default_fwd.nft',
55
          :owner          => 'root',
56
          :group          => 'root',
57
          :mode           => '0640',
58
          :ensure_newline => true,
59
        )}
60
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-header').with(
61
          :target  => 'nftables-inet-filter-chain-default_fwd',
62
          :content => /^chain default_fwd {$/,
63
          :order   => '00',
64
        )}
65
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-rule-jump_ingoing').with(
66
          :target  => 'nftables-inet-filter-chain-default_fwd',
67
          :content => /^  iifname eth0 oifname eth1 jump ingoing$/,
68
          :order   => '20',
69
        )}
70
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-footer').with(
71
          :target  => 'nftables-inet-filter-chain-default_fwd',
72
          :content => /^}$/,
73
          :order   => '99',
74
        )}
53
        it {
54
          is_expected.to contain_concat('nftables-inet-filter-chain-default_fwd').with(
55
            path:           '/etc/nftables/puppet/inet-filter-chain-default_fwd.nft',
56
            owner:          'root',
57
            group:          'root',
58
            mode:           '0640',
59
            ensure_newline: true,
60
          )
61
        }
62
        it {
63
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-header').with(
64
            target:  'nftables-inet-filter-chain-default_fwd',
65
            content: %r{^chain default_fwd \{$},
66
            order:   '00',
67
          )
68
        }
69
        it {
70
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-rule-jump_ingoing').with(
71
            target:  'nftables-inet-filter-chain-default_fwd',
72
            content: %r{^  iifname eth0 oifname eth1 jump ingoing$},
73
            order:   '20',
74
          )
75
        }
76
        it {
77
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-footer').with(
78
            target:  'nftables-inet-filter-chain-default_fwd',
79
            content: %r{^\}$},
80
            order:   '99',
81
          )
82
        }
75 83

  
76
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-ingoing-header').with(
77
          :target  => 'nftables-inet-filter-chain-ingoing',
78
          :content => /^chain ingoing {$/,
79
          :order   => '00',
80
        )}
81
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-ingoing-rule-http').with(
82
          :target  => 'nftables-inet-filter-chain-ingoing',
83
          :content => /^  ip daddr 192.0.2.2 tcp dport http accept$/,
84
          :order   => '10',
85
        )}
86
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-ingoing-rule-https').with(
87
          :target  => 'nftables-inet-filter-chain-ingoing',
88
          :content => /^  ip daddr 192.0.2.2 tcp dport https accept$/,
89
          :order   => '10',
90
        )}
91
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-ingoing-rule-http_alt').with(
92
          :target  => 'nftables-inet-filter-chain-ingoing',
93
          :content => /^  iifname eth0 ip daddr 192.0.2.2 tcp dport 8000 accept$/,
94
          :order   => '10',
95
        )}
96
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-ingoing-rule-wireguard').with(
97
          :target  => 'nftables-inet-filter-chain-ingoing',
98
          :content => /^  iifname eth0 ip daddr 192.0.2.3 udp dport 51820 accept$/,
99
          :order   => '10',
100
        )}
101
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-ingoing-footer').with(
102
          :target  => 'nftables-inet-filter-chain-ingoing',
103
          :content => /^}$/,
104
          :order   => '99',
105
        )}
84
        it {
85
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-ingoing-header').with(
86
            target:  'nftables-inet-filter-chain-ingoing',
87
            content: %r{^chain ingoing \{$},
88
            order:   '00',
89
          )
90
        }
91
        it {
92
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-ingoing-rule-http').with(
93
            target:  'nftables-inet-filter-chain-ingoing',
94
            content: %r{^  ip daddr 192.0.2.2 tcp dport http accept$},
95
            order:   '10',
96
          )
97
        }
98
        it {
99
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-ingoing-rule-https').with(
100
            target:  'nftables-inet-filter-chain-ingoing',
101
            content: %r{^  ip daddr 192.0.2.2 tcp dport https accept$},
102
            order:   '10',
103
          )
104
        }
105
        it {
106
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-ingoing-rule-http_alt').with(
107
            target:  'nftables-inet-filter-chain-ingoing',
108
            content: %r{^  iifname eth0 ip daddr 192.0.2.2 tcp dport 8000 accept$},
109
            order:   '10',
110
          )
111
        }
112
        it {
113
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-ingoing-rule-wireguard').with(
114
            target:  'nftables-inet-filter-chain-ingoing',
115
            content: %r{^  iifname eth0 ip daddr 192.0.2.3 udp dport 51820 accept$},
116
            order:   '10',
117
          )
118
        }
119
        it {
120
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-ingoing-footer').with(
121
            target:  'nftables-inet-filter-chain-ingoing',
122
            content: %r{^\}$},
123
            order:   '99',
124
          )
125
        }
106 126

  
107
        it { is_expected.to contain_concat('nftables-ip-nat-chain-PREROUTING').with(
108
          :path           => '/etc/nftables/puppet/ip-nat-chain-PREROUTING.nft',
109
          :owner          => 'root',
110
          :group          => 'root',
111
          :mode           => '0640',
112
          :ensure_newline => true,
113
        )}
114
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-header').with(
115
          :target  => 'nftables-ip-nat-chain-PREROUTING',
116
          :content => /^chain PREROUTING {$/,
117
          :order   => '00',
118
        )}
119
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-type').with(
120
          :target  => 'nftables-ip-nat-chain-PREROUTING',
121
          :content => /^  type nat hook prerouting priority -100$/,
122
          :order   => '01',
123
        )}
124
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-policy').with(
125
          :target  => 'nftables-ip-nat-chain-PREROUTING',
126
          :content => /^  policy accept$/,
127
          :order   => '02',
128
        )}
129
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-http').with(
130
          :target  => 'nftables-ip-nat-chain-PREROUTING',
131
          :content => /^  tcp dport http dnat to 192.0.2.2$/,
132
          :order   => '10',
133
        )}
134
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-https').with(
135
          :target  => 'nftables-ip-nat-chain-PREROUTING',
136
          :content => /^  tcp dport https dnat to 192.0.2.2$/,
137
          :order   => '10',
138
        )}
139
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-http_alt').with(
140
          :target  => 'nftables-ip-nat-chain-PREROUTING',
141
          :content => /^  iifname eth0 tcp dport 8080 dnat to 192.0.2.2:8000$/,
142
          :order   => '10',
143
        )}
144
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-wireguard').with(
145
          :target  => 'nftables-ip-nat-chain-PREROUTING',
146
          :content => /^  iifname eth0 udp dport 51820 dnat to 192.0.2.3$/,
147
          :order   => '10',
148
        )}
149
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-footer').with(
150
          :target  => 'nftables-ip-nat-chain-PREROUTING',
151
          :content => /^}$/,
152
          :order   => '99',
153
        )}
127
        it {
128
          is_expected.to contain_concat('nftables-ip-nat-chain-PREROUTING').with(
129
            path:           '/etc/nftables/puppet/ip-nat-chain-PREROUTING.nft',
130
            owner:          'root',
131
            group:          'root',
132
            mode:           '0640',
133
            ensure_newline: true,
134
          )
135
        }
136
        it {
137
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-header').with(
138
            target:  'nftables-ip-nat-chain-PREROUTING',
139
            content: %r{^chain PREROUTING \{$},
140
            order:   '00',
141
          )
142
        }
143
        it {
144
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-type').with(
145
            target:  'nftables-ip-nat-chain-PREROUTING',
146
            content: %r{^  type nat hook prerouting priority -100$},
147
            order:   '01',
148
          )
149
        }
150
        it {
151
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-policy').with(
152
            target:  'nftables-ip-nat-chain-PREROUTING',
153
            content: %r{^  policy accept$},
154
            order:   '02',
155
          )
156
        }
157
        it {
158
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-http').with(
159
            target:  'nftables-ip-nat-chain-PREROUTING',
160
            content: %r{^  tcp dport http dnat to 192.0.2.2$},
161
            order:   '10',
162
          )
163
        }
164
        it {
165
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-https').with(
166
            target:  'nftables-ip-nat-chain-PREROUTING',
167
            content: %r{^  tcp dport https dnat to 192.0.2.2$},
168
            order:   '10',
169
          )
170
        }
171
        it {
172
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-http_alt').with(
173
            target:  'nftables-ip-nat-chain-PREROUTING',
174
            content: %r{^  iifname eth0 tcp dport 8080 dnat to 192.0.2.2:8000$},
175
            order:   '10',
176
          )
177
        }
178
        it {
179
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-wireguard').with(
180
            target:  'nftables-ip-nat-chain-PREROUTING',
181
            content: %r{^  iifname eth0 udp dport 51820 dnat to 192.0.2.3$},
182
            order:   '10',
183
          )
184
        }
185
        it {
186
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-footer').with(
187
            target:  'nftables-ip-nat-chain-PREROUTING',
188
            content: %r{^\}$},
189
            order:   '99',
190
          )
191
        }
154 192
      end
155 193
    end
156 194
  end
spec/classes/inet_filter_spec.rb
9 9

  
10 10
      it { is_expected.to compile }
11 11

  
12
      it { is_expected.to contain_file('/etc/nftables/puppet/inet-filter.nft').with(
13
        :ensure => 'file',
14
        :owner  => 'root',
15
        :group  => 'root',
16
        :mode   => '0640',
17
      )}
12
      it {
13
        is_expected.to contain_file('/etc/nftables/puppet/inet-filter.nft').with(
14
          ensure: 'file',
15
          owner:  'root',
16
          group:  'root',
17
          mode:   '0640',
18
        )
19
      }
18 20

  
19 21
      context 'chain input' do
20
        it { is_expected.to contain_concat('nftables-inet-filter-chain-INPUT').with(
21
          :path           => '/etc/nftables/puppet/inet-filter-chain-INPUT.nft',
22
          :owner          => 'root',
23
          :group          => 'root',
24
          :mode           => '0640',
25
          :ensure_newline => true,
26
        )}
27
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-INPUT-header').with(
28
          :target  => 'nftables-inet-filter-chain-INPUT',
29
          :content => /^chain INPUT {$/,
30
          :order   => '00',
31
        )}
32
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-INPUT-rule-type').with(
33
          :target  => 'nftables-inet-filter-chain-INPUT',
34
          :content => /^  type filter hook input priority 0$/,
35
          :order   => '01',
36
        )}
37
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-INPUT-rule-policy').with(
38
          :target  => 'nftables-inet-filter-chain-INPUT',
39
          :content => /^  policy drop$/,
40
          :order   => '02',
41
        )}
42
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-INPUT-rule-lo').with(
43
          :target  => 'nftables-inet-filter-chain-INPUT',
44
          :content => /^  iifname lo accept$/,
45
          :order   => '03',
46
        )}
47
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-INPUT-rule-jump_global').with(
48
          :target  => 'nftables-inet-filter-chain-INPUT',
49
          :content => /^  jump global$/,
50
          :order   => '04',
51
        )}
52
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-INPUT-rule-jump_default_in').with(
53
          :target  => 'nftables-inet-filter-chain-INPUT',
54
          :content => /^  jump default_in$/,
55
          :order   => '10',
56
        )}
57
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-INPUT-rule-log_rejected').with(
58
          :target  => 'nftables-inet-filter-chain-INPUT',
59
          :content => /^  log prefix \"\[nftables\] INPUT Rejected: \" flags all counter reject with icmpx type port-unreachable$/,
60
          :order   => '98',
61
        )}
62
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-INPUT-footer').with(
63
          :target  => 'nftables-inet-filter-chain-INPUT',
64
          :content => /^}$/,
65
          :order   => '99',
66
        )}
22
        it {
23
          is_expected.to contain_concat('nftables-inet-filter-chain-INPUT').with(
24
            path:           '/etc/nftables/puppet/inet-filter-chain-INPUT.nft',
25
            owner:          'root',
26
            group:          'root',
27
            mode:           '0640',
28
            ensure_newline: true,
29
          )
30
        }
31
        it {
32
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-INPUT-header').with(
33
            target:  'nftables-inet-filter-chain-INPUT',
34
            content: %r{^chain INPUT \{$},
35
            order:   '00',
36
          )
37
        }
38
        it {
39
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-INPUT-rule-type').with(
40
            target:  'nftables-inet-filter-chain-INPUT',
41
            content: %r{^  type filter hook input priority 0$},
42
            order:   '01',
43
          )
44
        }
45
        it {
46
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-INPUT-rule-policy').with(
47
            target:  'nftables-inet-filter-chain-INPUT',
48
            content: %r{^  policy drop$},
49
            order:   '02',
50
          )
51
        }
52
        it {
53
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-INPUT-rule-lo').with(
54
            target:  'nftables-inet-filter-chain-INPUT',
55
            content: %r{^  iifname lo accept$},
56
            order:   '03',
57
          )
58
        }
59
        it {
60
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-INPUT-rule-jump_global').with(
61
            target:  'nftables-inet-filter-chain-INPUT',
62
            content: %r{^  jump global$},
63
            order:   '04',
64
          )
65
        }
66
        it {
67
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-INPUT-rule-jump_default_in').with(
68
            target:  'nftables-inet-filter-chain-INPUT',
69
            content: %r{^  jump default_in$},
70
            order:   '10',
71
          )
72
        }
73
        it {
74
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-INPUT-rule-log_rejected').with(
75
            target:  'nftables-inet-filter-chain-INPUT',
76
            content: %r{^  log prefix \"\[nftables\] INPUT Rejected: \" flags all counter reject with icmpx type port-unreachable$},
77
            order:   '98',
78
          )
79
        }
80
        it {
81
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-INPUT-footer').with(
82
            target:  'nftables-inet-filter-chain-INPUT',
83
            content: %r{^\}$},
84
            order:   '99',
85
          )
86
        }
67 87

  
68
        it { is_expected.to contain_concat('nftables-inet-filter-chain-default_in').with(
69
          :path           => '/etc/nftables/puppet/inet-filter-chain-default_in.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_in-header').with(
76
          :target  => 'nftables-inet-filter-chain-default_in',
77
          :content => /^chain default_in {$/,
78
          :order   => '00',
79
        )}
80
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_in-footer').with(
81
          :target  => 'nftables-inet-filter-chain-default_in',
82
          :content => /^}$/,
83
          :order   => '99',
84
        )}
85
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_in-rule-ssh').with(
86
          :target  => 'nftables-inet-filter-chain-default_in',
87
          :content => /^  tcp dport \{22\} accept$/,
88
          :order   => '50',
89
        )}
88
        it {
89
          is_expected.to contain_concat('nftables-inet-filter-chain-default_in').with(
90
            path:           '/etc/nftables/puppet/inet-filter-chain-default_in.nft',
91
            owner:          'root',
92
            group:          'root',
93
            mode:           '0640',
94
            ensure_newline: true,
95
          )
96
        }
97
        it {
98
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_in-header').with(
99
            target:  'nftables-inet-filter-chain-default_in',
100
            content: %r{^chain default_in \{$},
101
            order:   '00',
102
          )
103
        }
104
        it {
105
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_in-footer').with(
106
            target:  'nftables-inet-filter-chain-default_in',
107
            content: %r{^\}$},
108
            order:   '99',
109
          )
110
        }
111
        it {
112
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_in-rule-ssh').with(
113
            target:  'nftables-inet-filter-chain-default_in',
114
            content: %r{^  tcp dport \{22\} accept$},
115
            order:   '50',
116
          )
117
        }
90 118
      end
91 119

  
92 120
      context 'chain output' do
93
        it { is_expected.to contain_concat('nftables-inet-filter-chain-OUTPUT').with(
94
          :path           => '/etc/nftables/puppet/inet-filter-chain-OUTPUT.nft',
95
          :owner          => 'root',
96
          :group          => 'root',
97
          :mode           => '0640',
98
          :ensure_newline => true,
99
        )}
100
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-OUTPUT-header').with(
101
          :target  => 'nftables-inet-filter-chain-OUTPUT',
102
          :content => /^chain OUTPUT {$/,
103
          :order   => '00',
104
        )}
105
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-OUTPUT-rule-type').with(
106
          :target  => 'nftables-inet-filter-chain-OUTPUT',
107
          :content => /^  type filter hook output priority 0$/,
108
          :order   => '01',
109
        )}
110
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-OUTPUT-rule-policy').with(
111
          :target  => 'nftables-inet-filter-chain-OUTPUT',
112
          :content => /^  policy drop$/,
113
          :order   => '02',
114
        )}
115
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-OUTPUT-rule-lo').with(
116
          :target  => 'nftables-inet-filter-chain-OUTPUT',
117
          :content => /^  oifname lo accept$/,
118
          :order   => '03',
119
        )}
120
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-OUTPUT-rule-jump_global').with(
121
          :target  => 'nftables-inet-filter-chain-OUTPUT',
122
          :content => /^  jump global$/,
123
          :order   => '04',
124
        )}
125
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-OUTPUT-rule-jump_default_out').with(
126
          :target  => 'nftables-inet-filter-chain-OUTPUT',
127
          :content => /^  jump default_out$/,
128
          :order   => '10',
129
        )}
130
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-OUTPUT-rule-log_rejected').with(
131
          :target  => 'nftables-inet-filter-chain-OUTPUT',
132
          :content => /^  log prefix \"\[nftables\] OUTPUT Rejected: \" flags all counter reject with icmpx type port-unreachable$/,
133
          :order   => '98',
134
        )}
135
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-OUTPUT-footer').with(
136
          :target  => 'nftables-inet-filter-chain-OUTPUT',
137
          :content => /^}$/,
138
          :order   => '99',
139
        )}
121
        it {
122
          is_expected.to contain_concat('nftables-inet-filter-chain-OUTPUT').with(
123
            path:           '/etc/nftables/puppet/inet-filter-chain-OUTPUT.nft',
124
            owner:          'root',
125
            group:          'root',
126
            mode:           '0640',
127
            ensure_newline: true,
128
          )
129
        }
130
        it {
131
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-OUTPUT-header').with(
132
            target:  'nftables-inet-filter-chain-OUTPUT',
133
            content: %r{^chain OUTPUT \{$},
134
            order:   '00',
135
          )
136
        }
137
        it {
138
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-OUTPUT-rule-type').with(
139
            target:  'nftables-inet-filter-chain-OUTPUT',
140
            content: %r{^  type filter hook output priority 0$},
141
            order:   '01',
142
          )
143
        }
144
        it {
145
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-OUTPUT-rule-policy').with(
146
            target:  'nftables-inet-filter-chain-OUTPUT',
147
            content: %r{^  policy drop$},
148
            order:   '02',
149
          )
150
        }
151
        it {
152
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-OUTPUT-rule-lo').with(
153
            target:  'nftables-inet-filter-chain-OUTPUT',
154
            content: %r{^  oifname lo accept$},
155
            order:   '03',
156
          )
157
        }
158
        it {
159
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-OUTPUT-rule-jump_global').with(
160
            target:  'nftables-inet-filter-chain-OUTPUT',
161
            content: %r{^  jump global$},
162
            order:   '04',
163
          )
164
        }
165
        it {
166
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-OUTPUT-rule-jump_default_out').with(
167
            target:  'nftables-inet-filter-chain-OUTPUT',
168
            content: %r{^  jump default_out$},
169
            order:   '10',
170
          )
171
        }
172
        it {
173
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-OUTPUT-rule-log_rejected').with(
174
            target:  'nftables-inet-filter-chain-OUTPUT',
175
            content: %r{^  log prefix \"\[nftables\] OUTPUT Rejected: \" flags all counter reject with icmpx type port-unreachable$},
176
            order:   '98',
177
          )
178
        }
179
        it {
180
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-OUTPUT-footer').with(
181
            target:  'nftables-inet-filter-chain-OUTPUT',
182
            content: %r{^\}$},
183
            order:   '99',
184
          )
185
        }
140 186

  
141
        it { is_expected.to contain_concat('nftables-inet-filter-chain-default_out').with(
142
          :path           => '/etc/nftables/puppet/inet-filter-chain-default_out.nft',
143
          :owner          => 'root',
144
          :group          => 'root',
145
          :mode           => '0640',
146
          :ensure_newline => true,
147
        )}
148
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_out-header').with(
149
          :target  => 'nftables-inet-filter-chain-default_out',
150
          :content => /^chain default_out {$/,
151
          :order   => '00',
152
        )}
153
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_out-footer').with(
154
          :target  => 'nftables-inet-filter-chain-default_out',
155
          :content => /^}$/,
156
          :order   => '99',
157
        )}
158
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_out-rule-dnsudp').with(
159
          :target  => 'nftables-inet-filter-chain-default_out',
160
          :content => /^  udp dport 53 accept$/,
161
          :order   => '50',
162
        )}
163
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_out-rule-dnstcp').with(
164
          :target  => 'nftables-inet-filter-chain-default_out',
165
          :content => /^  tcp dport 53 accept$/,
166
          :order   => '50',
167
        )}
168
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_out-rule-chrony').with(
169
          :target  => 'nftables-inet-filter-chain-default_out',
170
          :content => /^  udp dport 123 accept$/,
171
          :order   => '50',
172
        )}
173
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_out-rule-http').with(
174
          :target  => 'nftables-inet-filter-chain-default_out',
175
          :content => /^  tcp dport 80 accept$/,
176
          :order   => '50',
177
        )}
178
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_out-rule-https').with(
179
          :target  => 'nftables-inet-filter-chain-default_out',
180
          :content => /^  tcp dport 443 accept$/,
181
          :order   => '50',
182
        )}
187
        it {
188
          is_expected.to contain_concat('nftables-inet-filter-chain-default_out').with(
189
            path:           '/etc/nftables/puppet/inet-filter-chain-default_out.nft',
190
            owner:          'root',
191
            group:          'root',
192
            mode:           '0640',
193
            ensure_newline: true,
194
          )
195
        }
196
        it {
197
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_out-header').with(
198
            target:  'nftables-inet-filter-chain-default_out',
199
            content: %r{^chain default_out \{$},
200
            order:   '00',
201
          )
202
        }
203
        it {
204
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_out-footer').with(
205
            target:  'nftables-inet-filter-chain-default_out',
206
            content: %r{^\}$},
207
            order:   '99',
208
          )
209
        }
210
        it {
211
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_out-rule-dnsudp').with(
212
            target:  'nftables-inet-filter-chain-default_out',
213
            content: %r{^  udp dport 53 accept$},
214
            order:   '50',
215
          )
216
        }
217
        it {
218
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_out-rule-dnstcp').with(
219
            target:  'nftables-inet-filter-chain-default_out',
220
            content: %r{^  tcp dport 53 accept$},
221
            order:   '50',
222
          )
223
        }
224
        it {
225
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_out-rule-chrony').with(
226
            target:  'nftables-inet-filter-chain-default_out',
227
            content: %r{^  udp dport 123 accept$},
228
            order:   '50',
229
          )
230
        }
231
        it {
232
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_out-rule-http').with(
233
            target:  'nftables-inet-filter-chain-default_out',
234
            content: %r{^  tcp dport 80 accept$},
235
            order:   '50',
236
          )
237
        }
238
        it {
239
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_out-rule-https').with(
240
            target:  'nftables-inet-filter-chain-default_out',
241
            content: %r{^  tcp dport 443 accept$},
242
            order:   '50',
243
          )
244
        }
183 245
      end
184 246

  
185 247
      context 'chain forward' do
186
        it { is_expected.to contain_concat('nftables-inet-filter-chain-FORWARD').with(
187
          :path           => '/etc/nftables/puppet/inet-filter-chain-FORWARD.nft',
188
          :owner          => 'root',
189
          :group          => 'root',
190
          :mode           => '0640',
191
          :ensure_newline => true,
192
        )}
193
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-FORWARD-header').with(
194
          :target  => 'nftables-inet-filter-chain-FORWARD',
195
          :content => /^chain FORWARD {$/,
196
          :order   => '00',
197
        )}
198
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-FORWARD-rule-type').with(
199
          :target  => 'nftables-inet-filter-chain-FORWARD',
200
          :content => /^  type filter hook forward priority 0$/,
201
          :order   => '01',
202
        )}
203
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-FORWARD-rule-policy').with(
204
          :target  => 'nftables-inet-filter-chain-FORWARD',
205
          :content => /^  policy drop$/,
206
          :order   => '02',
207
        )}
208
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-FORWARD-rule-jump_global').with(
209
          :target  => 'nftables-inet-filter-chain-FORWARD',
210
          :content => /^  jump global$/,
211
          :order   => '03',
212
        )}
213
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-FORWARD-rule-jump_default_fwd').with(
214
          :target  => 'nftables-inet-filter-chain-FORWARD',
215
          :content => /^  jump default_fwd$/,
216
          :order   => '10',
217
        )}
218
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-FORWARD-rule-log_rejected').with(
219
          :target  => 'nftables-inet-filter-chain-FORWARD',
220
          :content => /^  log prefix \"\[nftables\] FORWARD Rejected: \" flags all counter reject with icmpx type port-unreachable$/,
221
          :order   => '98',
222
        )}
223
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-FORWARD-footer').with(
224
          :target  => 'nftables-inet-filter-chain-FORWARD',
225
          :content => /^}$/,
226
          :order   => '99',
227
        )}
248
        it {
249
          is_expected.to contain_concat('nftables-inet-filter-chain-FORWARD').with(
250
            path:           '/etc/nftables/puppet/inet-filter-chain-FORWARD.nft',
251
            owner:          'root',
252
            group:          'root',
253
            mode:           '0640',
254
            ensure_newline: true,
255
          )
256
        }
257
        it {
258
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-FORWARD-header').with(
259
            target:  'nftables-inet-filter-chain-FORWARD',
260
            content: %r{^chain FORWARD \{$},
261
            order:   '00',
262
          )
263
        }
264
        it {
265
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-FORWARD-rule-type').with(
266
            target:  'nftables-inet-filter-chain-FORWARD',
267
            content: %r{^  type filter hook forward priority 0$},
268
            order:   '01',
269
          )
270
        }
271
        it {
272
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-FORWARD-rule-policy').with(
273
            target:  'nftables-inet-filter-chain-FORWARD',
274
            content: %r{^  policy drop$},
275
            order:   '02',
276
          )
277
        }
278
        it {
279
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-FORWARD-rule-jump_global').with(
280
            target:  'nftables-inet-filter-chain-FORWARD',
281
            content: %r{^  jump global$},
282
            order:   '03',
283
          )
284
        }
285
        it {
286
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-FORWARD-rule-jump_default_fwd').with(
287
            target:  'nftables-inet-filter-chain-FORWARD',
288
            content: %r{^  jump default_fwd$},
289
            order:   '10',
290
          )
291
        }
292
        it {
293
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-FORWARD-rule-log_rejected').with(
294
            target:  'nftables-inet-filter-chain-FORWARD',
295
            content: %r{^  log prefix \"\[nftables\] FORWARD Rejected: \" flags all counter reject with icmpx type port-unreachable$},
296
            order:   '98',
297
          )
298
        }
299
        it {
300
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-FORWARD-footer').with(
301
            target:  'nftables-inet-filter-chain-FORWARD',
302
            content: %r{^\}$},
303
            order:   '99',
304
          )
305
        }
228 306

  
229
        it { is_expected.to contain_concat('nftables-inet-filter-chain-default_fwd').with(
230
          :path           => '/etc/nftables/puppet/inet-filter-chain-default_fwd.nft',
231
          :owner          => 'root',
232
          :group          => 'root',
233
          :mode           => '0640',
234
          :ensure_newline => true,
235
        )}
236
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-header').with(
237
          :target  => 'nftables-inet-filter-chain-default_fwd',
238
          :content => /^chain default_fwd {$/,
239
          :order   => '00',
240
        )}
241
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-footer').with(
242
          :target  => 'nftables-inet-filter-chain-default_fwd',
243
          :content => /^}$/,
244
          :order   => '99',
245
        )}
307
        it {
308
          is_expected.to contain_concat('nftables-inet-filter-chain-default_fwd').with(
309
            path:           '/etc/nftables/puppet/inet-filter-chain-default_fwd.nft',
310
            owner:          'root',
311
            group:          'root',
312
            mode:           '0640',
313
            ensure_newline: true,
314
          )
315
        }
316
        it {
317
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-header').with(
318
            target:  'nftables-inet-filter-chain-default_fwd',
319
            content: %r{^chain default_fwd \{$},
320
            order:   '00',
321
          )
322
        }
323
        it {
324
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-footer').with(
325
            target:  'nftables-inet-filter-chain-default_fwd',
326
            content: %r{^\}$},
327
            order:   '99',
328
          )
329
        }
246 330
      end
247 331
    end
248 332
  end
spec/classes/ip_nat_spec.rb
9 9

  
10 10
      it { is_expected.to compile }
11 11

  
12
      it { is_expected.to contain_file('/etc/nftables/puppet/ip-nat.nft').with(
13
        :ensure => 'file',
14
        :owner  => 'root',
15
        :group  => 'root',
16
        :mode   => '0640',
17
      )}
12
      it {
13
        is_expected.to contain_file('/etc/nftables/puppet/ip-nat.nft').with(
14
          ensure: 'file',
15
          owner:  'root',
16
          group:  'root',
17
          mode:   '0640',
18
        )
19
      }
18 20

  
19 21
      context 'chain prerouting' do
20
        it { is_expected.to contain_concat('nftables-ip-nat-chain-PREROUTING').with(
21
          :path           => '/etc/nftables/puppet/ip-nat-chain-PREROUTING.nft',
22
          :owner          => 'root',
23
          :group          => 'root',
24
          :mode           => '0640',
25
          :ensure_newline => true,
26
        )}
27
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-header').with(
28
          :target  => 'nftables-ip-nat-chain-PREROUTING',
29
          :content => /^chain PREROUTING {$/,
30
          :order   => '00',
31
        )}
32
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-type').with(
33
          :target  => 'nftables-ip-nat-chain-PREROUTING',
34
          :content => /^  type nat hook prerouting priority -100$/,
35
          :order   => '01',
36
        )}
37
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-policy').with(
38
          :target  => 'nftables-ip-nat-chain-PREROUTING',
39
          :content => /^  policy accept$/,
40
          :order   => '02',
41
        )}
42
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-footer').with(
43
          :target  => 'nftables-ip-nat-chain-PREROUTING',
44
          :content => /^}$/,
45
          :order   => '99',
46
        )}
22
        it {
23
          is_expected.to contain_concat('nftables-ip-nat-chain-PREROUTING').with(
24
            path:           '/etc/nftables/puppet/ip-nat-chain-PREROUTING.nft',
25
            owner:          'root',
26
            group:          'root',
27
            mode:           '0640',
28
            ensure_newline: true,
29
          )
30
        }
31
        it {
32
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-header').with(
33
            target:  'nftables-ip-nat-chain-PREROUTING',
34
            content: %r{^chain PREROUTING \{$},
35
            order:   '00',
36
          )
37
        }
38
        it {
39
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-type').with(
40
            target:  'nftables-ip-nat-chain-PREROUTING',
41
            content: %r{^  type nat hook prerouting priority -100$},
42
            order:   '01',
43
          )
44
        }
45
        it {
46
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-policy').with(
47
            target:  'nftables-ip-nat-chain-PREROUTING',
48
            content: %r{^  policy accept$},
49
            order:   '02',
50
          )
51
        }
52
        it {
53
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-footer').with(
54
            target:  'nftables-ip-nat-chain-PREROUTING',
55
            content: %r{^\}$},
56
            order:   '99',
57
          )
58
        }
47 59
      end
48 60

  
49 61
      context 'chain output' do
50
        it { is_expected.to contain_concat('nftables-ip-nat-chain-POSTROUTING').with(
51
          :path           => '/etc/nftables/puppet/ip-nat-chain-POSTROUTING.nft',
52
          :owner          => 'root',
53
          :group          => 'root',
54
          :mode           => '0640',
55
          :ensure_newline => true,
56
        )}
57
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-header').with(
58
          :target  => 'nftables-ip-nat-chain-POSTROUTING',
59
          :content => /^chain POSTROUTING {$/,
60
          :order   => '00',
61
        )}
62
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-type').with(
63
          :target  => 'nftables-ip-nat-chain-POSTROUTING',
64
          :content => /^  type nat hook postrouting priority 100$/,
65
          :order   => '01',
66
        )}
67
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-policy').with(
68
          :target  => 'nftables-ip-nat-chain-POSTROUTING',
69
          :content => /^  policy accept$/,
70
          :order   => '02',
71
        )}
72
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-footer').with(
73
          :target  => 'nftables-ip-nat-chain-POSTROUTING',
74
          :content => /^}$/,
75
          :order   => '99',
76
        )}
62
        it {
63
          is_expected.to contain_concat('nftables-ip-nat-chain-POSTROUTING').with(
64
            path:           '/etc/nftables/puppet/ip-nat-chain-POSTROUTING.nft',
65
            owner:          'root',
66
            group:          'root',
67
            mode:           '0640',
68
            ensure_newline: true,
69
          )
70
        }
71
        it {
72
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-header').with(
73
            target:  'nftables-ip-nat-chain-POSTROUTING',
74
            content: %r{^chain POSTROUTING \{$},
75
            order:   '00',
76
          )
77
        }
78
        it {
79
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-type').with(
80
            target:  'nftables-ip-nat-chain-POSTROUTING',
81
            content: %r{^  type nat hook postrouting priority 100$},
82
            order:   '01',
83
          )
84
        }
85
        it {
86
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-policy').with(
87
            target:  'nftables-ip-nat-chain-POSTROUTING',
88
            content: %r{^  policy accept$},
89
            order:   '02',
90
          )
91
        }
92
        it {
93
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-footer').with(
94
            target:  'nftables-ip-nat-chain-POSTROUTING',
95
            content: %r{^\}$},
96
            order:   '99',
97
          )
98
        }
77 99
      end
78 100
    end
79 101
  end
spec/classes/masquerade_spec.rb
9 9

  
10 10
      context 'with masquerade' do
11 11
        let(:pre_condition) do
12
          """
12
          '
13 13
          nftables::rules::masquerade{
14
            'masquerade_eth0':
15
              oif => 'eth0';
16
            'masquerade_eth1_vpn':
17
              oif   => 'eth1',
18
              saddr => '192.0.2.0/24';
19
            'masquerade_ssh':
20
              saddr => '192.0.2.0/24',
21
              daddr => '198.51.100.2',
22
              proto => 'tcp',
23
              dport => '22';
24
            'masquerade_ssh_gitlab':
25
              saddr => '192.0.2.0/24',
26
              daddr => '198.51.100.2',
27
              dport => '22';
28
            'masquerade_wireguard':
29
              proto => 'udp',
30
              dport => '51820';
14
            \'masquerade_eth0\':
15
              oif => \'eth0\';
16
            \'masquerade_eth1_vpn\':
17
              oif   => \'eth1\',
18
              saddr => \'192.0.2.0/24\';
19
            \'masquerade_ssh\':
20
              saddr => \'192.0.2.0/24\',
21
              daddr => \'198.51.100.2\',
22
              proto => \'tcp\',
23
              dport => \'22\';
24
            \'masquerade_ssh_gitlab\':
25
              saddr => \'192.0.2.0/24\',
26
              daddr => \'198.51.100.2\',
27
              dport => \'22\';
28
            \'masquerade_wireguard\':
29
              proto => \'udp\',
30
              dport => \'51820\';
31 31
          }
32
          """
32
          '
33 33
        end
34 34

  
35 35
        it { is_expected.to compile }
36 36

  
37
        it { is_expected.to contain_concat('nftables-ip-nat-chain-POSTROUTING').with(
38
          :path           => '/etc/nftables/puppet/ip-nat-chain-POSTROUTING.nft',
39
          :owner          => 'root',
40
          :group          => 'root',
41
          :mode           => '0640',
42
          :ensure_newline => true,
43
        )}
44
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-header').with(
45
          :target  => 'nftables-ip-nat-chain-POSTROUTING',
46
          :content => /^chain POSTROUTING {$/,
47
          :order   => '00',
48
        )}
49
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-type').with(
50
          :target  => 'nftables-ip-nat-chain-POSTROUTING',
51
          :content => /^  type nat hook postrouting priority 100$/,
52
          :order   => '01',
53
        )}
54
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-policy').with(
55
          :target  => 'nftables-ip-nat-chain-POSTROUTING',
56
          :content => /^  policy accept$/,
57
          :order   => '02',
58
        )}
59
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-masquerade_eth0').with(
60
          :target  => 'nftables-ip-nat-chain-POSTROUTING',
61
          :content => /^  oifname eth0 masquerade$/,
62
          :order   => '70',
63
        )}
64
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-masquerade_eth1_vpn').with(
65
          :target  => 'nftables-ip-nat-chain-POSTROUTING',
66
          :content => /^  oifname eth1 ip saddr 192\.0\.2\.0\/24 masquerade$/,
67
          :order   => '70',
68
        )}
69
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-masquerade_ssh').with(
70
          :target  => 'nftables-ip-nat-chain-POSTROUTING',
71
          :content => /^  ip saddr 192\.0\.2\.0\/24 ip daddr 198.51.100.2 tcp dport 22 masquerade$/,
72
          :order   => '70',
73
        )}
74
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-masquerade_ssh_gitlab').with(
75
          :target  => 'nftables-ip-nat-chain-POSTROUTING',
76
          :content => /^  ip saddr 192\.0\.2\.0\/24 ip daddr 198.51.100.2 tcp dport 22 masquerade$/,
77
          :order   => '70',
78
        )}
79
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-masquerade_wireguard').with(
80
          :target  => 'nftables-ip-nat-chain-POSTROUTING',
81
          :content => /^  udp dport 51820 masquerade$/,
82
          :order   => '70',
83
        )}
84
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-footer').with(
85
          :target  => 'nftables-ip-nat-chain-POSTROUTING',
86
          :content => /^}$/,
87
          :order   => '99',
88
        )}
37
        it {
38
          is_expected.to contain_concat('nftables-ip-nat-chain-POSTROUTING').with(
39
            path:           '/etc/nftables/puppet/ip-nat-chain-POSTROUTING.nft',
40
            owner:          'root',
41
            group:          'root',
42
            mode:           '0640',
43
            ensure_newline: true,
44
          )
45
        }
46
        it {
47
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-header').with(
48
            target:  'nftables-ip-nat-chain-POSTROUTING',
49
            content: %r{^chain POSTROUTING \{$},
50
            order:   '00',
51
          )
52
        }
53
        it {
54
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-type').with(
55
            target:  'nftables-ip-nat-chain-POSTROUTING',
56
            content: %r{^  type nat hook postrouting priority 100$},
57
            order:   '01',
58
          )
59
        }
60
        it {
61
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-policy').with(
62
            target:  'nftables-ip-nat-chain-POSTROUTING',
63
            content: %r{^  policy accept$},
64
            order:   '02',
65
          )
66
        }
67
        it {
68
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-masquerade_eth0').with(
69
            target:  'nftables-ip-nat-chain-POSTROUTING',
70
            content: %r{^  oifname eth0 masquerade$},
71
            order:   '70',
72
          )
73
        }
74
        it {
75
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-masquerade_eth1_vpn').with(
76
            target:  'nftables-ip-nat-chain-POSTROUTING',
77
            content: %r{^  oifname eth1 ip saddr 192\.0\.2\.0\/24 masquerade$},
78
            order:   '70',
79
          )
80
        }
81
        it {
82
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-masquerade_ssh').with(
83
            target:  'nftables-ip-nat-chain-POSTROUTING',
84
            content: %r{^  ip saddr 192\.0\.2\.0\/24 ip daddr 198.51.100.2 tcp dport 22 masquerade$},
85
            order:   '70',
86
          )
87
        }
88
        it {
89
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-masquerade_ssh_gitlab').with(
90
            target:  'nftables-ip-nat-chain-POSTROUTING',
91
            content: %r{^  ip saddr 192\.0\.2\.0\/24 ip daddr 198.51.100.2 tcp dport 22 masquerade$},
92
            order:   '70',
93
          )
94
        }
95
        it {
96
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-masquerade_wireguard').with(
97
            target:  'nftables-ip-nat-chain-POSTROUTING',
98
            content: %r{^  udp dport 51820 masquerade$},
99
            order:   '70',
100
          )
101
        }
102
        it {
103
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-footer').with(
104
            target:  'nftables-ip-nat-chain-POSTROUTING',
105
            content: %r{^\}$},
106
            order:   '99',
107
          )
108
        }
89 109
      end
90 110
    end
91 111
  end
spec/classes/nftables_spec.rb
11 11

  
12 12
      it { is_expected.to contain_package('nftables') }
13 13

  
14
      it { is_expected.to contain_file('/etc/nftables/puppet.nft').with(
15
        :ensure => 'file',
16
        :owner  => 'root',
17
        :group  => 'root',
18
        :mode   => '0640',
19
        :source => 'puppet:///modules/nftables/config/puppet.nft',
20
      )}
21

  
22
      it { is_expected.to contain_file('/etc/nftables/puppet').with(
23
        :ensure  => 'directory',
24
        :owner   => 'root',
25
        :group   => 'root',
26
        :mode    => '0750',
27
        :purge   => true,
28
        :force   => true,
29
        :recurse => true,
30
      )}
31

  
32
      it { is_expected.to contain_service('nftables').with(
33
        :ensure => 'running',
34
        :enable => true,
35
      )}
36

  
37
      it { is_expected.to contain_service('firewalld').with(
38
        :ensure => 'stopped',
39
        :enable => 'mask',
40
      )}
14
      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
          source: 'puppet:///modules/nftables/config/puppet.nft',
21
        )
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
        is_expected.to contain_service('nftables').with(
38
          ensure: 'running',
39
          enable: true,
40
        )
41
      }
42

  
43
      it {
44
        is_expected.to contain_service('firewalld').with(
45
          ensure: 'stopped',
46
          enable: 'mask',
47
        )
48
      }
41 49
    end
42 50
  end
43 51
end
spec/classes/router_spec.rb
9 9

  
10 10
      context 'as router' do
11 11
        let(:pre_condition) do
12
          """
12
          '
13 13
          # inet-filter-chain-default_fwd
14 14
          nftables::rule{
15
            'default_fwd-out':
16
              order   => '20',
17
              content => 'iifname eth1 oifname eth0 accept';
18
            'default_fwd-drop':
19
              order   => '90',
20
              content => 'iifname eth0 drop';
15
            \'default_fwd-out\':
16
              order   => \'20\',
17
              content => \'iifname eth1 oifname eth0 accept\';
18
            \'default_fwd-drop\':
19
              order   => \'90\',
20
              content => \'iifname eth0 drop\';
21 21
          }
22 22

  
23 23
          nftables::rules::masquerade{
24
            'masquerade':
25
              order => '20',
26
              oif   => 'eth0';
24
            \'masquerade\':
25
              order => \'20\',
26
              oif   => \'eth0\';
27 27
          }
28
          """
28
          '
29 29
        end
30 30

  
31 31
        it { is_expected.to compile }
32 32

  
33
        it { is_expected.to contain_concat('nftables-inet-filter-chain-default_fwd').with(
34
          :path           => '/etc/nftables/puppet/inet-filter-chain-default_fwd.nft',
35
          :owner          => 'root',
36
          :group          => 'root',
37
          :mode           => '0640',
38
          :ensure_newline => true,
39
        )}
40
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-header').with(
41
          :target  => 'nftables-inet-filter-chain-default_fwd',
42
          :content => /^chain default_fwd {$/,
43
          :order   => '00',
44
        )}
45
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-rule-out').with(
46
          :target  => 'nftables-inet-filter-chain-default_fwd',
47
          :content => /^  iifname eth1 oifname eth0 accept$/,
48
          :order   => '20',
49
        )}
50
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-rule-drop').with(
51
          :target  => 'nftables-inet-filter-chain-default_fwd',
52
          :content => /^  iifname eth0 drop$/,
53
          :order   => '90',
54
        )}
55
        it { is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-footer').with(
56
          :target  => 'nftables-inet-filter-chain-default_fwd',
57
          :content => /^}$/,
58
          :order   => '99',
59
        )}
33
        it {
34
          is_expected.to contain_concat('nftables-inet-filter-chain-default_fwd').with(
35
            path:           '/etc/nftables/puppet/inet-filter-chain-default_fwd.nft',
36
            owner:          'root',
37
            group:          'root',
38
            mode:           '0640',
39
            ensure_newline: true,
40
          )
41
        }
42
        it {
43
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-header').with(
44
            target:  'nftables-inet-filter-chain-default_fwd',
45
            content: %r{^chain default_fwd \{$},
46
            order:   '00',
47
          )
48
        }
49
        it {
50
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-rule-out').with(
51
            target:  'nftables-inet-filter-chain-default_fwd',
52
            content: %r{^  iifname eth1 oifname eth0 accept$},
53
            order:   '20',
54
          )
55
        }
56
        it {
57
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-rule-drop').with(
58
            target:  'nftables-inet-filter-chain-default_fwd',
59
            content: %r{^  iifname eth0 drop$},
60
            order:   '90',
61
          )
62
        }
63
        it {
64
          is_expected.to contain_concat__fragment('nftables-inet-filter-chain-default_fwd-footer').with(
65
            target:  'nftables-inet-filter-chain-default_fwd',
66
            content: %r{^\}$},
67
            order:   '99',
68
          )
69
        }
60 70

  
61
        it { is_expected.to contain_concat('nftables-ip-nat-chain-PREROUTING').with(
62
          :path           => '/etc/nftables/puppet/ip-nat-chain-PREROUTING.nft',
63
          :owner          => 'root',
64
          :group          => 'root',
65
          :mode           => '0640',
66
          :ensure_newline => true,
67
        )}
68
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-header').with(
69
          :target  => 'nftables-ip-nat-chain-PREROUTING',
70
          :content => /^chain PREROUTING {$/,
71
          :order   => '00',
72
        )}
73
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-type').with(
74
          :target  => 'nftables-ip-nat-chain-PREROUTING',
75
          :content => /^  type nat hook prerouting priority -100$/,
76
          :order   => '01',
77
        )}
78
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-policy').with(
79
          :target  => 'nftables-ip-nat-chain-PREROUTING',
80
          :content => /^  policy accept$/,
81
          :order   => '02',
82
        )}
83
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-footer').with(
84
          :target  => 'nftables-ip-nat-chain-PREROUTING',
85
          :content => /^}$/,
86
          :order   => '99',
87
        )}
71
        it {
72
          is_expected.to contain_concat('nftables-ip-nat-chain-PREROUTING').with(
73
            path:           '/etc/nftables/puppet/ip-nat-chain-PREROUTING.nft',
74
            owner:          'root',
75
            group:          'root',
76
            mode:           '0640',
77
            ensure_newline: true,
78
          )
79
        }
80
        it {
81
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-header').with(
82
            target:  'nftables-ip-nat-chain-PREROUTING',
83
            content: %r{^chain PREROUTING \{$},
84
            order:   '00',
85
          )
86
        }
87
        it {
88
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-type').with(
89
            target:  'nftables-ip-nat-chain-PREROUTING',
90
            content: %r{^  type nat hook prerouting priority -100$},
91
            order:   '01',
92
          )
93
        }
94
        it {
95
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-rule-policy').with(
96
            target:  'nftables-ip-nat-chain-PREROUTING',
97
            content: %r{^  policy accept$},
98
            order:   '02',
99
          )
100
        }
101
        it {
102
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-PREROUTING-footer').with(
103
            target:  'nftables-ip-nat-chain-PREROUTING',
104
            content: %r{^\}$},
105
            order:   '99',
106
          )
107
        }
88 108

  
89
        it { is_expected.to contain_concat('nftables-ip-nat-chain-POSTROUTING').with(
90
          :path           => '/etc/nftables/puppet/ip-nat-chain-POSTROUTING.nft',
91
          :owner          => 'root',
92
          :group          => 'root',
93
          :mode           => '0640',
94
          :ensure_newline => true,
95
        )}
96
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-header').with(
97
          :target  => 'nftables-ip-nat-chain-POSTROUTING',
98
          :content => /^chain POSTROUTING {$/,
99
          :order   => '00',
100
        )}
101
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-type').with(
102
          :target  => 'nftables-ip-nat-chain-POSTROUTING',
103
          :content => /^  type nat hook postrouting priority 100$/,
104
          :order   => '01',
105
        )}
106
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-policy').with(
107
          :target  => 'nftables-ip-nat-chain-POSTROUTING',
108
          :content => /^  policy accept$/,
109
          :order   => '02',
110
        )}
111
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-rule-masquerade').with(
112
          :target  => 'nftables-ip-nat-chain-POSTROUTING',
113
          :content => /^  oifname eth0 masquerade$/,
114
          :order   => '20',
115
        )}
116
        it { is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-footer').with(
117
          :target  => 'nftables-ip-nat-chain-POSTROUTING',
118
          :content => /^}$/,
119
          :order   => '99',
120
        )}
109
        it {
110
          is_expected.to contain_concat('nftables-ip-nat-chain-POSTROUTING').with(
111
            path:           '/etc/nftables/puppet/ip-nat-chain-POSTROUTING.nft',
112
            owner:          'root',
113
            group:          'root',
114
            mode:           '0640',
115
            ensure_newline: true,
116
          )
117
        }
118
        it {
119
          is_expected.to contain_concat__fragment('nftables-ip-nat-chain-POSTROUTING-header').with(
120
            target:  'nftables-ip-nat-chain-POSTROUTING',
... Ce différentiel a été tronqué car il excède la taille maximale pouvant être affichée.

Formats disponibles : Unified diff