OnCallReadyStart learning

Security and secrets Lesson 23.13 · Kubernetes Security (CKS) · 3 min read

kube-bench: the CIS benchmark as a checklist

In plain words

kube-bench is a building inspector with a printed checklist. It walks through the control plane, ticks each item PASS or FAIL, writes "a person must check this" next to the items it cannot judge by itself, and for every FAIL tells you exactly which file to open and which line to change so the next inspection passes. It never fixes anything itself; you do.

A security review you can run

The CIS Kubernetes Benchmark is a long list of "this flag should be set like this" checks for the control plane, etcd and the nodes. kube-bench (Aqua Security) runs them against a node and prints one line per check:

[INFO] 1 Control Plane Security Configuration
[INFO] 1.2 API Server
[FAIL] 1.2.15 Ensure that the --profiling argument is set to false (Automated)
[PASS] 1.2.16 Ensure that the --audit-log-path argument is set (Automated)
[WARN] 1.2.27 Ensure that the --encryption-provider-config argument is set as appropriate (Manual)
...
== Remediations master ==
1.2.15 Edit the API server pod specification file /etc/kubernetes/manifests/kube-apiserver.yaml
on the control plane node and set the below parameter.
--profiling=false
  • FAIL: an automated check that did not pass; the remediation says exactly what to change.
  • WARN: a Manual check - kube-bench cannot judge it; a person reads it and decides.
  • Run it on the node it checks, as root: sudo kube-bench run --targets master on cp-1; --check 1.2.15 re-runs one check after a fix.

A fresh kubeadm cluster fails several checks on purpose (profiling is on, no audit log): the defaults favour "works out of the box". Hardening is choosing, check by check.

On the exam: "fix the kube-bench FAILs in section 1.2 / 1.3 / 1.4" - edit the static pod manifests, wait for the restart, re-run the checks.

Why it helps

"Is the cluster hardened?" has no answer without a list. The CIS Kubernetes Benchmark is the list everyone uses, auditors ask for its results, and fixing kube-bench FAILs is a standard exam task. Knowing why a fresh cluster fails some checks on purpose also helps you explain hardening as a series of choices rather than a switch you flip once.

On the blog

FAQ

What is the CIS Kubernetes Benchmark?

A published list of hardening checks for the control plane, etcd and the nodes, mostly about component flags and file permissions. Each check has an id such as 1.2.15, a description, and a remediation that says how to fix it.

What does WARN mean in kube-bench?

It marks a Manual check: kube-bench cannot decide it automatically, so a person reads the check, looks at the configuration and decides. WARN is not a failure by itself, but it is not a pass either.

Where do I run it?

On the node it checks, as root, because it reads the manifests and configuration files there. For the control plane that is sudo kube-bench run --targets master on cp-1; worker nodes have their own target.

Why does a fresh kubeadm cluster FAIL checks?

Its defaults favour working out of the box: profiling is on and there is no audit log, for example. Hardening means choosing, check by check, which defaults to change for your environment. Each change is a deliberate trade-off you can explain.

How do I re-run one check?

With --check followed by the ids, for example sudo kube-bench run --targets master --check 1.2.15. That is quicker than the full run after a fix, and the summary counts only those checks. Run the full report again before you call the work done.

In an interview Mid

How do you check a cluster against a security baseline?

Run kube-bench on each node type: it runs the CIS Kubernetes Benchmark and prints PASS or FAIL for automated checks and WARN for manual ones, each with a remediation - for example 1.2.15 says set --profiling=false in the apiserver manifest. Fix the manifests, let the kubelet restart the static pods, then re-run with --check to prove the FAILs now pass.

Also asked: What is the difference between FAIL and WARN in kube-bench? · Why is profiling a security concern? · How would you run the benchmark continuously?

Practise this lesson in the terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.