Projet

Général

Profil

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

root / spec / classes / rules / docker_ce_spec.rb @ 925c358d

Historique | Voir | Annoter | Télécharger (6,97 ko)

1
# frozen_string_literal: true
2

    
3
require 'spec_helper'
4

    
5
describe 'nftables::rules::docker_ce' do
6
  let(:pre_condition) { 'include nftables' }
7

    
8
  on_supported_os.each do |os, os_facts|
9
    context "on #{os}" do
10
      let(:facts) { os_facts }
11
      let(:pre_condition) { 'include nftables' }
12

    
13
      context 'default options' do
14
        it { is_expected.to compile }
15
        it { is_expected.to contain_nftables__chain('DOCKER') }
16
        it { is_expected.to contain_nftables__chain('DOCKER_ISOLATION_STAGE_1') }
17
        it { is_expected.to contain_nftables__chain('DOCKER_ISOLATION_STAGE_2') }
18
        it { is_expected.to contain_nftables__chain('DOCKER_USER') }
19

    
20
        it {
21
          expect(subject).to contain_nftables__chain('DOCKER-nat').with(
22
            chain: 'DOCKER',
23
            table: 'ip-nat'
24
          )
25
        }
26

    
27
        it {
28
          expect(subject).to contain_nftables__chain('OUTPUT-nat').with(
29
            chain: 'OUTPUT',
30
            table: 'ip-nat'
31
          )
32
        }
33

    
34
        it {
35
          expect(subject).to contain_nftables__chain('INPUT-nat').with(
36
            chain: 'INPUT',
37
            table: 'ip-nat'
38
          )
39
        }
40

    
41
        it { is_expected.to contain_nftables__rule('DOCKER_ISOLATION_STAGE_1-iifname').with_content('iifname "docker0" oifname != "docker0" counter jump DOCKER_ISOLATION_STAGE_2') }
42
        it { is_expected.to contain_nftables__rule('DOCKER_ISOLATION_STAGE_1-counter').with_content('counter return') }
43
        it { is_expected.to contain_nftables__rule('DOCKER_ISOLATION_STAGE_2-drop').with_content('oifname "docker0" counter drop') }
44
        it { is_expected.to contain_nftables__rule('DOCKER_ISOLATION_STAGE_2-counter').with_content('counter return') }
45
        it { is_expected.to contain_nftables__rule('DOCKER_USER-counter').with_content('counter return') }
46
        it { is_expected.to contain_nftables__rule('default_fwd-jump_docker_user').with_content('counter jump DOCKER_USER') }
47
        it { is_expected.to contain_nftables__rule('default_fwd-jump_docker_isolation_stage_1').with_content('counter jump DOCKER_ISOLATION_STAGE_1') }
48
        it { is_expected.to contain_nftables__rule('default_fwd-out_docker_accept').with_content('oifname "docker0" ct state established,related counter accept') }
49
        it { is_expected.to contain_nftables__rule('default_fwd-jump_docker').with_content('oifname "docker0" counter jump DOCKER') }
50
        it { is_expected.to contain_nftables__rule('default_fwd-idocker_onot_accept').with_content('iifname "docker0" oifname != "docker0" counter accept') }
51
        it { is_expected.to contain_nftables__rule('default_fwd-idocker_odocker_accept').with_content('iifname "docker0" oifname "docker0" counter accept') }
52

    
53
        it {
54
          expect(subject).to contain_nftables__rule('POSTROUTING-docker').with(
55
            content: 'oifname != "docker0" ip saddr 172.17.0.0/16 counter masquerade',
56
            table: 'ip-nat'
57
          )
58
        }
59

    
60
        it {
61
          expect(subject).to contain_nftables__rule('PREROUTING-docker').with(
62
            content: 'fib daddr type local counter jump DOCKER',
63
            table: 'ip-nat'
64
          )
65
        }
66

    
67
        it {
68
          expect(subject).to contain_nftables__rule('OUTPUT-jump_docker@ip-nat').with(
69
            rulename: 'OUTPUT-jump_docker',
70
            content: 'ip daddr != 127.0.0.0/8 fib daddr type local counter jump DOCKER',
71
            table: 'ip-nat'
72
          )
73
        }
