# Kube-Bench ###### tags: `CKS Day2` ## Practice ### 1.Installation on Ubuntu/Debian: ``` curl -L https://github.com/aquasecurity/kube-bench/releases/download/v0.3.1/kube-bench_0.3.1_linux_amd64.deb -o kube-bench_0.3.1_linux_amd64.deb sudo apt install ./kube-bench_0.3.1_linux_amd64.deb -f ``` ### 2.Run Kube-bench检测 我们可以使用Kube-Bench对一个master执行版本自动检测: ``` kube-bench master ``` 使用Kube-Bench针对Kubernete v1.20执行worker节点测试: ``` kube-bench node --version 1.20 ``` 指定“--benchmark”来运行指定的CIS Benchmark版本: ``` kube-bench node --benchmark cis-1.5 ``` 指定CIS Benchmark的target,比如说master、node、etcd等,你可以运行“run --targets”子命令: ``` kube-bench --benchmark cis-1.5 run --targets master,etcd ``` ### 3.请大家解决如下问题 ``` 1.1.12 Ensure that the etcd data directory ownership is set to etcd:etcd 1.3.2 Ensure that the --profiling argument is set to false 4.1.3 Ensure that the proxy kubeconfig file permissions are set to 644 or more restrictive 4.1.4 Ensure that the proxy kubeconfig file ownership is set to root:root ``` ## 排除测试项目 如果一些项目不适合我们的场景或者不适合我们当前版本,比如 1.2.21 1.3.2 1.4.1 三个测试项,是要求 /etc/kubernetes/manifests/ 目录下的三个文件kube-controller-manager.yaml kube-apiserver.yaml kube-scheduler.yaml ,需要设置参数 --profiling=false 通过查询官网,这个参数在1.16 k8s,kube-scheduler 已经弃用,apiserver和controller-manager没有说弃用。 所以我们把 1.4.1 这项忽略掉。 kubernetes官方说明: https://v1-16.docs.kubernetes.io/zh/docs/reference/command-line-tools-reference/kube-scheduler/ --profiling 弃用: 通过 Web 界面主机启用配置文件:port/debug/pprof/ 修改以忽略测试项的方法是: cd /etc/kube-bench/cfg/cis-1.5 编辑 master.yaml 找到 1.4.1 在id下面加一行参数 ![](https://i.imgur.com/B6ZPoJO.png)