# CIS compliance CIS Hardening refers to the process of implementing security configurations that align with the benchmarks set by the [Center for Internet Security (CIS)][]. The open source tool [kube-bench][] is designed to automatically check whether your Kubernetes clusters are configured according to the [CIS Kubernetes Benchmark][]. This guide covers how to setup your {{product}} cluster with kube-bench. ## What you'll need This guide assumes the following: - You have a bootstrapped {{product}} cluster (see the [Getting Started] [getting-started-guide] guide) - You have root or sudo access to the machine ## Install kube-bench Download the latest [kube-bench release][] on your Kubernetes nodes. Make sure to select the appropriate binary version. For example, to download the Linux binary, use the following command. Replace `KB` by the version listed in the releases page. ``` KB=8.0 mkdir kube-bench cd kube-bench curl -L https://github.com/aquasecurity/kube-bench/releases/download/v0.$KB/kube-bench_0.$KB\_linux_amd64.tar.gz -o kube-bench_0.$KB\_linux_amd64.tar.gz ``` Extract the downloaded tarball and move the binary to a directory in your PATH: ``` tar -xvf kube-bench_0.$KB\_linux_amd64.tar.gz sudo mv kube-bench /usr/local/bin/ ``` Verify kube-bench installation. ``` kube-bench version ``` The output should list the version installed. Install `kubectl` and configure it to interact with the cluster. ```{warning} This will override your ~/.kube/config if you already have kubectl installed in your cluster. ``` ``` sudo snap install kubectl --classic mkdir ~/.kube/ sudo k8s kubectl config view --raw > ~/.kube/config export KUBECONFIG=~/.kube/config ``` Get CIS hardening checks applicable for {{product}}: ``` git clone -b ck8s https://github.com/canonical/kube-bench.git kube-bench-ck8s-cfg ``` Test-run kube-bench against {{product}}: ``` sudo -E kube-bench --version ck8s-dqlite-cis-1.24 --config-dir ./kube-bench-ck8s-cfg/cfg/ --config ./kube-bench-ck8s-cfg/cfg/config.yaml ``` ## Harden your deployments Before running a CIS Kubernetes audit, it is essential to first harden your {{product}} deployment to minimize vulnerabilities and ensure compliance with industry best practices, as defined by the CIS Kubernetes Benchmark. ### Control plane nodes Run the following commands on your control plane nodes. #### Configure auditing Create an audit-policy.yaml file under `/var/snap/k8s/common/etc/` and specify the level of auditing you desire based on the [upstream instructions][]. Here is a minimal example of such a policy file. ``` sudo sh -c 'cat >/var/snap/k8s/common/etc/audit-policy.yaml <>/var/snap/k8s/common/args/kube-apiserver </var/snap/k8s/common/etc/eventconfig.yaml </var/snap/k8s/common/etc/admission-control-config-file.yaml <>/var/snap/k8s/common/args/kube-apiserver <>/var/snap/k8s/common/args/kubelet < [Center for Internet Security (CIS)]:https://www.cisecurity.org/ [kube-bench]:https://aquasecurity.github.io/kube-bench/v0.6.15/ [CIS Kubernetes Benchmark]:https://www.cisecurity.org/benchmark/kubernetes [getting-started-guide]: /snap/tutorial/getting-started [kube-bench release]: https://github.com/aquasecurity/kube-bench/releases [upstream instructions]:https://kubernetes.io/docs/tasks/debug/debug-cluster/audit/ [rate limits]:https://kubernetes.io/docs/reference/config-api/apiserver-eventratelimit.v1alpha1