首页 > 解决方案 > 使用 CA 证书为 S2I 构建拉取构建器映像

问题描述

我有一个BuildConfig具有以下strategy块的:

    strategy:
      sourceStrategy:
        from:
          kind: DockerImage
          name: <insecure registry pullspec>
        forcePull: true
        incremental: true
      type: Source

构建器映像来自使用自签名证书的注册表。我如何告诉构建配置 A)为注册表使用 CA 证书或 B)忽略证书错误?

我尝试将 CA 证书添加为不透明的秘密,然后使用pullSecret,但这不起作用:

  strategy:
    sourceStrategy:
      forcePull: true
      from:
        kind: DockerImage
        name: <insecure registry pullspec>
      incremental: true
      pullSecret:
        name: <name of opaque secret with ca cert>
    type: Source

我在 OpenShift 3.11 集群中运行此构建。

标签: openshift

解决方案


这实际上在文档中描述了如何将您自己的根 CA 添加为additionalTrustedCA为构建设置其他受信任的证书颁发机构

以下是相关部分:

在 openshift-config 命名空间中创建一个 ConfigMap,其中包含使用自签名证书的注册表的可信证书。对于每个 CA 文件,确保 ConfigMap 中的键是主机名 [..port] 格式的注册表主机名:

$ oc create configmap registry-cas -n openshift-config \
   --from-file=myregistry.corp.com..5000=/etc/docker/certs.d/myregistry.corp.com:5000/ca.crt \
   --from-file=otherregistry.com=/etc/docker/certs.d/otherregistry.com/ca.crt

更新集群镜像配置:

$ oc patch image.config.openshift.io/cluster --patch '{"spec":{"additionalTrustedCA":{"name":"registry-cas"}}}' --type=merge

推荐阅读