kube-bench: run CIS Kubernetes Benchmark checks against a Kubernetes deployment (Aqua Security kube-bench)
kube-bench [run] [--targets master,node,etcd,controlplane,policies] [--check IDS] [flags]
kube-bench version
What it does
Runs the checks of the CIS Kubernetes Benchmark (https://www.cisecurity.org/benchmark/kubernetes/) that match the node it runs on: it reads the control plane manifests, the kubelet config and the file permissions, and prints [PASS], [FAIL], [WARN] or [INFO] per check, then the remediations and a summary. The benchmark version is chosen from the detected Kubernetes version.
Options you will use
-s, --targets LIST- Specify targets of the benchmark to run (run only). These names need to match the filenames in the cfg/<version> directory, e.g. --targets=master,etcd. If no targets are specified, run tests from all files in the cfg/<version> directory.
-c, --check LIST- A comma-delimited list of checks to run as specified in CIS document. Example --check="1.1.1,1.1.2".
-g, --group LIST- Run all the checks under this comma-delimited list of groups. Example --group="1.1".
--skip LIST- List of comma separated values of checks to be skipped.
--json- Prints the results as JSON.
--junit- Prints the results as JUnit.
--outputfile FILE- Writes the results to output file when run with --json or --junit.
--noremediations- Disable printing of remediations section.
--noresults- Disable printing of results section.
--nosummary- Disable printing of summary section.
--nototals- Disable printing of totals for failed, passed, ... checks across all sections.
--include-test-output- Prints the actual result when test fails.
--exit-code N- Specify the exit code for when checks fail (default 0: kube-bench exits 0 even with FAILs).
--benchmark VERSION- Manually specify CIS benchmark version. It would be an error to specify both --version and --benchmark flags.
--version VERSION- Manually specify Kubernetes version, automatically detected if unset. Not the tool's version: that is
kube-bench version. --config-dir, -D DIR- Config directory (the cfg/ tree with the benchmark YAML).
Examples
$ sudo kube-bench run --targets masterthe control plane checks, remediations, summary
$ sudo kube-bench run --targets master --check 1.2.15,1.2.16only these checks
$ sudo kube-bench run --targets node --json --outputfile node.jsona worker, as JSON
$ kube-bench versionthe tool's version
Gotchas
- WARN is not a pass: those are the Manual checks (a person has to judge them) and the automated ones kube-bench could not decide.
- kube-bench exits 0 even when checks FAIL, unless --exit-code is set: a CI gate needs --exit-code 1.
- Run it as root on the node itself (the control plane node for master checks, each worker for node checks): it reads /etc/kubernetes/manifests and the kubelet config files directly.
- A fix in a static pod manifest takes effect when the kubelet restarts that pod (it watches the directory); re-run kube-bench with --check to confirm.
On the blog
Try kube-bench in a real terminal Free, in your browser - a real Ubuntu terminal to try it in, with missions that check your work.