root / spec / classes / rules / docker_ce_spec.rb @ fa92e118
Historique | Voir | Annoter | Télécharger (6,88 ko)
1 | 6be2adf7 | Luis Fernández Álvarez | 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 | fcb79d73 | Ben Morrice | let(:pre_condition) { 'include nftables' } |
10 | 6be2adf7 | Luis Fernández Álvarez | |
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 | fa92e118 | Romain Tartière | table: 'ip-nat' |
21 | 6be2adf7 | Luis Fernández Álvarez | ) |
22 | } |
||
23 | it { |
||
24 | is_expected.to contain_nftables__chain('OUTPUT-nat').with(
|
||
25 | chain: 'OUTPUT', |
||
26 | fa92e118 | Romain Tartière | table: 'ip-nat' |
27 | 6be2adf7 | Luis Fernández Álvarez | ) |
28 | } |
||
29 | it { |
||
30 | is_expected.to contain_nftables__chain('INPUT-nat').with(
|
||
31 | chain: 'INPUT', |
||
32 | fa92e118 | Romain Tartière | table: 'ip-nat' |
33 | 6be2adf7 | Luis Fernández Álvarez | ) |
34 | } |
||
35 | c3515492 | Luis Fernández Álvarez | 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 | 6be2adf7 | Luis Fernández Álvarez | it { is_expected.to contain_nftables__rule('DOCKER_ISOLATION_STAGE_2-drop').with_content('oifname "docker0" counter drop') } |
38 | c3515492 | Luis Fernández Álvarez | 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 | 6be2adf7 | Luis Fernández Álvarez | 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 | fa92e118 | Romain Tartière | table: 'ip-nat' |
51 | 6be2adf7 | Luis Fernández Álvarez | ) |
52 | } |
||
53 | c3515492 | Luis Fernández Álvarez | it { |
54 | is_expected.to contain_nftables__rule('PREROUTING-docker').with(
|
||
55 | content: 'fib daddr type local counter jump DOCKER', |
||
56 | fa92e118 | Romain Tartière | table: 'ip-nat' |
57 | c3515492 | Luis Fernández Álvarez | ) |
58 | } |
||
59 | it { |
||
60 | is_expected.to contain_nftables__rule('OUTPUT-jump_docker@ip-nat').with(
|
||
61 | b61ccb4a | Luis Fernández Álvarez | rulename: 'OUTPUT-jump_docker', |
62 | c3515492 | Luis Fernández Álvarez | content: 'ip daddr != 127.0.0.0/8 fib daddr type local counter jump DOCKER', |
63 | fa92e118 | Romain Tartière | table: 'ip-nat' |
64 | c3515492 | Luis Fernández Álvarez | ) |
65 | } |
||
66 | it { |
||
67 | is_expected.to contain_nftables__rule('DOCKER-counter').with(
|
||
68 | content: 'iifname "docker0" counter return', |
||
69 | fa92e118 | Romain Tartière | table: 'ip-nat' |
70 | c3515492 | Luis Fernández Álvarez | ) |
71 | } |
||
72 | it { |
||
73 | is_expected.to contain_nftables__rule('INPUT-type@ip-nat').with(
|
||
74 | 283e1c3c | Luis Fernández Álvarez | rulename: 'INPUT-type', |
75 | c3515492 | Luis Fernández Álvarez | content: 'type nat hook input priority 100', |
76 | fa92e118 | Romain Tartière | table: 'ip-nat' |
77 | c3515492 | Luis Fernández Álvarez | ) |
78 | } |
||
79 | it { |
||
80 | is_expected.to contain_nftables__rule('INPUT-policy@ip-nat').with(
|
||
81 | 283e1c3c | Luis Fernández Álvarez | rulename: 'INPUT-policy', |
82 | c3515492 | Luis Fernández Álvarez | content: 'policy accept', |
83 | fa92e118 | Romain Tartière | table: 'ip-nat' |
84 | c3515492 | Luis Fernández Álvarez | ) |
85 | } |
||
86 | 6be2adf7 | Luis Fernández Álvarez | end
|
87 | |||
88 | 1bf717d9 | Luis Fernández Álvarez | 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 | 6be2adf7 | Luis Fernández Álvarez | 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 | c3515492 | Luis Fernández Álvarez | 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 | 6be2adf7 | Luis Fernández Álvarez | it { is_expected.to contain_nftables__rule('DOCKER_ISOLATION_STAGE_2-drop').with_content('oifname "ifdo0" counter drop') } |
137 | c3515492 | Luis Fernández Álvarez | 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 | 6be2adf7 | Luis Fernández Álvarez | 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 | fa92e118 | Romain Tartière | table: 'ip-nat' |
146 | 6be2adf7 | Luis Fernández Álvarez | ) |
147 | } |
||
148 | c3515492 | Luis Fernández Álvarez | it { |
149 | is_expected.to contain_nftables__rule('DOCKER-counter').with(
|
||
150 | content: 'iifname "ifdo0" counter return', |
||
151 | fa92e118 | Romain Tartière | table: 'ip-nat' |
152 | c3515492 | Luis Fernández Álvarez | ) |
153 | } |
||
154 | 6be2adf7 | Luis Fernández Álvarez | end
|
155 | end
|
||
156 | end
|
||
157 | c3515492 | Luis Fernández Álvarez | end |