5.4. 高级 Clair 配置


使用以下部分中的步骤配置高级 Clair 设置。

5.4.1. 非受管 Clair 配置

Red Hat Quay 用户可以使用 Red Hat Quay OpenShift Container Platform Operator 运行非受管 Clair 配置。此功能允许用户创建非受管 Clair 数据库,或者在没有非受管数据库的情况下运行其自定义 Clair 配置。

非受管 Clair 数据库允许 Red Hat Quay Operator 在地理复制环境中工作,其中多个 Operator 实例必须与同一数据库通信。当用户需要集群外的高可用性(HA) Clair 数据库时,也可以使用非受管 Clair 数据库。

5.4.1.1. 使用非受管 Clair 数据库运行自定义 Clair 配置

使用以下步骤将 Clair 数据库设置为 unmanaged。

流程

  • 在 Quay Operator 中,将 QuayRegistry 自定义资源的 clairpostgres 组件设置为 managed: false

    apiVersion: quay.redhat.com/v1
    kind: QuayRegistry
    metadata:
      name: quay370
    spec:
      configBundleSecret: config-bundle-secret
      components:
        - kind: objectstorage
          managed: false
        - kind: route
          managed: true
        - kind: tls
          managed: false
        - kind: clairpostgres
          managed: false

5.4.1.2. 使用非受管 Clair 数据库配置自定义 Clair 数据库

用于 OpenShift Container Platform 的 Red Hat Quay Operator 允许用户提供自己的 Clair 数据库。

使用以下步骤创建自定义 Clair 数据库。

注意

以下流程使用 SSL/TLS 认证设置 Clair。要查看没有使用 SSL/TSL 认证设置 Clair 的类似流程,请参阅"使用受管 Clair 配置自定义 Clair 数据库"。

流程

  1. 输入以下命令创建一个包含 clair-config.yaml 的 Quay 配置捆绑包 secret:

    $ oc create secret generic --from-file config.yaml=./config.yaml --from-file extra_ca_cert_rds-ca-2019-root.pem=./rds-ca-2019-root.pem --from-file clair-config.yaml=./clair-config.yaml --from-file ssl.cert=./ssl.cert --from-file ssl.key=./ssl.key config-bundle-secret

    Clair config.yaml 文件示例

    indexer:
        connstring: host=quay-server.example.com port=5432 dbname=quay user=quayrdsdb password=quayrdsdb sslrootcert=/run/certs/rds-ca-2019-root.pem sslmode=verify-ca
        layer_scan_concurrency: 6
        migrations: true
        scanlock_retry: 11
    log_level: debug
    matcher:
        connstring: host=quay-server.example.com port=5432 dbname=quay user=quayrdsdb password=quayrdsdb sslrootcert=/run/certs/rds-ca-2019-root.pem sslmode=verify-ca
        migrations: true
    metrics:
        name: prometheus
    notifier:
        connstring: host=quay-server.example.com port=5432 dbname=quay user=quayrdsdb password=quayrdsdb sslrootcert=/run/certs/rds-ca-2019-root.pem sslmode=verify-ca
        migrations: true

    注意
    • 数据库证书挂载到 clair-config.yaml 中的 Clair 应用程序 pod 上的 /run/certs/rds-ca-2019-root.pem 下。它必须在配置 clair-config.yaml 时指定。
    • Clair on OpenShift config 中包括了一个 clair-config.yaml 示例。
  2. clair-config.yaml 文件添加到捆绑包 secret 中,例如:

    apiVersion: v1
    kind: Secret
    metadata:
      name: config-bundle-secret
      namespace: quay-enterprise
    data:
      config.yaml: <base64 encoded Quay config>
      clair-config.yaml: <base64 encoded Clair config>
      extra_ca_cert_<name>: <base64 encoded ca cert>
      ssl.crt: <base64 encoded SSL certificate>
      ssl.key: <base64 encoded SSL private key>
    注意

    更新后,提供的 clair-config.yaml 文件会挂载到 Clair pod 中。不提供的任何字段都会使用 Clair 配置模块自动填充默认值。

  3. 您可以点击 Build History 页面中的提交或运行 oc get pods -n <namespace > 来检查 Clair pod 的状态。例如:

    $ oc get pods -n <namespace>

    输出示例

    NAME                                               READY   STATUS    RESTARTS   AGE
    f192fe4a-c802-4275-bcce-d2031e635126-9l2b5-25lg2   1/1     Running   0          7s

