Security & multi-tenancyLesson 10 of 13
CIS Kubernetes Benchmark and kube-bench (CKS)
This covers "Use CIS benchmark to review the security configuration of Kubernetes components" in the CKS Cluster Setup domain. We run kube-bench on a kubeadm cluster, read what fails, fix it in the right file and run it again.
Checking—
FAIL—
Fix—
RequestResponse / reportWatchAppears in a later step
What you will learn
- What the CIS Kubernetes Benchmark is and how its sections are laid out
- Running kube-bench as a Job and reading PASS, FAIL, WARN and remediation
- Fixing API server findings in the static Pod manifest
- Fixing kubelet findings in /var/lib/kubelet/config.yaml
- What you can and cannot check on a managed cluster
Common findings on a kubeadm cluster
Check IDs below are from kube-bench's cis-2.0 config. Numbers can shift between benchmark versions, so match on the text too.
| ID | Check | Where to fix | Fix |
|---|---|---|---|
| 1.1.1 | API server manifest permissions 600 or stricter | /etc/kubernetes/manifests/kube-apiserver.yaml | chmod 600 |
| 1.2.6 | --authorization-mode not AlwaysAllow | API server manifest | --authorization-mode=Node,RBAC |
| 1.2.15 | --profiling=false | API server manifest | Add --profiling=false (also 1.3.2 controller manager, 1.4.1 scheduler) |
| 1.2.16 | --audit-log-path is set | API server manifest | Policy file, log path, plus hostPath volumes and mounts |
| 4.2.1 | kubelet anonymous auth off | /var/lib/kubelet/config.yaml | authentication.anonymous.enabled: false, restart kubelet |
| 4.2.2 | kubelet authorization not AlwaysAllow | /var/lib/kubelet/config.yaml | authorization.mode: Webhook, restart kubelet |
| Result | Meaning | What to do |
|---|---|---|
[PASS] | Check ran and passed | Nothing |
[FAIL] | Check ran and failed (or a scored check could not run) | Apply the remediation, rerun |
[WARN] | Needs attention, usually a manual check | Read the remediation, decide yourself |
[INFO] | Informational, or a skipped check | Nothing |
Try it yourself
# Control plane checks (Job pinned to a control plane node)
kubectl apply -f https://raw.githubusercontent.com/aquasecurity/kube-bench/main/job-master.yaml
kubectl wait --for=condition=complete job/kube-bench-master --timeout=120s
kubectl logs job/kube-bench-master | grep '^\[FAIL\]' # failing checks
kubectl logs job/kube-bench-master | grep -A4 '^== Summary' # PASS/FAIL/WARN/INFO counts
# Worker checks
kubectl apply -f https://raw.githubusercontent.com/aquasecurity/kube-bench/main/job-node.yaml
kubectl logs job/kube-bench-node | grep -A3 '4.2.1'
# Fix on the control plane node
sudo cp /etc/kubernetes/manifests/kube-apiserver.yaml /root/kube-apiserver.yaml.bak # backup OUTSIDE manifests/
sudo vi /etc/kubernetes/manifests/kube-apiserver.yaml # e.g. add --profiling=false
sudo crictl ps --name kube-apiserver # wait for the new container
# Rerun
kubectl delete job kube-bench-master && kubectl apply -f https://raw.githubusercontent.com/aquasecurity/kube-bench/main/job-master.yaml
Check yourself
Further reading: CIS Kubernetes Benchmark · kube-bench · Running kube-bench · Kubelet authentication and authorization · Audit Logs · Building a cluster with kubeadm (CKA) · Viewing the cluster through the 4Cs and a threat model (KCSA·KCNA)