4.2.2. 创建凭证和 CA 证书以添加 Helm Chart 仓库
有些 Helm Chart 仓库需要凭证和自定义证书颁发机构(CA)证书才能与其连接。您可以使用 Web 控制台和 CLI 添加凭证和证书。
流程
配置凭证和证书,然后使用 CLI 添加 Helm Chart 仓库:
在
openshift-config
命名空间中,使用 PEM 编码格式的自定义 CA 证书创建一个configmap
,并将它存储在配置映射中的ca-bundle.crt
键下:$ oc create configmap helm-ca-cert \ --from-file=ca-bundle.crt=/path/to/certs/ca.crt \ -n openshift-config
在
openshift-config
命名空间中,创建一个Secret
对象来添加客户端 TLS 配置:$ oc create secret generic helm-tls-configs \ --from-file=tls.crt=/path/to/certs/client.crt \ --from-file=tls.key=/path/to/certs//client.key \ -n openshift-config
请注意:客户端证书和密钥必须采用 PEM 编码格式,并分别保存在
tls.crt
和tls.key
密钥中。按如下所示添加 Helm 仓库:
$ cat <<EOF | oc apply -f - apiVersion: helm.openshift.io/v1beta1 kind: HelmChartRepository metadata: name: <helm-repository> spec: name: <helm-repository> connectionConfig: url: <URL for the Helm repository> tlsConfig: name: helm-tls-configs ca: name: helm-ca-cert EOF
ConfigMap
和Secret
使用tlsConfig
和ca
字段在 HelmChartRepository CR 中消耗。这些证书用于连接 Helm 仓库 URL。默认情况下,所有经过身份验证的用户都可以访问所有配置的 chart。但是,对于需要证书的 Chart 仓库,您必须为用户提供对
openshift-config
命名空间中helm-ca-cert
配置映射和helm-tls-configs
secret 的读取访问权限,如下所示:$ cat <<EOF | kubectl apply -f - apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: namespace: openshift-config name: helm-chartrepos-tls-conf-viewer rules: - apiGroups: [""] resources: ["configmaps"] resourceNames: ["helm-ca-cert"] verbs: ["get"] - apiGroups: [""] resources: ["secrets"] resourceNames: ["helm-tls-configs"] verbs: ["get"] --- kind: RoleBinding apiVersion: rbac.authorization.k8s.io/v1 metadata: namespace: openshift-config name: helm-chartrepos-tls-conf-viewer subjects: - kind: Group apiGroup: rbac.authorization.k8s.io name: 'system:authenticated' roleRef: apiGroup: rbac.authorization.k8s.io kind: Role name: helm-chartrepos-tls-conf-viewer EOF