root / spec / classes / rules / docker_ce_spec.rb @ 7b9d6ffc
Historique | Voir | Annoter | Télécharger (6,85 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 | |||
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 | 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') } |
35 | it { is_expected.to contain_nftables__rule('DOCKER_ISOLATION_STAGE_1-counter').with_content('counter return') } |
||
36 | 6be2adf7 | Luis Fernández Álvarez | it { is_expected.to contain_nftables__rule('DOCKER_ISOLATION_STAGE_2-drop').with_content('oifname "docker0" counter drop') } |
37 | c3515492 | Luis Fernández Álvarez | 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 | 6be2adf7 | Luis Fernández Álvarez | 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 | c3515492 | Luis Fernández Álvarez | 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 | b61ccb4a | Luis Fernández Álvarez | rulename: 'OUTPUT-jump_docker', |
61 | c3515492 | Luis Fernández Álvarez | 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 | 283e1c3c | Luis Fernández Álvarez | rulename: 'INPUT-type', |
74 | c3515492 | Luis Fernández Álvarez | 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 | 283e1c3c | Luis Fernández Álvarez | rulename: 'INPUT-policy', |
81 | c3515492 | Luis Fernández Álvarez | content: 'policy accept', |
82 | table: 'ip-nat', |
||
83 | ) |
||
84 | } |
||
85 | 6be2adf7 | Luis Fernández Álvarez | end
|
86 | |||
87 | 1bf717d9 | Luis Fernández Álvarez | 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 | 6be2adf7 | Luis Fernández Álvarez | 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 | 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') } |
135 | 6be2adf7 | Luis Fernández Álvarez | it { is_expected.to contain_nftables__rule('DOCKER_ISOLATION_STAGE_2-drop').with_content('oifname "ifdo0" counter drop') } |
136 | 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') } |
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 | 6be2adf7 | Luis Fernández Álvarez | 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 | c3515492 | Luis Fernández Álvarez | it { |
148 | is_expected.to contain_nftables__rule('DOCKER-counter').with(
|
||
149 | content: 'iifname "ifdo0" counter return', |
||
150 | table: 'ip-nat', |
||
151 | ) |
||
152 | } |
||
153 | 6be2adf7 | Luis Fernández Álvarez | end
|
154 | end
|
||
155 | end
|
||
156 | c3515492 | Luis Fernández Álvarez | end |