Fortifying Kubernetes — Mastering Security With CIS Benchmarks
A Comprehensive Approach to Safeguarding Your Cluster

In my recent post about Network Policies, I mentioned that I’m preparing for the CKS exam. Another subject to study, which is part of the Cluster Setup section in the exam curriculum, focuses on using the CIS Benchmark to enhance cluster security
In this article, we’ll explore how the CIS Benchmark can be effectively applied to fortify your Kubernetes cluster.

CIS Benchmarks
CIS Benchmarks serve as a comprehensive suite of guidelines for enhancing the security of IT systems and data. These benchmarks offer in-depth advice on the secure configuration of a diverse array of technologies, encompassing operating systems, cloud services, and applications such as Kubernetes.
Accessible through their website upon registration, the benchmarks are highly regarded for their thoroughness and regular updates, which keep pace with evolving security threats. Developed with contributions from an extensive network of IT experts, these guidelines are both practical and effective, tailored to meet real-world security challenges.
In the context of Kubernetes, the CIS Benchmarks provide specific directions for fortifying the Kubernetes environment against vulnerabilities. This includes detailed recommendations on network configurations, access control measures, and monitoring protocols, all aimed at bolstering the security of Kubernetes clusters against unauthorized intrusions and various cyber threats.
The scope of CIS Benchmarks extends beyond just KubeAdmin installations. They also encompass distinct benchmarks tailored for Kubernetes services offered by major cloud providers, ensuring a wide-ranging and adaptable approach to cybersecurity.
Implementing CIS Benchmarks with a Hands-On Approach
My approach to cybersecurity emphasizes a hands-on methodology, prioritizing direct engagement over merely perusing downloaded PDFs that outline benchmarks.
The tool ‘kube-bench’ emerges as a standout choice in this context. It actively assesses your Kubernetes cluster against the latest security standards recommended in the CIS Benchmarks, ensuring both compliance and robust defense in the ever-evolving realm of cybersecurity.
Methods of Deploying kube-bench in Your Kubernetes Cluster
There are several effective strategies to deploy kube-bench within your Kubernetes environment. We will explore two primary methods: executing it as a Kubernetes Job and running it through a Docker container.
Executing kube-bench as a Kubernetes Job
To run kube-bench as a Kubernetes Job, you begin by visiting the kube-bench GitHub repository, where you can find the job.yaml
file. This file is designed to deploy kube-bench in this manner. The process involves logging into your control plane node and downloading the job.yaml
file, and then execute it via kubectl
.
wget https://raw.githubusercontent.com/aquasecurity/kube-bench/main/job.yaml
kubectl -f create -f job.yaml
An additional step is required if your objective is to ensure the job executes on your control plane. Typically, master nodes in Kubernetes are safeguarded with a taint to prevent the scheduling of workload pods on them.
To allow the kube-bench job to run on the master node, this taint must be removed, thus enabling the scheduling of the job on the master node.
To review the results produced by kube-bench, examine the output generated by the pod that was executed as part of the Kubernetes Job.
This output provides detailed insights into the security assessments kube-bench performs on your cluster.

The logs display a breakdown of the messages generated during the kube-bench execution, categorizing them into informational notices, warnings, failures, and passes. This categorization offers a comprehensive overview of the security assessment.
Each type of log message holds significance: ‘PASS’ indicates compliance with the benchmark, ‘FAIL’ shows non-compliance or potential vulnerabilities, ‘WARN’ suggests areas that might require attention or caution, and ‘INFO’ provides general information about the system’s state.
Understanding these distinctions is crucial for thoroughly analyzing your Kubernetes cluster’s security posture.
== Summary policies ==
0 checks PASS
0 checks FAIL
30 checks WARN
0 checks INFO
== Summary total ==
13 checks PASS
4 checks FAIL
36 checks WARN
0 checks INFO
The true advantage of kube-bench lies in its dual functionality: it identifies areas for improvement in your cluster and provides precise, actionable steps for implementation.
Below is an excerpt from the kube-bench logs illustrating this.
== Remediations node ==
4.1.1 Run the below command (based on the file location on your system) on the each worker node.
For example, chmod 600 /etc/systemd/system/kubelet.service.d/10-kubeadm.conf
4.1.3 Run the below command (based on the file location on your system) on the each worker node.
For example,
chmod 600 /etc/kubernetes/proxy.conf
Executing kube-bench as a docker container
You can also deploy kube-bench within your cluster utilizing Docker. If Docker is not installed on your system, you must install it first.
Once Docker is set up, execute the command below to run kube-bench. Additionally, ensure to refer to the latest kube-bench documentation for any updates to the command.
sudo docker run --pid=host -v /etc:/etc:ro -v /var:/var:ro -t docker.io/aquasec/kube-bench:latest --version 1.24
The output generated by running kube-bench using Docker will mirror the previously discussed results obtained by executing kube-bench as a Kubernetes Job.
Conclusion
Securing a Kubernetes cluster is a critical aspect of modern infrastructure management, and the CIS Benchmarks offer an invaluable roadmap to achieving this security.
This article has highlighted the importance of understanding and effectively implementing these benchmarks through practical tools like kube-bench.
Kube-bench stands out as an essential tool in this endeavor, offering a clear, actionable, and automated way to evaluate and enhance the security posture of your Kubernetes clusters. By providing specific insights and remediation steps, kube-bench demystifies the often complex process of aligning with the CIS Benchmarks. Whether deployed as a Kubernetes Job or through Docker, kube-bench simplifies identifying and addressing potential security weaknesses.
Remember, security in the digital landscape is not a one-time effort but a continuous process of improvement and adaptation. As you continue to fortify your Kubernetes environments, keep abreast of the latest updates and practices in cybersecurity.
The landscape constantly changes, and staying informed is critical to maintaining a solid defense.
Happy fortifying!