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