7.2. 在 air-gapped OpenShift 集群中为 Clair 手动更新漏洞数据库
Clair 使用名为 updaters 的软件包,用于封装获取和解析不同漏洞数据库的逻辑。Clair 支持在不同环境中运行更新器并导入结果。这旨在支持不允许 Clair 集群直接与互联网对话的安装。
要手动更新 air-gapped OpenShift 集群中的 Clair 漏洞数据库,请使用以下步骤:
-
获取
clairctl程序 - 检索 Clair 配置
-
使用
clairctl从可访问互联网的 Clair 实例导出 updaters 捆绑包 - 更新 air-gapped OpenShift 集群中的 Clair 配置,以允许访问 Clair 数据库
- 从有互联网访问的系统中传输更新者捆绑包,使其可在 air-gapped 环境中可用
-
使用
clairctl将 updaters 捆绑包导入到 air-gapped OpenShift 集群的 Clair 实例中
7.2.1. 获取 clairctl 复制链接链接已复制到粘贴板!
要从 OpenShift 集群中的 Clair 部署中获取 clairctl 程序,请使用 oc cp 命令,例如:
oc -n quay-enterprise cp example-registry-clair-app-64dd48f866-6ptgw:/usr/bin/clairctl ./clairctl chmod u+x ./clairctl
$ oc -n quay-enterprise cp example-registry-clair-app-64dd48f866-6ptgw:/usr/bin/clairctl ./clairctl
$ chmod u+x ./clairctl
对于独立 Clair 部署,请使用 podman cp 命令,例如:
sudo podman cp clairv4:/usr/bin/clairctl ./clairctl chmod u+x ./clairctl
$ sudo podman cp clairv4:/usr/bin/clairctl ./clairctl
$ chmod u+x ./clairctl
7.2.2. 检索 Clair 配置 复制链接链接已复制到粘贴板!
7.2.2.1. OpenShift 配置的 Clair 复制链接链接已复制到粘贴板!
要检索使用 OpenShift Operator 部署的 Clair 实例的配置文件,请使用适当的命名空间检索和解码配置 secret,并将它保存到文件中,例如:
kubectl get secret -n quay-enterprise example-registry-clair-config-secret -o "jsonpath={$.data['config\.yaml']}" | base64 -d > clair-config.yaml
$ kubectl get secret -n quay-enterprise example-registry-clair-config-secret -o "jsonpath={$.data['config\.yaml']}" | base64 -d > clair-config.yaml
Clair 配置文件摘录如下:
clair-config.yaml
7.2.2.2. 独立 Clair 配置 复制链接链接已复制到粘贴板!
对于独立 Clair 部署,配置文件是在 podman run 命令中 CLAIR_CONF 环境变量中指定的环境变量指定的,例如:
sudo podman run -d --rm --name clairv4 \ -p 8081:8081 -p 8089:8089 \ -e CLAIR_CONF=/clair/config.yaml -e CLAIR_MODE=combo \ -v /etc/clairv4/config:/clair:Z \ registry.redhat.io/quay/clair-rhel8:v3.7.10
sudo podman run -d --rm --name clairv4 \
-p 8081:8081 -p 8089:8089 \
-e CLAIR_CONF=/clair/config.yaml -e CLAIR_MODE=combo \
-v /etc/clairv4/config:/clair:Z \
registry.redhat.io/quay/clair-rhel8:v3.7.10
7.2.3. 导出更新器捆绑包 复制链接链接已复制到粘贴板!
从可访问互联网的 Clair 实例中,使用正确的配置文件使用 clairctl 导出 updaters 捆绑包:
./clairctl --config ./config.yaml export-updaters updates.gz
$ ./clairctl --config ./config.yaml export-updaters updates.gz
7.2.4. 配置 air-gapped OpenShift 集群中的 Clair 数据库访问 复制链接链接已复制到粘贴板!
使用
kubectl来确定 Clair 数据库服务:Copy to Clipboard Copied! Toggle word wrap Toggle overflow 转发 Clair 数据库端口,使其可从本地机器访问,例如:
kubectl port-forward -n quay-enterprise service/example-registry-clair-postgres 5432:5432
$ kubectl port-forward -n quay-enterprise service/example-registry-clair-postgres 5432:5432Copy to Clipboard Copied! Toggle word wrap Toggle overflow 更新 Clair 配置文件,使用
localhost替换多个connstring字段中的host值,例如:clair-config.yaml
... connstring: host=localhost port=5432 dbname=postgres user=postgres password=postgres sslmode=disable ...... connstring: host=localhost port=5432 dbname=postgres user=postgres password=postgres sslmode=disable ...Copy to Clipboard Copied! Toggle word wrap Toggle overflow
作为使用 kubectl port-forward 的替代选择,您可以使用 kubefwd 替代。使用此方法时,不需要修改 Clair 配置文件中的 connstring 字段,以使用 localhost。
7.2.5. 将 updaters 捆绑包导入到 air-gapped 环境中 复制链接链接已复制到粘贴板!
将 updaters 捆绑包传送到 air-gapped 环境后,使用 clairctl 将捆绑包导入到 OpenShift Operator 部署的 Clair 数据库中:
./clairctl --config ./clair-config.yaml import-updaters updates.gz
$ ./clairctl --config ./clair-config.yaml import-updaters updates.gz