Documentation survey

为集群扫描创建自定义 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 via kube-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:

  1. 创建一个名为 foo 的目录,并在该目录中放置所有配置 YAML 文件, kube-bench 工具会搜索这些文件。例如,通用 CIS 1.5 Benchmark 版本的配置 YAML 文件在此处

  2. 放置完整的 config.yaml 文件,其中包括所有要测试的组件。

  3. 将 Benchmark 版本名称添加到 config.yamltarget_mapping 中:

    target_mapping:
      "foo":
        - "master"
        - "node"
        - "controlplane"
        - "etcd"
        - "policies"
  4. 通过创建 ConfigMap 将此目录上传到 Kubernetes 集群:

    kubectl create configmap -n <namespace> foo --from-file=<path to directory foo>

2. 将自定义 Benchmark 版本添加到集群

  1. 在左上角,单击 ☰ > 集群管理

  2. 集群页面上,转到要添加自定义 Benchmark 的集群,然后单击 Explore

  3. 在左侧导航栏中,单击 Compliance > Profile

  4. 单击创建

  5. 输入自定义 Benchmark 版本的名称和描述。

  6. 选择要应用 Benchmark 版本的集群提供商。

  7. 在下拉列表中选择你已上传的 ConfigMap。

  8. 添加最低和最高 Kubernetes 版本限制(如果有)。

  9. 单击创建

3. 为自定义 Benchmark 版本创建新配置文件

要使用你的自定义 Benchmark 版本运行扫描,你需要添加一个指向此 Benchmark 版本的新配置文件:

  1. 在左上角,单击 ☰ > 集群管理

  2. 集群页面上,转到要添加自定义 Benchmark 的集群,然后单击 Explore

  3. 在左侧导航栏中,单击 Compliance > Profile

  4. 单击创建

  5. 设置名称和描述。在本例中,我们将其命名为 foo-profile

  6. 在下拉列表中选择 Benchmark 版本。

  7. 单击创建

4. 使用自定义 Benchmark 版本运行扫描

指向你的自定义 Benchmark 版本的 foo 配置文件创建完成后,你可以创建一个新的扫描,从而在 Benchmark 版本中运行自定义测试。

要运行扫描:

  1. 在左上角,单击 ☰ > 集群管理

  2. 集群页面上,转到要添加自定义 Benchmark 的集群,然后单击 Explore

  3. 在左侧导航栏中,单击 Compliance > Profile

  4. 单击创建

  5. 选择新的集群扫描配置文件。

  6. 单击创建

结果:已生成带有扫描结果的报告。如需查看结果,请单击显示的扫描名称。