5.4.2. 使用受管 Clair 数据库运行自定义 Clair 配置

在某些情况下,用户可能希望使用受管 Clair 数据库运行自定义 Clair 配置。这在以下情况中很有用:

  • 当用户想要禁用特定的更新器资源时。
  • 当用户在断开连接的环境中运行 Red Hat Quay 时。有关在断开连接的环境中运行 Clair 的更多信息,请参阅 在 air-gapped OpenShift 集群中配置对 Clair 数据库的访问

    注意
    • 如果您在断开连接的环境中运行 Red Hat Quay,则 clair-config.yamlairgap 参数必须设置为 true
    • 如果您在断开连接的环境中运行 Red Hat Quay,您应该禁用所有更新器组件。

5.4.2.1. 将 Clair 数据库设置为 managed

使用以下步骤将 Clair 数据库设置为 managed。

流程

  • 在 Quay Operator 中,将 QuayRegistry 自定义资源的 clairpostgres 组件设置为 managed: true

    apiVersion: quay.redhat.com/v1
    kind: QuayRegistry
    metadata:
      name: quay370
    spec:
      configBundleSecret: config-bundle-secret
      components:
        - kind: objectstorage
          managed: false
        - kind: route
          managed: true
        - kind: tls
          managed: false
        - kind: clairpostgres
          managed: true

5.4.2.2. 使用受管 Clair 配置配置自定义 Clair 数据库

用于 OpenShift Container Platform 的 Red Hat Quay Operator 允许用户提供自己的 Clair 数据库。

使用以下步骤创建自定义 Clair 数据库。

流程

  1. 输入以下命令创建一个包含 clair-config.yaml 的 Quay 配置捆绑包 secret:

    $ oc create secret generic --from-file config.yaml=./config.yaml --from-file extra_ca_cert_rds-ca-2019-root.pem=./rds-ca-2019-root.pem --from-file clair-config.yaml=./clair-config.yaml config-bundle-secret

    Clair config.yaml 文件示例

    indexer:
        connstring: host=quay-server.example.com port=5432 dbname=quay user=quayrdsdb password=quayrdsdb sslmode=disable
        layer_scan_concurrency: 6
        migrations: true
        scanlock_retry: 11
    log_level: debug
    matcher:
        connstring: host=quay-server.example.com port=5432 dbname=quay user=quayrdsdb password=quayrdsdb sslmode=disable
        migrations: true
    metrics:
        name: prometheus
    notifier:
        connstring: host=quay-server.example.com port=5432 dbname=quay user=quayrdsdb password=quayrdsdb sslmode=disable
        migrations: true

    注意
    • 数据库证书挂载到 clair-config.yaml 中的 Clair 应用程序 pod 上的 /run/certs/rds-ca-2019-root.pem 下。它必须在配置 clair-config.yaml 时指定。
    • Clair on OpenShift config 中包括了一个 clair-config.yaml 示例。
  2. clair-config.yaml 文件添加到捆绑包 secret 中,例如:

    apiVersion: v1
    kind: Secret
    metadata:
      name: config-bundle-secret
      namespace: quay-enterprise
    data:
      config.yaml: <base64 encoded Quay config>
      clair-config.yaml: <base64 encoded Clair config>
    注意
    • 更新后,提供的 clair-config.yaml 文件会挂载到 Clair pod 中。不提供的任何字段都会使用 Clair 配置模块自动填充默认值。
  3. 您可以点击 Build History 页面中的提交或运行 oc get pods -n <namespace > 来检查 Clair pod 的状态。例如:

    $ oc get pods -n <namespace>

    输出示例

    NAME                                               READY   STATUS    RESTARTS   AGE
    f192fe4a-c802-4275-bcce-d2031e635126-9l2b5-25lg2   1/1     Running   0          7s

5.4.3. 在断开连接的环境中的 Clair

