Skip to content

Commit 6466721

Browse files
committed
Add attribute to select profile level
Signed-off-by: Kristian Vlaardingerbroek <[email protected]>
1 parent b8c6ed9 commit 6466721

File tree

3 files changed

+67
-52
lines changed

3 files changed

+67
-52
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
## Description
44
This profile implements the [CIS Kubernetes 1.1.0 Benchmark](https://www.cisecurity.org/benchmark/kubernetes/).
55

6+
## Attributes
7+
8+
To switch between the CIS profile levels the following attribute can be used:
9+
10+
* `cis_level: 2`
11+
define which profile level to use, accepted values are `1` and `2`.
12+
613
## License and Author
714

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

controls/1_5_master_node_etcd.rb

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#
1616
# author: Kristian Vlaardingerbroek
1717

18+
cis_level = attribute('cis_level', default: '2', description: 'CIS profile level to audit', required: true)
19+
1820
title '1.5 Master Node: etcd'
1921

2022
etcd_regex = Regexp.new(%r{/usr/bin/etcd})
@@ -201,15 +203,17 @@
201203
end
202204
end
203205

204-
control 'cis-kubernetes-benchmark-1.5.9' do
205-
title 'Ensure that a unique Certificate Authority is used for etcd'
206-
desc "Use a different certificate authority for etcd from the one used for Kubernetes.\n\nRationale: etcd is a highly available key-value store used by Kubernetes deployments for persistent storage of all of its REST API objects. Its access should be restricted to specifically designated clients and peers only. Authentication to etcd is based on whether the certificate presented was issued by a trusted certificate authority. There is no checking of certificate attributes such as common name or subject alternative name. As such, if any attackers were able to gain access to any certificate issued by the trusted certificate authority, they would be able to gain full access to the etcd database."
207-
impact 0.0
206+
if cis_level == '2'
207+
control 'cis-kubernetes-benchmark-1.5.9' do
208+
title 'Ensure that a unique Certificate Authority is used for etcd'
209+
desc "Use a different certificate authority for etcd from the one used for Kubernetes.\n\nRationale: etcd is a highly available key-value store used by Kubernetes deployments for persistent storage of all of its REST API objects. Its access should be restricted to specifically designated clients and peers only. Authentication to etcd is based on whether the certificate presented was issued by a trusted certificate authority. There is no checking of certificate attributes such as common name or subject alternative name. As such, if any attackers were able to gain access to any certificate issued by the trusted certificate authority, they would be able to gain full access to the etcd database."
210+
impact 0.0
208211

209-
tag cis: 'kubernetes:1.5.9'
210-
tag level: 2
212+
tag cis: 'kubernetes:1.5.9'
213+
tag level: 2
211214

212-
describe 'cis-kubernetes-benchmark-1.5.9' do
213-
skip 'Review if the CA used for etcd is different from the one used for Kubernetes'
215+
describe 'cis-kubernetes-benchmark-1.5.9' do
216+
skip 'Review if the CA used for etcd is different from the one used for Kubernetes'
217+
end
214218
end
215219
end

controls/1_6_master_node_general_security_primitives.rb

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
#
1616
# author: Kristian Vlaardingerbroek
1717

18+
cis_level = attribute('cis_level', default: '2', description: 'CIS profile level to audit', required: true)
19+
1820
title '1.6 Master Node: General Security Primitives'
1921

2022
control 'cis-kubernetes-benchmark-1.6.1' do
@@ -56,67 +58,69 @@
5658
end
5759
end
5860

59-
control 'cis-kubernetes-benchmark-1.6.4' do
60-
title 'Create network segmentation using Network Policies'
61-
desc "Use network policies to isolate your cluster network.\n\nRationale: Running different applications on the same Kubernetes cluster creates a risk of one compromised application attacking a neighboring application. Network segmentation is important to ensure that containers can communicate only with those they are supposed to. A network policy is a specification of how selections of pods are allowed to communicate with each other and other network endpoints. `NetworkPolicy` resources use labels to select pods and define whitelist rules which allow traffic to the selected pods in addition to what is allowed by the isolation policy for a given namespace."
62-
impact 0.0
61+
if cis_level == '2'
62+
control 'cis-kubernetes-benchmark-1.6.4' do
63+
title 'Create network segmentation using Network Policies'
64+
desc "Use network policies to isolate your cluster network.\n\nRationale: Running different applications on the same Kubernetes cluster creates a risk of one compromised application attacking a neighboring application. Network segmentation is important to ensure that containers can communicate only with those they are supposed to. A network policy is a specification of how selections of pods are allowed to communicate with each other and other network endpoints. `NetworkPolicy` resources use labels to select pods and define whitelist rules which allow traffic to the selected pods in addition to what is allowed by the isolation policy for a given namespace."
65+
impact 0.0
6366

64-
tag cis: 'kubernetes:1.6.4'
65-
tag level: 2
67+
tag cis: 'kubernetes:1.6.4'
68+
tag level: 2
6669

67-
describe 'cis-kubernetes-benchmark-1.6.4' do
68-
skip 'Review the output of `kubectl get pods --namespace=kube-system` and ensure the `NetworkPolicy` objects are the ones you need.'
70+
describe 'cis-kubernetes-benchmark-1.6.4' do
71+
skip 'Review the output of `kubectl get pods --namespace=kube-system` and ensure the `NetworkPolicy` objects are the ones you need.'
72+
end
6973
end
70-
end
7174

72-
control 'cis-kubernetes-benchmark-1.6.5' do
73-
title 'Ensure that the seccomp profile is set to docker/default in your pod definitions'
74-
desc "Enable `docker/default` seccomp profile in your pod definitions.\n\nRationale: Seccomp (secure computing mode) is used to restrict the set of system calls applications can make, allowing cluster administrators greater control over the security of workloads running in the cluster. Kubernetes disables seccomp profiles by default for historical reasons. You should enable it to ensure that the workloads have restricted actions available within the container."
75-
impact 0.0
75+
control 'cis-kubernetes-benchmark-1.6.5' do
76+
title 'Ensure that the seccomp profile is set to docker/default in your pod definitions'
77+
desc "Enable `docker/default` seccomp profile in your pod definitions.\n\nRationale: Seccomp (secure computing mode) is used to restrict the set of system calls applications can make, allowing cluster administrators greater control over the security of workloads running in the cluster. Kubernetes disables seccomp profiles by default for historical reasons. You should enable it to ensure that the workloads have restricted actions available within the container."
78+
impact 0.0
7679

77-
tag cis: 'kubernetes:1.6.5'
78-
tag level: 2
80+
tag cis: 'kubernetes:1.6.5'
81+
tag level: 2
7982

80-
describe 'cis-kubernetes-benchmark-1.6.5' do
81-
skip 'Review all the pod definitions in your cluster and verify that `seccomp` is enabled.'
83+
describe 'cis-kubernetes-benchmark-1.6.5' do
84+
skip 'Review all the pod definitions in your cluster and verify that `seccomp` is enabled.'
85+
end
8286
end
83-
end
8487

85-
control 'cis-kubernetes-benchmark-1.6.6' do
86-
title 'Apply Security Context to Your Pods and Containers'
87-
desc "Apply Security Context to Your Pods and Containers\n\nRationale: A security context defines the operating system security settings (uid, gid, capabilities, SELinux role, etc..) applied to a container. When designing your containers and pods, make sure that you configure the security context for your pods, containers, and volumes. A security context is a property defined in the deployment yaml. It controls the security parameters that will be assigned to the pod/container/volume. There are two levels of security context: pod level security context, and container level security context."
88-
impact 0.0
88+
control 'cis-kubernetes-benchmark-1.6.6' do
89+
title 'Apply Security Context to Your Pods and Containers'
90+
desc "Apply Security Context to Your Pods and Containers\n\nRationale: A security context defines the operating system security settings (uid, gid, capabilities, SELinux role, etc..) applied to a container. When designing your containers and pods, make sure that you configure the security context for your pods, containers, and volumes. A security context is a property defined in the deployment yaml. It controls the security parameters that will be assigned to the pod/container/volume. There are two levels of security context: pod level security context, and container level security context."
91+
impact 0.0
8992

90-
tag cis: 'kubernetes:1.6.6'
91-
tag level: 2
93+
tag cis: 'kubernetes:1.6.6'
94+
tag level: 2
9295

93-
describe 'cis-kubernetes-benchmark-1.6.6' do
94-
skip 'Review the pod definitions in your cluster and verify that you have security contexts defined as appropriate.'
96+
describe 'cis-kubernetes-benchmark-1.6.6' do
97+
skip 'Review the pod definitions in your cluster and verify that you have security contexts defined as appropriate.'
98+
end
9599
end
96-
end
97100

98-
control 'cis-kubernetes-benchmark-1.6.7' do
99-
title 'Configure Image Provenance using ImagePolicyWebhook admission controller'
100-
desc "Configure Image Provenance for your deployment.\n\nRationale: Kubernetes supports plugging in provenance rules to accept or reject the images in your deployments. You could configure such rules to ensure that only approved images are deployed in the cluster."
101-
impact 0.0
101+
control 'cis-kubernetes-benchmark-1.6.7' do
102+
title 'Configure Image Provenance using ImagePolicyWebhook admission controller'
103+
desc "Configure Image Provenance for your deployment.\n\nRationale: Kubernetes supports plugging in provenance rules to accept or reject the images in your deployments. You could configure such rules to ensure that only approved images are deployed in the cluster."
104+
impact 0.0
102105

103-
tag cis: 'kubernetes:1.6.7'
104-
tag level: 2
106+
tag cis: 'kubernetes:1.6.7'
107+
tag level: 2
105108

106-
describe 'cis-kubernetes-benchmark-1.6.7' do
107-
skip 'Review the pod definitions in your cluster and verify that image provenance is configured as appropriate.'
109+
describe 'cis-kubernetes-benchmark-1.6.7' do
110+
skip 'Review the pod definitions in your cluster and verify that image provenance is configured as appropriate.'
111+
end
108112
end
109-
end
110113

111-
control 'cis-kubernetes-benchmark-1.6.8' do
112-
title 'Configure Network policies as appropriate'
113-
desc "Configure Network policies as appropriate.\n\nRationale: The Network Policy API is now stable. Network policy, implemented through a network plug-in, allows users to set and enforce rules governing which pods can communicate with each other. You should leverage it as appropriate in your environment."
114-
impact 0.0
114+
control 'cis-kubernetes-benchmark-1.6.8' do
115+
title 'Configure Network policies as appropriate'
116+
desc "Configure Network policies as appropriate.\n\nRationale: The Network Policy API is now stable. Network policy, implemented through a network plug-in, allows users to set and enforce rules governing which pods can communicate with each other. You should leverage it as appropriate in your environment."
117+
impact 0.0
115118

116-
tag cis: 'kubernetes:1.6.8'
117-
tag level: 2
119+
tag cis: 'kubernetes:1.6.8'
120+
tag level: 2
118121

119-
describe 'cis-kubernetes-benchmark-1.6.8' do
120-
skip 'Review the network policies enforced and ensure that they are suitable for your requirements.'
122+
describe 'cis-kubernetes-benchmark-1.6.8' do
123+
skip 'Review the network policies enforced and ensure that they are suitable for your requirements.'
124+
end
121125
end
122126
end

0 commit comments

Comments
 (0)