Exercise: kube-bench, then fix two controls
Host: controlplane (root) · Time: 10 min · Domain: Cluster Setup
Task
- Run kube-bench against the control plane.
- Fix these two failures if present:
1.2.1(anonymous auth) and1.2.7(profiling). - Leave the API server running.
Acceptance criteria
kube-bench run --targets master --check 1.2.1reports[PASS].- Same for
1.2.7. kubectl get --raw /healthzreturnsok.
Solution
sudo kube-bench run --targets master | grep -E '^\[FAIL\]' | head -20
sudo cp /etc/kubernetes/manifests/kube-apiserver.yaml /root/apiserver.bak
sudo vi /etc/kubernetes/manifests/kube-apiserver.yaml
In the command: list:
- --anonymous-auth=false
- --profiling=false
sleep 20
sudo crictl ps | grep kube-apiserver
kubectl get --raw /healthz
sudo kube-bench run --targets master --check 1.2.1
If the API server does not come back: sudo crictl logs <id> shows the parse
error, fix the indentation, wait 20 s. Never delete the manifest.