-
Notifications
You must be signed in to change notification settings - Fork 77
Expand file tree
/
Copy path1_1_master_node_configuration_files.rb
More file actions
executable file
·439 lines (350 loc) · 17.4 KB
/
1_1_master_node_configuration_files.rb
File metadata and controls
executable file
·439 lines (350 loc) · 17.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
# frozen_string_literal: true
title '1.1 Master Node: Configuration Files'
apiserver_manifest = input('apiserver-manifest')
controller_manager_manifest = input('controller_manager-manifest')
scheduler_manifest = input('scheduler-manifest')
etcd_manifest = input('etcd-manifest')
etcd_regex = Regexp.new(input('etcd'))
admin_conf = input('admin-conf')
scheduler_conf = input('scheduler-conf')
controller_manager_conf = input('controller_manager-conf')
kubernetes_pki = input('kubernetes-pki')
control 'cis-kubernetes-benchmark-1.1.1' do
title 'Ensure that the API server pod specification file permissions are set to 644 or more restrictive'
desc "Ensure that the API server pod specification file has permissions of `644` or more restrictive.\n\nRationale: The API server pod specification file controls various parameters that set the behavior of the API server. 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."
impact 1.0
tag cis: 'kubernetes:1.1.1'
tag level: 1
only_if do
file(apiserver_manifest).exist?
end
describe file(apiserver_manifest).mode.to_s(8) do
it { should match(/[0246][024][024]/) }
end
end
control 'cis-kubernetes-benchmark-1.1.2' do
title 'Ensure that the API server pod specification file ownership is set to root:root'
desc "Ensure that the API server pod specification file ownership is set to `root:root`.\n\nRationale: The API server pod specification file controls various parameters that set the behavior of the API server. You should set its file ownership to maintain the integrity of the file. The file should be owned by `root:root`."
impact 1.0
tag cis: 'kubernetes:1.1.2'
tag level: 1
only_if do
file(apiserver_manifest).exist?
end
describe file(apiserver_manifest) do
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
end
end
control 'cis-kubernetes-benchmark-1.1.3' do
title 'Ensure that the controller manager pod specification file permissions are set to 644 or more restrictive'
desc "Ensure that the controller manager pod specification file has permissions of `644` or more restrictive.\n\nRationale: The controller manager pod specification file controls various parameters that set the behavior of the Controller Manager on the master 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."
impact 1.0
tag cis: 'kubernetes:1.1.3'
tag level: 1
only_if do
file(controller_manager_manifest).exist?
end
describe file(controller_manager_manifest).mode.to_s(8) do
it { should match(/[0246][024][024]/) }
end
end
control 'cis-kubernetes-benchmark-1.1.4' do
title 'Ensure that the controller manager pod specification file ownership is set to root:root'
desc "Ensure that the controller manager pod specification file ownership is set to `root:root`.\n\nRationale: The controller manager pod specification file controls various parameters that set the behavior of various components of the master node. You should set its file ownership to maintain the integrity of the file. The file should be owned by `root:root`."
impact 1.0
tag cis: 'kubernetes:1.1.4'
tag level: 1
only_if do
file(controller_manager_manifest).exist?
end
describe file(controller_manager_manifest) do
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
end
end
control 'cis-kubernetes-benchmark-1.1.5' do
title 'Ensure that the scheduler pod specification file permissions are set to 644 or more restrictive'
desc "Ensure that the scheduler pod specification file has permissions of `644` or more restrictive.\n\nRationale: The scheduler pod specification file controls various parameters that set the behavior of the Scheduler service in the master 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."
impact 1.0
tag cis: 'kubernetes:1.1.5'
tag level: 1
only_if do
file(scheduler_manifest).exist?
end
describe file(scheduler_manifest).mode.to_s(8) do
it { should match(/[0246][024][024]/) }
end
end
control 'cis-kubernetes-benchmark-1.1.6' do
title 'Ensure that the scheduler pod specification file ownership is set to root:root'
desc "Ensure that the scheduler pod specification file ownership is set to `root:root`.\n\nRationale: The scheduler pod specification file controls various parameters that set the behavior of the `kube-scheduler` service in the master node. You should set its file ownership to maintain the integrity of the file. The file should be owned by `root:root`."
impact 1.0
tag cis: 'kubernetes:1.1.6'
tag level: 1
only_if do
file(scheduler_manifest).exist?
end
describe file(scheduler_manifest) do
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
end
end
control 'cis-kubernetes-benchmark-1.1.7' do
title 'Ensure that the etcd pod specification file permissions are set to 644 or more restrictive'
desc "Ensure that the `/etc/kubernetes/manifests/etcd.yaml` file has permissions of `644` or more restrictive.\n\nRationale: The etcd pod specification file `/etc/kubernetes/manifests/etcd.yaml` controls various parameters that set the behavior of the `etcd` service in the master node. etcd is a highly-available key-value store which Kubernetes uses for persistent storage of all of its REST API object. 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."
impact 1.0
tag cis: 'kubernetes:1.1.7'
tag level: 1
only_if do
file(etcd_manifest).exist?
end
describe file(etcd_manifest).mode.to_s(8) do
it { should match(/[0246][024][024]/) }
end
end
control 'cis-kubernetes-benchmark-1.1.8' do
title 'Ensure that the etcd pod specification file ownership is set to root:root'
desc "Ensure that the `/etc/kubernetes/manifests/etcd.yaml` file ownership is set to `root:root`.\n\nRationale: The etcd pod specification file `/etc/kubernetes/manifests/etcd.yaml` controls various parameters that set the behavior of the `etcd` service in the master node. etcd is a highly-available key-value store which Kubernetes uses for persistent storage of all of its REST API object. You should set its file ownership to maintain the integrity of the file. The file should be owned by `root:root`."
impact 1.0
tag cis: 'kubernetes:1.1.8'
tag level: 1
only_if do
file(etcd_manifest).exist?
end
describe file(etcd_manifest) do
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
end
end
control 'cis-kubernetes-benchmark-1.1.9' do
title 'Ensure that the Container Network Interface file permissions are set to 644 or more restrictive'
desc "Ensure that the Container Network Interface files have permissions of `644` or more restrictive.\n\nRationale: Container Network Interface provides various networking options for overlay networking. You should consult their documentation and restrict their respective file permissions to maintain the integrity of those files. Those files should be writable by only the administrators on the system."
impact 0.0
tag cis: 'kubernetes:1.1.9'
tag level: 1
if file('/etc/sysconfig/flanneld').exist?
describe file('/etc/sysconfig/flanneld').mode.to_s(8) do
it { should match(/[0246][024][024]/) }
end
else
describe 'cis-kubernetes-benchmark-1.1.9' do
skip 'Review the permissions on your CNI configuration file(s).'
end
end
end
control 'cis-kubernetes-benchmark-1.1.10' do
title 'Ensure that the Container Network Interface file ownership is set to root:root'
desc "Ensure that the Container Network Interface files have ownership set to `root:root`.\n\nRationale: Container Network Interface provides various networking options for overlay networking. You should consult their documentation and restrict their respective file permissions to maintain the integrity of those files. Those files should be owned by `root:root`."
impact 0.0
tag cis: 'kubernetes:1.1.10'
tag level: 1
if file('/etc/sysconfig/flanneld').exist?
describe file('/etc/sysconfig/flanneld') do
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
end
else
describe 'cis-kubernetes-benchmark-1.1.10' do
skip 'Review the ownership of your CNI configuration file(s).'
end
end
end
control 'cis-kubernetes-benchmark-1.1.11' do
title 'Ensure that the etcd data directory permissions are set to 700 or more restrictive'
desc "Ensure that the etcd data directory has permissions of `700` or more restrictive.\n\nRationale: etcd is a highly-available key-value store used by Kubernetes deployments for persistent storage of all of its REST API objects. This data directory should be protected from any unauthorized reads or writes. It should not be readable or writable by any group members or the world."
impact 1.0
tag cis: 'kubernetes:1.1.11'
tag level: 1
etcd_process = processes(Regexp.new(%r{/usr/bin/etcd}))
data_dir = ''
catch(:stop) do
if etcd_process.exists?
if (data_dir = etcd_process.commands.to_s.scan(/--data-dir=(\S+)/).last)
data_dir = data_dir.first
throw :stop
end
if (data_dir = file("/proc/#{etcd_process.pids.first}/environ").content.split("\0").select { |i| i[/^ETCD_DATA_DIR/] }.first.to_s.split('=', 2).last.to_s)
throw :stop
end
end
end
if !data_dir.empty?
describe file(data_dir).mode.to_s(8) do
it { should match(/[01234567]00/) }
end
else
describe 'cis-kubernetes-benchmark-1.1.11' do
skip 'etcd data directory not found'
end
end
end
control 'cis-kubernetes-benchmark-1.1.12' do
title 'Ensure that the etcd data directory ownership is set to etcd:etcd'
desc "Ensure that the etcd data directory ownership is set to `etcd:etcd`.\n\nRationale: etcd is a highly-available key-value store used by Kubernetes deployments for persistent storage of all of its REST API objects. This data directory should be protected from any unauthorized reads or writes. It should be owned by `etcd:etcd`."
impact 1.0
tag cis: 'kubernetes:1.1.12'
tag level: 1
etcd_process = processes(etcd_regex)
data_dir = ''
catch(:stop) do
if etcd_process.exists?
if (data_dir = etcd_process.commands.to_s.scan(/--data-dir=(\S+)/).last)
data_dir = data_dir.first
throw :stop
end
if (data_dir = file("/proc/#{etcd_process.pids.first}/environ").content.split("\0").select { |i| i[/^ETCD_DATA_DIR/] }.first.to_s.split('=', 2).last.to_s)
throw :stop
end
end
end
if !data_dir.empty?
describe file(data_dir) do
it { should be_owned_by 'etcd' }
it { should be_grouped_into 'etcd' }
end
else
describe 'cis-kubernetes-benchmark-1.1.12' do
skip 'etcd data directory not found'
end
end
end
control 'cis-kubernetes-benchmark-1.1.13' do
title 'Ensure that the admin.conf file permissions are set to 644 or more restrictive'
desc "Ensure that the `admin.conf` file has permissions of `644` or more restrictive.\n\nRationale: The `admin.conf` is the administrator kubeconfig file defining various settings for the administration of the cluster. 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."
impact 1.0
tag cis: 'kubernetes:1.1.13'
tag level: 1
only_if do
file(admin_conf).exist?
end
describe file(admin_conf).mode.to_s(8) do
it { should match(/[0246][024][024]/) }
end
end
control 'cis-kubernetes-benchmark-1.1.14' do
title 'Ensure that the admin.conf file ownership is set to root:root'
desc "Ensure that the `admin.conf` file ownership is set to `root:root`.\n\nRationale: The `admin.conf` file contains the admin credentials for the cluster. You should set its file ownership to maintain the integrity of the file. The file should be owned by `root:root`."
impact 1.0
tag cis: 'kubernetes:1.1.14'
tag level: 1
only_if do
file(admin_conf).exist?
end
describe file(admin_conf) do
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
end
end
control 'cis-kubernetes-benchmark-1.1.15' do
title 'Ensure that the scheduler.conf file has permissions of 644 or more restrictive'
desc "Ensure that the `scheduler.conf` file has permissions of `644` or more restrictive.\n\nRationale: The `scheduler.conf` file is the kubeconfig file for the Scheduler. 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."
impact 1.0
tag cis: 'kubernetes:1.1.15'
tag level: 1
only_if do
file(scheduler_conf).exist?
end
describe file(scheduler_conf).mode.to_s(8) do
it { should match(/[0246][024][024]/) }
end
end
control 'cis-kubernetes-benchmark-1.1.16' do
title 'Ensure that the scheduler.conf file ownership is set to root:root'
desc "Ensure that the `scheduler.conf` file ownership is set to `root:root`.\n\nRationale: The `scheduler.conf` file is the kubeconfig file for the Scheduler. You should set its file ownership to maintain the integrity of the file. The file should be owned by `root:root`."
impact 1.0
tag cis: 'kubernetes:1.1.16'
tag level: 1
only_if do
file(scheduler_conf).exist?
end
describe file(scheduler_conf) do
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
end
end
control 'cis-kubernetes-benchmark-1.1.17' do
title 'Ensure that the controller-manager.conf file permissions are set to 644 or more restrictive'
desc "Ensure that the `controller-manager.conf` file has permissions of 644 or more restrictive.\n\nRationale: The `controller-manager.conf` file is the kubeconfig file for the Controller Manager. 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."
impact 1.0
tag cis: 'kubernetes:1.1.17'
tag level: 1
only_if do
file(controller_manager_conf).exist?
end
describe file(controller_manager_conf).mode.to_s(8) do
it { should match(/[0246][024][024]/) }
end
end
control 'cis-kubernetes-benchmark-1.1.18' do
title 'Ensure that the controller-manager.conf file ownership is set to root:root'
desc "Ensure that the `controller-manager.conf` file ownership is set to `root:root`.\n\nRationale: The `controller-manager.conf` file is the kubeconfig file for the Controller Manager. You should set its file ownership to maintain the integrity of the file. The file should be owned by `root:root`."
impact 1.0
tag cis: 'kubernetes:1.1.18'
tag level: 1
only_if do
file(controller_manager_conf).exist?
end
describe file(controller_manager_conf) do
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
end
end
control 'cis-kubernetes-benchmark-1.1.19' do
title 'Ensure that the Kubernetes PKI directory and file ownership is set to root:root'
desc "Ensure that the Kubernetes PKI directory and file ownership is set to `root:root`.\n\nRationale: Kubernetes makes use of a number of certificates as part of its operation. You should set the ownership of the directory containing the PKI information and all files in that directory to maintain their integrity. The directory and files should be owned by `root:root`."
impact 1.0
tag cis: 'kubernetes:1.1.19'
tag level: 1
only_if do
directory(kubernetes_pki).exist?
end
describe directory(kubernetes_pki) do
it { should be_owned_by 'root' }
it { should be_grouped_into 'root' }
end
end
control 'cis-kubernetes-benchmark-1.1.20' do
title 'Ensure that the Kubernetes PKI certificate file permissions are set to 644 or more restrictive'
desc "Ensure that Kubernetes PKI certificate files have permissions of `644` or more restrictive.\n\nRationale: Kubernetes makes use of a number of certificate files as part of the operation of its components. The permissions on these files should be set to `644` or more restrictive to protect their integrity."
impact 1.0
tag cis: 'kubernetes:1.1.20'
tag level: 1
only_if do
directory(kubernetes_pki).exist?
end
cert_files = command('find /etc/kubernetes/pki -type f -name *.crt').stdout.split
if cert_files.empty?
describe 'cis-kubernetes-benchmark-1.1.20' do
skip 'No certificate files found'
end
else
cert_files.each do |cert|
describe file(cert).mode.to_s(8) do
it { should match(/[0246][024][024]/) }
end
end
end
end
control 'cis-kubernetes-benchmark-1.1.21' do
title 'Ensure that the Kubernetes PKI key file permissions are set to 600'
desc "Ensure that Kubernetes PKI key files have permissions of `600`.\n\nRationale: Kubernetes makes use of a number of key files as part of the operation of its components. The permissions on these files should be set to `600` to protect their integrity and confidentiality."
impact 1.0
tag cis: 'kubernetes:1.1.21'
tag level: 1
only_if do
directory(kubernetes_pki).exist?
end
key_files = command('find /etc/kubernetes/pki -type f -name *.key').stdout.split
if key_files.empty?
describe 'cis-kubernetes-benchmark-1.1.21' do
skip 'No private key files found'
end
else
key_files.each do |key|
describe file(key) do
its('mode') { should cmp '0600' }
end
end
end
end