Clair 使用一组名为 updaters 的组件来处理从各种漏洞数据库获取和解析数据。默认设置更新程序,以直接从互联网拉取漏洞数据,并可以立即使用。但是,一些用户可能需要 Red Hat Quay 在断开连接的环境中运行,或者在没有直接访问互联网的环境中运行。Clair 通过处理不同类型的更新工作流来支持断开连接的环境。这可以通过使用 clairctl 命令行界面工具来工作,该工具使用开放主机从互联网获取更新器数据,安全地将数据传送到隔离的主机上,然后将隔离主机上的更新器数据变为 Clair。

使用本指南在断开连接的环境中部署 Clair。

注意

目前,Clair 增强数据是 CVSS 数据。目前在断开连接的环境中不支持增强数据。

有关 Clair updaters 的更多信息,请参阅"Clair updaters"。

5.4.3.1. 在断开连接的 OpenShift Container Platform 集群中设置 Clair

使用以下步骤在断开连接的 OpenShift Container Platform 集群中设置 OpenShift Container Platform 置备的 Clair pod。

5.4.3.1.1. 为 OpenShift Container Platform 部署安装 clairctl 命令行工具

使用以下步骤为 OpenShift Container Platform 部署安装 clairctl CLI 工具。

流程

  1. 输入以下命令在 OpenShift Container Platform 集群中为 Clair 部署安装 clairctl 程序:

    $ oc -n quay-enterprise exec example-registry-clair-app-64dd48f866-6ptgw -- cat /usr/bin/clairctl > clairctl
    注意

    未正式,可以下载 clairctl 工具

  2. 设置 clairctl 文件的权限,以便用户可以由用户执行并运行,例如:

    $ chmod u+x ./clairctl
5.4.3.1.2. 为 OpenShift Container Platform 上的 Clair 部署检索和解码 Clair 配置 secret

使用以下步骤检索和解码 OpenShift Container Platform 上置备的 Clair 实例的配置 secret。

先决条件

  • 已安装 clairctl 命令行工具工具。

流程

  1. 输入以下命令来检索和解码配置 secret,然后将其保存到 Clair 配置 YAML 中:

    $ oc get secret -n quay-enterprise example-registry-clair-config-secret  -o "jsonpath={$.data['config\.yaml']}" | base64 -d > clair-config.yaml
  2. 更新 clair-config.yaml 文件,以便 disable_updatersairgap 参数设置为 true,例如:

    ---
    indexer:
      airgap: true
    ---
    matcher:
      disable_updaters: true
    ---
5.4.3.1.3. 从连接的 Clair 实例导出更新程序捆绑包

使用以下步骤从可访问互联网的 Clair 实例导出 updaters 捆绑包。

先决条件

  • 已安装 clairctl 命令行工具工具。
  • 您已检索并解码了 Clair 配置 secret,并将其保存到 Clair config.yaml 文件中。
  • 在 Clair config.yaml 文件中,disable_updatersairgap 参数被设置为 true

流程

  • 从可访问互联网的 Clair 实例中,使用 clairctl CLI 工具和配置文件导出更新器捆绑包。例如:

    $ ./clairctl --config ./config.yaml export-updaters updates.gz
5.4.3.1.4. 在断开连接的 OpenShift Container Platform 集群中配置对 Clair 数据库的访问

使用以下步骤在断开连接的 OpenShift Container Platform 集群中配置对 Clair 数据库的访问。

先决条件

  • 已安装 clairctl 命令行工具工具。
  • 您已检索并解码了 Clair 配置 secret,并将其保存到 Clair config.yaml 文件中。
  • 在 Clair config.yaml 文件中,disable_updatersairgap 参数被设置为 true
  • 您已从可访问互联网的 Clair 实例导出 updaters 捆绑包。

流程

  1. 使用 oc CLI 工具确定 Clair 数据库服务,例如:

    $ oc get svc -n quay-enterprise

    输出示例

    NAME                                  TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)                             AGE
    example-registry-clair-app            ClusterIP      172.30.224.93    <none>        80/TCP,8089/TCP                     4d21h
    example-registry-clair-postgres       ClusterIP      172.30.246.88    <none>        5432/TCP                            4d21h
    ...

  2. 转发 Clair 数据库端口,使其可从本地机器访问。例如:

    $ oc port-forward -n quay-enterprise service/example-registry-clair-postgres 5432:5432
  3. 更新 Clair config.yaml 文件,例如:

    indexer:
        connstring: host=localhost port=5432 dbname=postgres user=postgres password=postgres sslmode=disable 1
        scanlock_retry: 10
        layer_scan_concurrency: 5
        migrations: true
        scanner:
          repo:
            rhel-repository-scanner: 2
              repo2cpe_mapping_file: /data/cpe-map.json
          package:
            rhel_containerscanner: 3
              name2repos_mapping_file: /data/repo-map.json
    1
    在多 connstring 字段中使用 localhost 替换 host 的值。
    2
    有关 rhel-repository-scanner 参数的更多信息,请参阅 "Mapping repository to Common Product Enumeration"。
    3
    有关 rhel_containerscanner 参数的更多信息,请参阅 "Mapping repository to Common Product Enumeration information"。
