root / spec / classes / rules / docker_ce_spec.rb @ c94658e1
Historique | Voir | Annoter | Télécharger (6,85 ko)
1 |
require 'spec_helper'
|
---|---|
2 |
|
3 |
describe 'nftables::rules::docker_ce' do |
4 |
let(:pre_condition) { 'include nftables' } |
5 |
|
6 |
on_supported_os.each do |os, os_facts|
|
7 |
context "on #{os}" do |
8 |
let(:facts) { os_facts }
|
9 |
|
10 |
context 'default options' do |
11 |
it { is_expected.to compile } |
12 |
it { is_expected.to contain_nftables__chain('DOCKER') }
|
13 |
it { is_expected.to contain_nftables__chain('DOCKER_ISOLATION_STAGE_1') }
|
14 |
it { is_expected.to contain_nftables__chain('DOCKER_ISOLATION_STAGE_2') }
|
15 |
it { is_expected.to contain_nftables__chain('DOCKER_USER') }
|
16 |
it { |
17 |
is_expected.to contain_nftables__chain('DOCKER-nat').with(
|
18 |
chain: 'DOCKER', |
19 |
table: 'ip-nat', |
20 |
) |
21 |
} |
22 |
it { |
23 |
is_expected.to contain_nftables__chain('OUTPUT-nat').with(
|
24 |
chain: 'OUTPUT', |
25 |
table: 'ip-nat', |
26 |
) |
27 |
} |
28 |
it { |
29 |
is_expected.to contain_nftables__chain('INPUT-nat').with(
|
30 |
chain: 'INPUT', |
31 |
table: 'ip-nat', |
32 |
) |
33 |
} |
34 |
it { is_expected.to contain_nftables__rule('DOCKER_ISOLATION_STAGE_1-iifname').with_content('iifname "docker0" oifname != "docker0" counter jump DOCKER_ISOLATION_STAGE_2') } |
35 |
it { is_expected.to contain_nftables__rule('DOCKER_ISOLATION_STAGE_1-counter').with_content('counter return') } |
36 |
it { is_expected.to contain_nftables__rule('DOCKER_ISOLATION_STAGE_2-drop').with_content('oifname "docker0" counter drop') } |
37 |
it { is_expected.to contain_nftables__rule('DOCKER_ISOLATION_STAGE_2-counter').with_content('counter return') } |
38 |
it { is_expected.to contain_nftables__rule('DOCKER_USER-counter').with_content('counter return') } |
39 |
it { is_expected.to contain_nftables__rule('default_fwd-jump_docker_user').with_content('counter jump DOCKER_USER') } |
40 |
it { is_expected.to contain_nftables__rule('default_fwd-jump_docker_isolation_stage_1').with_content('counter jump DOCKER_ISOLATION_STAGE_1') } |
41 |
it { is_expected.to contain_nftables__rule('default_fwd-out_docker_accept').with_content('oifname "docker0" ct state established,related counter accept') } |
42 |
it { is_expected.to contain_nftables__rule('default_fwd-jump_docker').with_content('oifname "docker0" counter jump DOCKER') } |
43 |
it { is_expected.to contain_nftables__rule('default_fwd-idocker_onot_accept').with_content('iifname "docker0" oifname != "docker0" counter accept') } |
44 |
it { is_expected.to contain_nftables__rule('default_fwd-idocker_odocker_accept').with_content('iifname "docker0" oifname "docker0" counter accept') } |
45 |
|
46 |
it { |
47 |
is_expected.to contain_nftables__rule('POSTROUTING-docker').with(
|
48 |
content: 'oifname != "docker0" ip saddr 172.17.0.0/16 counter masquerade', |
49 |
table: 'ip-nat', |
50 |
) |
51 |
} |
52 |
it { |
53 |
is_expected.to contain_nftables__rule('PREROUTING-docker').with(
|
54 |
content: 'fib daddr type local counter jump DOCKER', |
55 |
table: 'ip-nat', |
56 |
) |
57 |
} |
58 |
it { |
59 |
is_expected.to contain_nftables__rule('OUTPUT-jump_docker@ip-nat').with(
|
60 |
rulename: 'OUTPUT-jump_docker', |
61 |
content: 'ip daddr != 127.0.0.0/8 fib daddr type local counter jump DOCKER', |
62 |
table: 'ip-nat', |
63 |
) |
64 |
} |
65 |
it { |
66 |
is_expected.to contain_nftables__rule('DOCKER-counter').with(
|
67 |
content: 'iifname "docker0" counter return', |
68 |
table: 'ip-nat', |
69 |
) |
70 |
} |
71 |
it { |
72 |
is_expected.to contain_nftables__rule('INPUT-type@ip-nat').with(
|
73 |
rulename: 'INPUT-type', |
74 |
content: 'type nat hook input priority 100', |
75 |
table: 'ip-nat', |
76 |
) |
77 |
} |
78 |
it { |
79 |
is_expected.to contain_nftables__rule('INPUT-policy@ip-nat').with(
|
80 |
rulename: 'INPUT-policy', |
81 |
content: 'policy accept', |
82 |
table: 'ip-nat', |
83 |
) |
84 |
} |
85 |
end
|
86 |
|
87 |
context 'with base chain management false' do |
88 |
let(:params) do |
89 |
{ |
90 |
manage_base_chains: false, |
91 |
} |
92 |
end
|
93 |
|
94 |
it { is_expected.to compile } |
95 |
|
96 |
it { is_expected.to contain_nftables__chain('DOCKER') }
|
97 |
it { is_expected.to contain_nftables__chain('DOCKER_ISOLATION_STAGE_1') }
|
98 |
it { is_expected.to contain_nftables__chain('DOCKER_ISOLATION_STAGE_2') }
|
99 |
it { is_expected.to contain_nftables__chain('DOCKER_USER') }
|
100 |
it { is_expected.to contain_nftables__chain('DOCKER-nat') }
|
101 |
|
102 |
it { is_expected.not_to contain_nftables__chain('OUTPUT-nat') }
|
103 |
it { is_expected.not_to contain_nftables__chain('INPUT-nat') }
|
104 |
end
|
105 |
|
106 |
context 'with docker chain management false' do |
107 |
let(:params) do |
108 |
{ |
109 |
manage_docker_chains: false, |
110 |
} |
111 |
end
|
112 |
|
113 |
it { is_expected.to compile } |
114 |
|
115 |
it { is_expected.not_to contain_nftables__chain('DOCKER') }
|
116 |
it { is_expected.not_to contain_nftables__chain('DOCKER_ISOLATION_STAGE_1') }
|
117 |
it { is_expected.not_to contain_nftables__chain('DOCKER_ISOLATION_STAGE_2') }
|
118 |
it { is_expected.not_to contain_nftables__chain('DOCKER_USER') }
|
119 |
it { is_expected.not_to contain_nftables__chain('DOCKER-nat') }
|
120 |
|
121 |
it { is_expected.to contain_nftables__chain('OUTPUT-nat') }
|
122 |
it { is_expected.to contain_nftables__chain('INPUT-nat') }
|
123 |
end
|
124 |
|
125 |
context 'with custom interface and subnet' do |
126 |
let(:params) do |
127 |
{ |
128 |
docker_interface: 'ifdo0', |
129 |
docker_prefix: '192.168.4.0/24', |
130 |
} |
131 |
end
|
132 |
|
133 |
it { is_expected.to compile } |
134 |
it { is_expected.to contain_nftables__rule('DOCKER_ISOLATION_STAGE_1-iifname').with_content('iifname "ifdo0" oifname != "ifdo0" counter jump DOCKER_ISOLATION_STAGE_2') } |
135 |
it { is_expected.to contain_nftables__rule('DOCKER_ISOLATION_STAGE_2-drop').with_content('oifname "ifdo0" counter drop') } |
136 |
it { is_expected.to contain_nftables__rule('default_fwd-out_docker_accept').with_content('oifname "ifdo0" ct state established,related counter accept') } |
137 |
it { is_expected.to contain_nftables__rule('default_fwd-jump_docker').with_content('oifname "ifdo0" counter jump DOCKER') } |
138 |
it { is_expected.to contain_nftables__rule('default_fwd-idocker_onot_accept').with_content('iifname "ifdo0" oifname != "ifdo0" counter accept') } |
139 |
it { is_expected.to contain_nftables__rule('default_fwd-idocker_odocker_accept').with_content('iifname "ifdo0" oifname "ifdo0" counter accept') } |
140 |
|
141 |
it { |
142 |
is_expected.to contain_nftables__rule('POSTROUTING-docker').with(
|
143 |
content: 'oifname != "ifdo0" ip saddr 192.168.4.0/24 counter masquerade', |
144 |
table: 'ip-nat', |
145 |
) |
146 |
} |
147 |
it { |
148 |
is_expected.to contain_nftables__rule('DOCKER-counter').with(
|
149 |
content: 'iifname "ifdo0" counter return', |
150 |
table: 'ip-nat', |
151 |
) |
152 |
} |
153 |
end
|
154 |
end
|
155 |
end
|
156 |
end
|