74

    
75
        it {
76
          expect(subject).to contain_nftables__rule('DOCKER-counter').with(
77
            content: 'iifname "docker0" counter return',
78
            table: 'ip-nat'
79
          )
80
        }
81

    
82
        it {
83
          expect(subject).to contain_nftables__rule('INPUT-type@ip-nat').with(
84
            rulename: 'INPUT-type',
85
            content: 'type nat hook input priority 100',
86
            table: 'ip-nat'
87
          )
88
        }
89

    
90
        it {
91
          expect(subject).to contain_nftables__rule('INPUT-policy@ip-nat').with(
92
            rulename: 'INPUT-policy',
93
            content: 'policy accept',
94
            table: 'ip-nat'
95
          )
96
        }
97
      end
98

    
99
      context 'with base chain management false' do
100
        let(:params) do
101
          {
102
            manage_base_chains: false,
103
          }
104
        end
105

    
106
        it { is_expected.to compile }
107

    
108
        it { is_expected.to contain_nftables__chain('DOCKER') }
109
        it { is_expected.to contain_nftables__chain('DOCKER_ISOLATION_STAGE_1') }
110
        it { is_expected.to contain_nftables__chain('DOCKER_ISOLATION_STAGE_2') }
111
        it { is_expected.to contain_nftables__chain('DOCKER_USER') }
112
        it { is_expected.to contain_nftables__chain('DOCKER-nat') }
113

    
114
        it { is_expected.not_to contain_nftables__chain('OUTPUT-nat') }
115
        it { is_expected.not_to contain_nftables__chain('INPUT-nat') }
116
      end
117

    
118
      context 'with docker chain management false' do
119
        let(:params) do
120
          {
121
            manage_docker_chains: false,
122
          }
123
        end
124

    
125
        it { is_expected.to compile }
126

    
127
        it { is_expected.not_to contain_nftables__chain('DOCKER') }
128
        it { is_expected.not_to contain_nftables__chain('DOCKER_ISOLATION_STAGE_1') }
129
        it { is_expected.not_to contain_nftables__chain('DOCKER_ISOLATION_STAGE_2') }
130
        it { is_expected.not_to contain_nftables__chain('DOCKER_USER') }
131
        it { is_expected.not_to contain_nftables__chain('DOCKER-nat') }
132

    
133
        it { is_expected.to contain_nftables__chain('OUTPUT-nat') }
134
        it { is_expected.to contain_nftables__chain('INPUT-nat') }
135
      end
136

    
137
      context 'with custom interface and subnet' do
138
        let(:params) do
139
          {
140
            docker_interface: 'ifdo0',
141
            docker_prefix: '192.168.4.0/24',
142
          }
143
        end
144

    
145
        it { is_expected.to compile }
146
        it { is_expected.to contain_nftables__rule('DOCKER_ISOLATION_STAGE_1-iifname').with_content('iifname "ifdo0" oifname != "ifdo0" counter jump DOCKER_ISOLATION_STAGE_2') }
147
        it { is_expected.to contain_nftables__rule('DOCKER_ISOLATION_STAGE_2-drop').with_content('oifname "ifdo0" counter drop') }
148
        it { is_expected.to contain_nftables__rule('default_fwd-out_docker_accept').with_content('oifname "ifdo0" ct state established,related counter accept') }
149
        it { is_expected.to contain_nftables__rule('default_fwd-jump_docker').with_content('oifname "ifdo0" counter jump DOCKER') }
150
        it { is_expected.to contain_nftables__rule('default_fwd-idocker_onot_accept').with_content('iifname "ifdo0" oifname != "ifdo0" counter accept') }
151
        it { is_expected.to contain_nftables__rule('default_fwd-idocker_odocker_accept').with_content('iifname "ifdo0" oifname "ifdo0" counter accept') }
152

    
153
        it {
154
          expect(subject).to contain_nftables__rule('POSTROUTING-docker').with(
155
            content: 'oifname != "ifdo0" ip saddr 192.168.4.0/24 counter masquerade',
156
            table: 'ip-nat'
157
          )
158
        }
159

    
160
        it {
161
          expect(subject).to contain_nftables__rule('DOCKER-counter').with(
162
            content: 'iifname "ifdo0" counter return',
163
            table: 'ip-nat'
164
          )
165
        }
166
      end
167
    end
168
  end
169
end