5.4.3.1.5. 将 updaters 捆绑包导入到断开连接的 OpenShift Container Platform 集群中

使用以下步骤将更新器捆绑包导入到断开连接的 OpenShift Container Platform 集群中。

先决条件

  • 已安装 clairctl 命令行工具工具。
  • 您已检索并解码了 Clair 配置 secret,并将其保存到 Clair config.yaml 文件中。
  • 在 Clair config.yaml 文件中,disable_updatersairgap 参数被设置为 true
  • 您已从可访问互联网的 Clair 实例导出 updaters 捆绑包。
  • 您已将更新器捆绑包传送到断开连接的环境中。

流程

  • 使用 clairctl CLI 工具将 updaters 捆绑包导入到 OpenShift Container Platform 部署的 Clair 数据库中。例如:

    $ ./clairctl --config ./clair-config.yaml import-updaters updates.gz

5.4.3.2. 为断开连接的 OpenShift Container Platform 集群设置 Clair 的自我管理部署

使用以下步骤为断开连接的 OpenShift Container Platform 集群设置 Clair 的自我管理部署。

5.4.3.2.1. 为 OpenShift Container Platform 上的自我管理的 Clair 部署安装 clairctl 命令行工具

使用以下步骤在 OpenShift Container Platform 上安装 clairctl CLI 工具进行自我管理的 Clair 部署。

流程

  1. 使用 podman cp 命令为自我管理的 Clair 部署安装 clairctl 程序,例如:

    $ sudo podman cp clairv4:/usr/bin/clairctl ./clairctl
  2. 设置 clairctl 文件的权限,以便用户可以由用户执行并运行,例如:

    $ chmod u+x ./clairctl
5.4.3.2.2. 为断开连接的 OpenShift Container Platform 集群部署自我管理的 Clair 容器

使用以下步骤为断开连接的 OpenShift Container Platform 集群部署自我管理的 Clair 容器。

先决条件

  • 已安装 clairctl 命令行工具工具。

流程

  1. 为您的 Clair 配置文件创建一个文件夹,例如:

    $ mkdir /etc/clairv4/config/
  2. 创建一个 Clair 配置文件,将 disable_updaters 参数设置为 true,例如:

    ---
    indexer:
      airgap: true
    ---
    matcher:
      disable_updaters: true
    ---
  3. 使用容器镜像启动 Clair,从您创建的文件中挂载在配置中:

    $ sudo podman run -it --rm --name clairv4 \
    -p 8081:8081 -p 8088:8088 \
    -e CLAIR_CONF=/clair/config.yaml \
    -e CLAIR_MODE=combo \
    -v /etc/clairv4/config:/clair:Z \
    registry.redhat.io/quay/clair-rhel8:v3.9.7
5.4.3.2.3. 从连接的 Clair 实例导出更新程序捆绑包

使用以下步骤从可访问互联网的 Clair 实例导出 updaters 捆绑包。

先决条件

  • 已安装 clairctl 命令行工具工具。
  • 您已部署了 Clair。
  • 在 Clair config.yaml 文件中,disable_updatersairgap 参数被设置为 true

流程

  • 从可访问互联网的 Clair 实例中,使用 clairctl CLI 工具和配置文件导出更新器捆绑包。例如:

    $ ./clairctl --config ./config.yaml export-updaters updates.gz
5.4.3.2.4. 在断开连接的 OpenShift Container Platform 集群中配置对 Clair 数据库的访问

使用以下步骤在断开连接的 OpenShift Container Platform 集群中配置对 Clair 数据库的访问。

