Skip to content

Commit d5a2098

Browse files
committed
Update for CIS Kubernetes benchmark version 1.2.0
Signed-off-by: Kristian Vlaardingerbroek <[email protected]>
1 parent 6411ee3 commit d5a2098

8 files changed

+386
-186
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
**/.librarian
22
**/.tmp
33
**/Puppetfile.lock
4+
vendor/
5+
.bundle
46
Gemfile.lock
57
Berksfile.lock
68
inspec.lock

README.md

100644100755
+26-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# CIS Kubernetes Benchmark - InSpec Profile
22

33
## Description
4-
This profile implements the [CIS Kubernetes 1.1.0 Benchmark](https://www.cisecurity.org/benchmark/kubernetes/).
4+
This profile implements the [CIS Kubernetes 1.2.0 Benchmark](https://www.cisecurity.org/benchmark/kubernetes/).
55

66
## Attributes
77

@@ -10,6 +10,31 @@ To switch between the CIS profile levels the following attribute can be used:
1010
* `cis_level: 2`
1111
define which profile level to use, accepted values are `1` and `2`.
1212

13+
Refer to the [InSpec Profiles Reference](https://www.inspec.io/docs/reference/profiles/) for more information about Profile Attributes.
14+
15+
## Usage
16+
17+
This Compliance Profile requires [InSpec](https://github.com/chef/inspec) for execution:
18+
19+
```
20+
$ git clone https://github.com/dev-sec/cis-kubernetes-benchmark
21+
$ inspec exec cis-kubernetes-benchmark
22+
```
23+
24+
You can also execute the profile directly from Github:
25+
26+
```
27+
$ inspec exec https://github.com/dev-sec/cis-kubernetes-benchmark
28+
```
29+
30+
Or execute specific controls instead of all:
31+
32+
```
33+
$ inspec exec cis-kubernetes-benchmark --controls=cis-kubernetes-benchmark-1.1.2 cis-kubernetes-benchmark-1.3.5
34+
```
35+
36+
Refer to the [InSpec CLI reference](https://www.inspec.io/docs/reference/cli) for more information.
37+
1338
## License and Author
1439

1540
* Author:: Kristian Vlaardingerbroek <[email protected]>

controls/1_1_master_node_api_server.rb

100644100755
+106-80
Large diffs are not rendered by default.

controls/1_4_master_node_configuration_files.rb

100644100755
+158-48
Large diffs are not rendered by default.

controls/1_5_master_node_etcd.rb

100644100755
+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@
161161

162162
catch(:stop) do
163163
if etcd_process.exists?
164-
if (wal_dir = etcd_process.commands.to_s.scan(/--data-dir=(\S+)/).last)
164+
if (wal_dir = etcd_process.commands.first.scan(/--data-dir=(\S+)/).last)
165165
wal_dir = wal_dir.first
166166
throw :stop
167167
end

controls/1_6_master_node_general_security_primitives.rb

100644100755
+13
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,17 @@
123123
skip 'Review the network policies enforced and ensure that they are suitable for your requirements.'
124124
end
125125
end
126+
127+
control 'cis-kubernetes-benchmark-1.6.9' do
128+
title 'Place compensating controls in the form of PSP and RBAC for privileged containers usage'
129+
desc "Use Pod Security Policies (PSP) and RBAC authorization to mitigate the risk arising from using privileged containers.\n\nRationale: A number of components used by Kubernetes clusters currently make use of privileged containers (e.g. Container Network Interface plugins). Privileged containers pose a risk to the underlying host infrastructure. You should use PSP and RBAC or other forms of authorization to mitigate the risk arising out of such privileged container usage. PSPs should be in place to restrict access to create privileged containers to specific roles only, and access to those roles should be restricted using RBAC role bindings."
130+
impact 0.0
131+
132+
tag cis: 'kubernetes:1.6.9'
133+
tag level: 2
134+
135+
describe 'cis-kubernetes-benchmark-1.6.8' do
136+
skip 'Review Pod Security Policies and RBAC authorization.'
137+
end
138+
end
126139
end

controls/2_2_worker_node_configuration_files.rb

100644100755
+79-55
Original file line numberDiff line numberDiff line change
@@ -18,107 +18,119 @@
1818
title '2.2 Worker Node: Configuration Files'
1919

2020
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."
2323
impact 1.0
2424

2525
tag cis: 'kubernetes:2.2.1'
2626
tag level: 1
2727

2828
only_if do
29-
file('/etc/kubernetes/config').exist?
29+
file('/etc/kubernetes/kubelet.conf').exist?
3030
end
3131

32-
describe file('/etc/kubernetes/config').mode.to_s do
32+
describe file('/etc/kubernetes/kubelet.conf').mode.to_s do
3333
it { should match(/[0246][024][024]/) }
3434
end
3535
end
3636

3737
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."
4040
impact 1.0
4141

4242
tag cis: 'kubernetes:2.2.2'
4343
tag level: 1
4444

4545
only_if do
46-
file('/etc/kubernetes/config').exist?
46+
file('/etc/kubernetes/kubelet.conf').exist?
4747
end
4848

49-
describe file('/etc/kubernetes/config') do
49+
describe file('/etc/kubernetes/kubelet.conf') do
5050
it { should be_owned_by 'root' }
5151
it { should be_grouped_into 'root' }
5252
end
5353
end
5454

5555
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."
5858
impact 1.0
5959

6060
tag cis: 'kubernetes:2.2.3'
6161
tag level: 1
6262

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
6971
end
7072
end
7173

7274
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."
7577
impact 1.0
7678

7779
tag cis: 'kubernetes:2.2.4'
7880
tag level: 1
7981

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
8791
end
8892
end
8993

9094
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."
9397
impact 1.0
9498

9599
tag cis: 'kubernetes:2.2.5'
96100
tag level: 1
97101

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
101104

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
104112
end
105113
end
106114

107115
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."
110118
impact 1.0
111119

112120
tag cis: 'kubernetes:2.2.6'
113121
tag level: 1
114122

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
118125

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
122134
end
123135
end
124136

@@ -130,15 +142,21 @@
130142
tag cis: 'kubernetes:2.2.7'
131143
tag level: 1
132144

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
138156
end
139157
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'
142160
end
143161
end
144162
end
@@ -151,16 +169,22 @@
151169
tag cis: 'kubernetes:2.2.8'
152170
tag level: 1
153171

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
159184
end
160185
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'
164188
end
165189
end
166190
end

inspec.yml

100644100755
+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ copyright: Schuberg Philis B.V.
55
copyright_email: [email protected]
66
license: Apache-2.0
77
summary: An InSpec Compliance profile for the CIS Kubernetes Benchmark
8-
version: 0.2.0
8+
version: 0.3.0

0 commit comments

Comments
 (0)