Skip to main content
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—
Control plane nodeWorker nodeCIS Benchmarkconsensus checklistOperatorkubectl · sshManaged clustere.g. EKS, GKE, AKSkube-bench JobhostPID · hostPathkube-apiserverstatic Podmanifests//etc/kubernetesJob logsPASS · FAIL · WARNetcdstatic PodAudit log--audit-log-pathkube-benchnode checkskubeletconfig.yamlchecklist
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.

IDCheckWhere to fixFix
1.1.1API server manifest permissions 600 or stricter/etc/kubernetes/manifests/kube-apiserver.yamlchmod 600
1.2.6--authorization-mode not AlwaysAllowAPI server manifest--authorization-mode=Node,RBAC
1.2.15--profiling=falseAPI server manifestAdd --profiling=false (also 1.3.2 controller manager, 1.4.1 scheduler)
1.2.16--audit-log-path is setAPI server manifestPolicy file, log path, plus hostPath volumes and mounts
4.2.1kubelet anonymous auth off/var/lib/kubelet/config.yamlauthentication.anonymous.enabled: false, restart kubelet
4.2.2kubelet authorization not AlwaysAllow/var/lib/kubelet/config.yamlauthorization.mode: Webhook, restart kubelet
ResultMeaningWhat to do
[PASS]Check ran and passedNothing
[FAIL]Check ran and failed (or a scored check could not run)Apply the remediation, rerun
[WARN]Needs attention, usually a manual checkRead the remediation, decide yourself
[INFO]Informational, or a skipped checkNothing

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

  1. kube-bench reports FAIL 1.2.15 (--profiling). Where do you make the change on a kubeadm cluster?
  2. You run kube-bench as a Job on a managed cluster such as EKS, and the control plane section is missing. Why?
  3. After adding --audit-log-path and --audit-policy-file to the manifest, the API server does not come back. What is the most likely cause?

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)