kube-bench checks the CIS Kubernetes Benchmark automatically: process flags, file permissions, configuration files. [FAIL] means checked automatically and violated, [WARN] means check manually. Understand first, then change, then check again.
Symptom
sudo kube-bench run --targets=master --benchmark=cis-1.12 > master.txt 2>&1 sed -n '/== Summary master ==/,/INFO/p' master.txt grep "^\[FAIL\]" master.txt | cut -c1-62 == Summary master == 39 checks PASS 10 checks FAIL 11 checks WARN 0 checks INFO [FAIL] 1.1.12 Ensure that the etcd data directory ownership is [FAIL] 1.2.15 Ensure that the --profiling argument is set to f [FAIL] 1.3.2 Ensure that the --profiling argument is set to fa [FAIL] 1.4.1 Ensure that the --profiling argument is set to fa
1.2 is the API server, 1.3 the controller manager, 1.4 the scheduler. Chapter 4 checks the workers.
Diagnosis
Run just the one finding with --check. The remediation names file and parameter; --include-test-output also shows what kube-bench found.
sudo kube-bench run --targets=master --benchmark=cis-1.12 --check=1.4.1 \ 2>/dev/null | sed -n '/== Remediations/,/^$/p' | cut -c1-80 == Remediations master == 1.4.1 Edit the Scheduler pod specification file /etc/kubernetes/manifests/kube-s on the control plane node and set the below parameter. --profiling=false
Causes
Assuming default version 1.18Wrong benchmark under sudo
Under sudo the kubeconfig is missing, kube-bench assumes version 1.18 and checks against an old benchmark. So name the benchmark explicitly with --benchmark.
Warning: Kubernetes version was not auto-detected because kubectl could not connect to the Kubernetes server. ... Assuming default version 1.18
--profilingFlag missing in the running process
kube-bench reads the flags from the running process list, not from the manifest. Only once the pod has restarted does FAIL turn into PASS.
4.1.1 / 4.1.9Permissions of the kubelet files
On the workers the benchmark asks for chmod 600 on the kubelet unit and /var/lib/kubelet/config.yaml. There kube-bench runs as a job.
k -n tag03 logs job/kube-bench-node | grep -E "^\[FAIL\]" | cut -c1-62 [FAIL] 4.1.1 Ensure that the kubelet service file permissions [FAIL] 4.1.9 If the kubelet config.yaml configuration file is
Fix
sudo cp /etc/kubernetes/manifests/*.yaml ~/cks/tag03/backup/ M=/etc/kubernetes/manifests sudo sed -i 's/ - --leader-elect=true/&\n - --profiling=false/' \ $M/kube-controller-manager.yaml $M/kube-scheduler.yaml sudo kube-bench run --targets=master --benchmark=cis-1.12 \ --check=1.1.12,1.2.15,1.3.2,1.4.1 2>/dev/null | grep "^\[PASS\]" | cut -c1-62 [PASS] 1.1.12 Ensure that the etcd data directory ownership is [PASS] 1.2.15 Ensure that the --profiling argument is set to f [PASS] 1.3.2 Ensure that the --profiling argument is set to fa [PASS] 1.4.1 Ensure that the --profiling argument is set to fa
Don't: Applying every remediation blindly. In the course --kubelet-certificate-authority (1.2.5) breaks logs and exec because the kubelet's serving certificate is self-signed. You document such findings as a deliberate exception.
CKS hands-on, day 3: install kube-bench, read FAIL and remediation, harden the control plane and workers.
Go to day 3 →
FAQ
What error do I get if I fix 1.2.5 blindly?
logs and exec fail with "x509: cannot validate certificate … because it doesn't contain any IP SANs".