|
18 | 18 | title '2.2 Worker Node: Configuration Files'
|
19 | 19 |
|
20 | 20 | control 'cis-kubernetes-benchmark-2.2.1' do
|
21 |
| - title 'Ensure that the config file permissions are set to 644 or more restrictive' |
22 |
| - desc "Ensure that the `config` file has permissions of `644` or more restrictive.\n\nRationale: The `config` file controls various parameters that set the behavior of various components of the worker node. You should restrict its file permissions to maintain the integrity of the file. The file should be writable by only the administrators on the system." |
| 21 | + title 'Ensure that the kubelet.conf file permissions are set to 644 or more restrictive' |
| 22 | + desc "Ensure that the kubelet.conf file has permissions of 644 or more restrictive.\n\nRationale: The kubelet.conf file is the kubeconfig file for the node, and controls various parameters that set the behavior and identity of the worker node. You should restrict its file permissions to maintain the integrity of the file. The file should be writable by only the administrators on the system." |
23 | 23 | impact 1.0
|
24 | 24 |
|
25 | 25 | tag cis: 'kubernetes:2.2.1'
|
26 | 26 | tag level: 1
|
27 | 27 |
|
28 | 28 | only_if do
|
29 |
| - file('/etc/kubernetes/config').exist? |
| 29 | + file('/etc/kubernetes/kubelet.conf').exist? |
30 | 30 | end
|
31 | 31 |
|
32 |
| - describe file('/etc/kubernetes/config').mode.to_s do |
| 32 | + describe file('/etc/kubernetes/kubelet.conf').mode.to_s do |
33 | 33 | it { should match(/[0246][024][024]/) }
|
34 | 34 | end
|
35 | 35 | end
|
36 | 36 |
|
37 | 37 | control 'cis-kubernetes-benchmark-2.2.2' do
|
38 |
| - title 'Ensure that the config file ownership is set to root:root' |
39 |
| - desc "Ensure that the `config` file ownership is set to `root:root`.\n\nRationale: The `config` file controls various parameters that set the behavior of various components of the worker node. You should set its file ownership to maintain the integrity of the file. The file should be owned by `root:root`." |
| 38 | + title 'Ensure that the kubelet.conf file ownership is set to root:root' |
| 39 | + desc "Ensure that the kubelet.conf file ownership is set to root:root.\n\nRationale: The kubelet.conf file is the kubeconfig file for the node, and controls various parameters that set the behavior and identity of the worker node. You should set its file ownership to maintain the integrity of the file. The file should be owned by root:root." |
40 | 40 | impact 1.0
|
41 | 41 |
|
42 | 42 | tag cis: 'kubernetes:2.2.2'
|
43 | 43 | tag level: 1
|
44 | 44 |
|
45 | 45 | only_if do
|
46 |
| - file('/etc/kubernetes/config').exist? |
| 46 | + file('/etc/kubernetes/kubelet.conf').exist? |
47 | 47 | end
|
48 | 48 |
|
49 |
| - describe file('/etc/kubernetes/config') do |
| 49 | + describe file('/etc/kubernetes/kubelet.conf') do |
50 | 50 | it { should be_owned_by 'root' }
|
51 | 51 | it { should be_grouped_into 'root' }
|
52 | 52 | end
|
53 | 53 | end
|
54 | 54 |
|
55 | 55 | control 'cis-kubernetes-benchmark-2.2.3' do
|
56 |
| - title 'Ensure that the kubelet file permissions are set to 644 or more restrictive' |
57 |
| - desc "Ensure that the `kubelet` file has permissions of `644` or more restrictive.\n\nRationale: The `kubelet` file controls various parameters that set the behavior of the `kubelet` service in the worker node. You should restrict its file permissions to maintain the integrity of the file. The file should be writable by only the administrators on the system." |
| 56 | + title 'Ensure that the kubelet service file permissions are set to 644 or more restrictive' |
| 57 | + desc "Ensure that the kubelet service file has permissions of 644 or more restrictive.\n\nRationale: The kubelet service file controls various parameters that set the behavior of the kubelet service in the worker node. You should restrict its file permissions to maintain the integrity of the file. The file should be writable by only the administrators on the system." |
58 | 58 | impact 1.0
|
59 | 59 |
|
60 | 60 | tag cis: 'kubernetes:2.2.3'
|
61 | 61 | tag level: 1
|
62 | 62 |
|
63 |
| - only_if do |
64 |
| - file('/etc/kubernetes/kubelet').exist? |
65 |
| - end |
66 |
| - |
67 |
| - describe file('/etc/kubernetes/kubelet').mode.to_s do |
68 |
| - it { should match(/[0246][024][024]/) } |
| 63 | + if file('/etc/systemd/system/kubelet.service.d/10-kubeadm.conf').exist? |
| 64 | + describe file('/etc/systemd/system/kubelet.service.d/10-kubeadm.conf').mode.to_s do |
| 65 | + it { should match(/[0246][024][024]/) } |
| 66 | + end |
| 67 | + else |
| 68 | + describe 'cis-kubernetes-benchmark-2.2.3' do |
| 69 | + skip 'Review the permissions on your Kubelet systemd service file.' |
| 70 | + end |
69 | 71 | end
|
70 | 72 | end
|
71 | 73 |
|
72 | 74 | control 'cis-kubernetes-benchmark-2.2.4' do
|
73 |
| - title 'Ensure that the kubelet file ownership is set to root:root' |
74 |
| - desc "Ensure that the `kubelet` file ownership is set to `root:root`.\n\nRationale: The `kubelet` file controls various parameters that set the behavior of the `kubelet` service in the worker node. You should set its file ownership to maintain the integrity of the file. The file should be owned by `root:root`." |
| 75 | + title 'Ensure that the kubelet service file ownership is set to root:root' |
| 76 | + desc "Ensure that the kubelet service file ownership is set to root:root.\n\nRationale: The kubelet service file controls various parameters that set the behavior of the kubelet service in the worker node. You should set its file ownership to maintain the integrity of the file. The file should be owned by root:root." |
75 | 77 | impact 1.0
|
76 | 78 |
|
77 | 79 | tag cis: 'kubernetes:2.2.4'
|
78 | 80 | tag level: 1
|
79 | 81 |
|
80 |
| - only_if do |
81 |
| - file('/etc/kubernetes/kubelet').exist? |
82 |
| - end |
83 |
| - |
84 |
| - describe file('/etc/kubernetes/kubelet') do |
85 |
| - it { should be_owned_by 'root' } |
86 |
| - it { should be_grouped_into 'root' } |
| 82 | + if file('/etc/systemd/system/kubelet.service.d/10-kubeadm.conf').exist? |
| 83 | + describe file('/etc/systemd/system/kubelet.service.d/10-kubeadm.conf') do |
| 84 | + it { should be_owned_by 'root' } |
| 85 | + it { should be_grouped_into 'root' } |
| 86 | + end |
| 87 | + else |
| 88 | + describe 'cis-kubernetes-benchmark-1.4.10' do |
| 89 | + skip 'Review the ownership of your Kubelet systemd service file.' |
| 90 | + end |
87 | 91 | end
|
88 | 92 | end
|
89 | 93 |
|
90 | 94 | control 'cis-kubernetes-benchmark-2.2.5' do
|
91 |
| - title 'Ensure that the proxy file permissions are set to 644 or more restrictive' |
92 |
| - desc "Ensure that the `proxy` file has permissions of `644` or more restrictive.\n\nRationale: The `proxy` file controls various parameters that set the behavior of the `kube-proxy` service in the worker node. You should restrict its file permissions to maintain the integrity of the file. The file should be writable by only the administrators on the system." |
| 95 | + title 'Ensure that the proxy kubeconfig file permissions are set to 644 or more restrictive' |
| 96 | + desc "If kube-proxy is running, ensure that the proxy kubeconfig file has permissions of 644 or more restrictive.\n\nRationale: The kube-proxy kubeconfig file controls various parameters of the kube-proxy service in the worker node. You should restrict its file permissions to maintain the integrity of the file. The file should be writable by only the administrators on the system." |
93 | 97 | impact 1.0
|
94 | 98 |
|
95 | 99 | tag cis: 'kubernetes:2.2.5'
|
96 | 100 | tag level: 1
|
97 | 101 |
|
98 |
| - only_if do |
99 |
| - file('/etc/kubernetes/proxy').exist? |
100 |
| - end |
| 102 | + if processes('kube-proxy').exists? |
| 103 | + conf_file = processes('kube-proxy').commands.first.scan(/--config=(\S+)/).last.first |
101 | 104 |
|
102 |
| - describe file('/etc/kubernetes/proxy').mode.to_s do |
103 |
| - it { should match(/[0246][024][024]/) } |
| 105 | + describe file(conf_file).mode.to_s do |
| 106 | + it { should match(/[0246][024][024]/) } |
| 107 | + end |
| 108 | + else |
| 109 | + describe 'cis-kubernetes-benchmark-2.2.5' do |
| 110 | + skip 'kube-proxy process not found' |
| 111 | + end |
104 | 112 | end
|
105 | 113 | end
|
106 | 114 |
|
107 | 115 | control 'cis-kubernetes-benchmark-2.2.6' do
|
108 |
| - title 'Ensure that the proxy file ownership is set to root:root' |
109 |
| - desc "Ensure that the `proxy` file ownership is set to `root:root`.\n\nRationale: The `proxy` file controls various parameters that set the behavior of the `kube-proxy` service in the worker node. You should set its file ownership to maintain the integrity of the file. The file should be owned by `root:root`." |
| 116 | + title 'Ensure that the proxy kubeconfig file ownership is set to root:root' |
| 117 | + desc "If kube-proxy is running, ensure that the file ownership of its kubeconfig file is set to root:root.\n\nRationale: The kubeconfig file for kube-proxy controls various parameters for the kube-proxy service in the worker node. You should set its file ownership to maintain the integrity of the file. The file should be owned by root:root." |
110 | 118 | impact 1.0
|
111 | 119 |
|
112 | 120 | tag cis: 'kubernetes:2.2.6'
|
113 | 121 | tag level: 1
|
114 | 122 |
|
115 |
| - only_if do |
116 |
| - file('/etc/kubernetes/proxy').exist? |
117 |
| - end |
| 123 | + if processes('kube-proxy').exists? |
| 124 | + conf_file = processes('kube-proxy').commands.first.scan(/--config=(\S+)/).last.first |
118 | 125 |
|
119 |
| - describe file('/etc/kubernetes/proxy') do |
120 |
| - it { should be_owned_by 'root' } |
121 |
| - it { should be_grouped_into 'root' } |
| 126 | + describe file(conf_file) do |
| 127 | + it { should be_owned_by 'root' } |
| 128 | + it { should be_grouped_into 'root' } |
| 129 | + end |
| 130 | + else |
| 131 | + describe 'cis-kubernetes-benchmark-2.2.6' do |
| 132 | + skip 'kube-proxy process not found' |
| 133 | + end |
122 | 134 | end
|
123 | 135 | end
|
124 | 136 |
|
|
130 | 142 | tag cis: 'kubernetes:2.2.7'
|
131 | 143 | tag level: 1
|
132 | 144 |
|
133 |
| - ca_cert_path = processes('kubelet').commands.to_s.scan(/--client-ca-file=(\S*)/) |
134 |
| - |
135 |
| - if ca_cert_path.empty? |
136 |
| - describe 'cis-kubernetes-benchmark-2.2.7' do |
137 |
| - skip 'No client CA file specified for `kubelet` process' |
| 145 | + if processes('kubelet').exists? |
| 146 | + ca_cert_path = processes('kubelet').commands.first.scan(/--client-ca-file=(\S+)/) |
| 147 | + |
| 148 | + if ca_cert_path.empty? |
| 149 | + describe 'cis-kubernetes-benchmark-2.2.7' do |
| 150 | + skip 'No client CA file specified for `kubelet` process' |
| 151 | + end |
| 152 | + else |
| 153 | + describe file(ca_cert_path.last.first).mode.to_s do |
| 154 | + it { should match(/[0246][024][024]/) } |
| 155 | + end |
138 | 156 | end
|
139 | 157 | else
|
140 |
| - describe file(ca_cert_path.last.first).mode.to_s do |
141 |
| - it { should match(/[0246][024][024]/) } |
| 158 | + describe 'cis-kubernetes-benchmark-2.2.7' do |
| 159 | + skip 'kubelet process not found' |
142 | 160 | end
|
143 | 161 | end
|
144 | 162 | end
|
|
151 | 169 | tag cis: 'kubernetes:2.2.8'
|
152 | 170 | tag level: 1
|
153 | 171 |
|
154 |
| - ca_cert_path = processes('kubelet').commands.to_s.scan(/--client-ca-file=(\S*)/) |
155 |
| - |
156 |
| - if ca_cert_path.empty? |
157 |
| - describe 'cis-kubernetes-benchmark-2.2.8' do |
158 |
| - skip 'No client CA file specified for `kubelet` process' |
| 172 | + if processes('kubelet').exists? |
| 173 | + ca_cert_path = processes('kubelet').commands.to_s.scan(/--client-ca-file=(\S+)/) |
| 174 | + |
| 175 | + if ca_cert_path.empty? |
| 176 | + describe 'cis-kubernetes-benchmark-2.2.8' do |
| 177 | + skip 'No client CA file specified for `kubelet` process' |
| 178 | + end |
| 179 | + else |
| 180 | + describe file(ca_cert_path.last.first) do |
| 181 | + it { should be_owned_by 'root' } |
| 182 | + it { should be_grouped_into 'root' } |
| 183 | + end |
159 | 184 | end
|
160 | 185 | else
|
161 |
| - describe file(ca_cert_path.last.first) do |
162 |
| - it { should be_owned_by 'root' } |
163 |
| - it { should be_grouped_into 'root' } |
| 186 | + describe 'cis-kubernetes-benchmark-2.2.8' do |
| 187 | + skip 'kubelet process not found' |
164 | 188 | end
|
165 | 189 | end
|
166 | 190 | end
|
0 commit comments