为集群扫描创建自定义 Benchmark 版本
每个 Benchmark 版本都定义了一组测试配置文件,这些文件定义了由 kube-bench 工具运行的 Compliance 测试。
rancher-compliance
应用安装了一些默认的 Benchmark 测试版本,这些版本列在了 Compliance 测试应用菜单下。
但是,某些 Kubernetes 集群可能需要自定义配置 Benchmark 测试。例如,Kubernetes 配置文件或证书的路径可能与上游 CIS Benchmark 的标准位置不同。
现在,你可以使用 rancher-compliance
应用来创建自定义 compliance 版本,从而运行集群扫描。
But in the following cases, a custom configuration or remediation may be required:
-
Non-standard file locations: When Kubernetes binaries, configuration or certificate paths deviate from upstream benchmark defaults.
Example: Unlike traditional Kubernetes, K3s bundles control plane components into a single binary. Therefore,
--anonymous-auth
flag presence and configuration should be verified in K3s' logs (journalctl
), not viakube-apiserver
process checks (ps
). -
Alternative risk mitigations: If a setup doesn’t meet a check but has an equally effective compensating control with justification. Or simply is not concerned by the check requirement because of its design.
Example: By default, K3s embeds the api server within the k3s process. There is no API server pod specification file, so verifying the latter’s file permissions is not required.
1. 准备自定义 Benchmark 版本 ConfigMap
要创建自定义 Benchmark 版本,你需要先创建一个包含 Benchmark 版本配置文件的 ConfigMap,并将其上传到要运行扫描的 Kubernetes 集群。
假设要添加一个名为 foo
的自定义 Benchmark 版本,你可以按照以下步骤准备自定义 Benchmark 版本 ConfigMap:
-
创建一个名为
foo
的目录,并在该目录中放置所有配置 YAML 文件, kube-bench 工具会搜索这些文件。例如,通用 CIS 1.5 Benchmark 版本的配置 YAML 文件在此处。 -
放置完整的
config.yaml
文件,其中包括所有要测试的组件。 -
将 Benchmark 版本名称添加到
config.yaml
的target_mapping
中:target_mapping: "foo": - "master" - "node" - "controlplane" - "etcd" - "policies"
-
通过创建 ConfigMap 将此目录上传到 Kubernetes 集群:
kubectl create configmap -n <namespace> foo --from-file=<path to directory foo>
2. 将自定义 Benchmark 版本添加到集群
-
在左上角,单击 ☰ > 集群管理。
-
在集群页面上,转到要添加自定义 Benchmark 的集群,然后单击 Explore。
-
在左侧导航栏中,单击 Compliance > Profile。
-
单击创建。
-
输入自定义 Benchmark 版本的名称和描述。
-
选择要应用 Benchmark 版本的集群提供商。
-
在下拉列表中选择你已上传的 ConfigMap。
-
添加最低和最高 Kubernetes 版本限制(如果有)。
-
单击创建。