使用 ScanSuite

ScanSuite 是用于批量管理合规扫描的资源。它关联多个 profile,并从一个共享模板创建子 Scan 资源。

何时使用 ScanSuite

当您需要:

  • 一起管理多个 profile
  • 安排定期的合规扫描
  • 将相同的扫描模板应用于一组子 Scan 资源
  • 作为一个整体暂停、恢复或触发一批相关扫描

时,请使用 ScanSuite

如果您只需要一个 profile 和一个 Scan 资源,请改用使用 Scan

基本 ScanSuite 示例

apiVersion: compliance.security.alauda.io/v1alpha1
kind: ScanSuite
metadata:
  name: test-scan-suite
  namespace: compliance-system
spec:
  profiles:
    - stig-k8s-api-server
    - stig-k8s-control-plane
    - stig-k8s-general
    - stig-k8s-kubelet
  maxHistoricalResults: 3
  scanTemplate:
    scanType: node
    nodeScopeStrategy: auto
    targetNodeRoles:
      - control-plane
    nodeSelector:
      node-role.kubernetes.io/control-plane: ""

定时 ScanSuite 示例

apiVersion: compliance.security.alauda.io/v1alpha1
kind: ScanSuite
metadata:
  name: scheduled-scan-suite
  namespace: compliance-system
spec:
  profiles:
    - stig-k8s-api-server
    - stig-k8s-control-plane
  schedule: "0 2 * * *"
  maxHistoricalResults: 3
  scanTemplate:
    scanType: node
    nodeScopeStrategy: auto

带邮件通知的 ScanSuite

apiVersion: compliance.security.alauda.io/v1alpha1
kind: ScanSuite
metadata:
  name: notify-scan-suite
  namespace: compliance-system
spec:
  profiles:
    - stig-k8s-api-server
  maxHistoricalResults: 3
  scanTemplate:
    scanType: node
    nodeScopeStrategy: auto
  reportDelivery:
    email:
      enabled: true
      recipientsRef:
        name: compliance-mail-recipients

ScanSuite 参数

下表描述了 ScanSuite 资源的顶层参数:

参数类型描述
spec.profilesarrayScanSuite 关联的 profile 列表。控制器会为这些 profile 创建子 Scan 资源。
spec.schedulestring可选。使用 cron 语法配置定时执行。例如:"0 2 * * *" 表示每天凌晨 2 点执行。如果未设置,ScanSuite 仅在手动触发时运行。
spec.pausedboolean可选。暂停 ScanSuite。设置为 true 可临时停止执行,设置回 false 可恢复执行。
spec.maxHistoricalResultsint可选。为每个子 Scan 保留的历史结果数量(默认:5)。
spec.scanTemplateobject可选。应用于由 ScanSuite 创建的子 Scan 资源的模板。
spec.reportDeliveryobject可选。生成报告的投递配置。目前支持邮件投递。

扫描模板参数

下表描述了 spec.scanTemplate 下可用的参数:

参数类型作用域描述
spec.scanTemplate.scanTypestringk8s, os支持 platformnodeall。在 platform 模式下,系统仅扫描 Kubernetes 资源;在 node 模式下,系统仅扫描节点文件。
spec.scanTemplate.nodeScopeStrategystringk8s节点选择模式。支持 automanual。在 auto 模式下,节点根据规则特定的范围定义选择;在 manual 模式下,所有规则均在指定节点上执行。
spec.scanTemplate.targetNodeRolesarrayk8s, os可选。限制节点角色。有效值包括 control-planeworker。配置后参与节点过滤,并与 nodeScopeStrategy 取交集。
spec.scanTemplate.nodeSelectorobjectk8s, os可选。使用节点标签进行选择。配置后参与节点过滤,并与 nodeScopeStrategy 取交集。

对于 ScanSuite,节点选择和调度字段配置在 spec.scanTemplate 下,而非直接在 spec 下。

有关共享行为和 profile 特定限制,请参见节点选择和调度

报告投递参数

如果配置了 spec.reportDelivery,以下字段用于邮件投递:

参数类型描述
spec.reportDelivery.email.enabledboolean启用 ScanSuite 生成报告的邮件投递功能。
spec.reportDelivery.email.recipientsRef.namestring定义邮件接收者的 ConfigMap 名称。

ScanSuite 注解

以下注解可用于控制 ScanSuite 执行:

注解作用域描述
compliance.security.alauda.io/force-suite: "true"k8s, os手动触发立即执行 ScanSuite。完成后自动重置为 false

监控 ScanSuite 执行

使用 ScanSuite 查看批量资源,使用 Scan 查看由其创建的子执行。

# 查看 ScanSuite 状态
kubectl get scansuite test-scan-suite -n compliance-system -o yaml

# 查看 ScanSuite 创建的子 Scan
kubectl get scan -n compliance-system -o wide