先决条件

  • 已安装 clairctl 命令行工具工具。
  • 您已部署了 Clair。
  • 在 Clair config.yaml 文件中,disable_updatersairgap 参数被设置为 true
  • 您已从可访问互联网的 Clair 实例导出 updaters 捆绑包。

流程

  1. 使用 oc CLI 工具确定 Clair 数据库服务,例如:

    $ oc get svc -n quay-enterprise

    输出示例

    NAME                                  TYPE           CLUSTER-IP       EXTERNAL-IP   PORT(S)                             AGE
    example-registry-clair-app            ClusterIP      172.30.224.93    <none>        80/TCP,8089/TCP                     4d21h
    example-registry-clair-postgres       ClusterIP      172.30.246.88    <none>        5432/TCP                            4d21h
    ...

  2. 转发 Clair 数据库端口,使其可从本地机器访问。例如:

    $ oc port-forward -n quay-enterprise service/example-registry-clair-postgres 5432:5432
  3. 更新 Clair config.yaml 文件,例如:

    indexer:
        connstring: host=localhost port=5432 dbname=postgres user=postgres password=postgres sslmode=disable 1
        scanlock_retry: 10
        layer_scan_concurrency: 5
        migrations: true
        scanner:
          repo:
            rhel-repository-scanner: 2
              repo2cpe_mapping_file: /data/cpe-map.json
          package:
            rhel_containerscanner: 3
              name2repos_mapping_file: /data/repo-map.json
    1
    在多 connstring 字段中使用 localhost 替换 host 的值。
    2
    有关 rhel-repository-scanner 参数的更多信息,请参阅 "Mapping repository to Common Product Enumeration"。
    3
    有关 rhel_containerscanner 参数的更多信息,请参阅 "Mapping repository to Common Product Enumeration information"。
5.4.3.2.5. 将 updaters 捆绑包导入到断开连接的 OpenShift Container Platform 集群中

使用以下步骤将更新器捆绑包导入到断开连接的 OpenShift Container Platform 集群中。

先决条件

  • 已安装 clairctl 命令行工具工具。
  • 您已部署了 Clair。
  • 在 Clair config.yaml 文件中,disable_updatersairgap 参数被设置为 true
  • 您已从可访问互联网的 Clair 实例导出 updaters 捆绑包。
  • 您已将更新器捆绑包传送到断开连接的环境中。

流程

  • 使用 clairctl CLI 工具将 updaters 捆绑包导入到 OpenShift Container Platform 部署的 Clair 数据库中:

    $ ./clairctl --config ./clair-config.yaml import-updaters updates.gz

5.4.4. 将存储库映射到通用产品枚举信息

Clair 的 Red Hat Enterprise Linux (RHEL)扫描程序依赖于通用产品枚举(CPE)文件,将 RPM 软件包映射到对应的安全数据,以生成匹配的结果。这些文件归产品安全所有,每天更新。

必须允许 cpe 文件或访问该文件,以便扫描程序能够正确处理 RPM 软件包。如果文件不存在,则不会扫描容器镜像中安装的 RPM 软件包。

表 5.1. Clair cp 映射文件
CPE到 JSON 映射文件的链接

repos2cpe

Red Hat Repository-to-CPE JSON

names2repos

Red Hat Name-to-Repos JSON.

除了将 CVE 信息上传到用于断开连接的 Clair 安装的数据库外,还必须在本地提供映射文件:

  • 对于独立的 Red Hat Quay 和 Clair 部署,映射文件必须加载到 Clair pod 中。
  • 对于在 OpenShift Container Platform 和 Clair 部署上部署 Red Hat Quay Operator,您必须将 Clair 组件设置为 非受管。然后,必须手动部署 Clair,设置配置来加载映射文件的本地副本。

5.4.4.1. 将存储库映射到通用产品枚举示例配置

在 Clair 配置中使用 repo2cpe_mapping_filename2repos_mapping_file 字段,使其包含 cp JSON 映射文件。例如:

indexer:
 scanner:
    repo:
      rhel-repository-scanner:
        repo2cpe_mapping_file: /data/cpe-map.json
    package:
      rhel_containerscanner:
        name2repos_mapping_file: /data/repo-map.json

如需更多信息,请参阅如何准确将 OVAL 安全数据与已安装的 RPM 匹配

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.