OnCallReadyStart learning

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 master

the control plane checks, remediations, summary

$ sudo kube-bench run --targets master --check 1.2.15,1.2.16

only these checks

$ sudo kube-bench run --targets node --json --outputfile node.json

a worker, as JSON

$ kube-bench version

the tool's version

Gotchas

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.