1.3. 使用 RHEL 权利构建镜像
如果您有 Red Hat Enterprise Linux (RHEL)授权,Insights Operator 会使用简单内容访问(SCA)功能自动管理权利密钥。使用 SCA 时,RHEL 系统将访问订阅内容,而无需手动管理授权密钥。Insights Operator 导入 SCA 授权密钥,并将其存储在 openshift-config-managed 命名空间中的名为 etc-pki-entitlement 的 secret 中。
在以前的版本中,集群管理员会将 etc-pki-entitlement secret 手动复制到所需的命名空间中。从 OpenShift Container Platform 4.10 及之后的版本开始,Red Hat OpenShift 的构建可以使用 Shared Resource Container Storage Interface (CSI) Driver Operator 从 openshift-config-managed 命名空间中共享 etc-pki-entitlement secret。
1.3.1. 在命名空间间共享 RHEL 权利 复制链接链接已复制到粘贴板!
您可以使用 SharedSecret 对象安全地共享并同步跨命名空间中的集群的 RHEL 授权密钥。
先决条件
您必须具有执行以下操作的权限:
-
创建
SharedSecret对象。 - 创建构建配置和启动构建。
-
运行
oc get sharedsecrets命令,以发现哪些SharedSecret自定义资源(CR)实例可用。 -
运行
oc adm policy who-can use <sharedsecret_identifier> 命令检查服务帐户是否可以使用SharedSecretCR,并且服务帐户列在命名空间中。
-
创建
如果您无法完成最后的两个先决条件,集群管理员可以建立必要的 RBAC 权限,以便您可以授予服务帐户以使用 SharedSecret CR。
流程
运行以下命令,使用集群的授权 secret 创建
SharedSecret对象实例:$ oc apply -f -<<EOF apiVersion: sharedresource.openshift.io/v1alpha1 kind: SharedSecret metadata: name: etc-pki-entitlement spec: secretRef: name: etc-pki-entitlement namespace: openshift-config-managed EOF创建
ClusterRole对象,以授予使用以下示例配置访问SharedSecret对象的权限:apiVersion: rbac.authorization.k8s.io/v1 kind: ClusterRole metadata: name: use-share-etc-pki-entitlement1 rules: - apiGroups: - sharedresource.openshift.io resources: - sharedsecrets resourceNames: - etc-pki-entitlement verbs: - use- 1
ClusterRoleCR 的名称。
创建
Role和RoleBinding对象,为 Shared Resource CSI 驱动程序授予访问SharedSecret对象的权限:Role对象示例apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: name: share-etc-pki-entitlement1 namespace: openshift-config-managed rules: - apiGroups: - "" resources: - secrets resourceNames: - etc-pki-entitlement verbs: - get - list - watch- 1
RoleCR 的名称。
RoleBinding对象示例apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: share-etc-pki-entitlement1 namespace: openshift-config-managed roleRef: apiGroup: rbac.authorization.k8s.io kind: Role name: share-etc-pki-entitlement subjects: - kind: ServiceAccount name: csi-driver-shared-resource namespace: openshift-builds2 为运行构建的命名空间中
构建器和管道服务帐户创建RoleBinding对象:apiVersion: rbac.authorization.k8s.io/v1 kind: RoleBinding metadata: name: use-share-etc-pki-entitlement1 roleRef: apiGroup: rbac.authorization.k8s.io kind: ClusterRole name: use-share-etc-pki-entitlement subjects: - kind: ServiceAccount name: pipeline - kind: ServiceAccount name: builder- 1
构建器和管道服务帐户的RoleBindingCR 的名称。
注意使用
SharedSecret对象的服务帐户由 OpenShift 控制器创建和管理。使用
buildah构建策略挂载SharedSecret对象。请参见以下示例:$ oc apply -f -<<EOF apiVersion: shipwright.io/v1beta1 kind: Build metadata: name: buildah-rhel spec: source: type: Git git: url: https://github.com/redhat-openshift-builds/samples contextDir: buildah-build strategy: name: buildah kind: ClusterBuildStrategy paramValues: - name: dockerfile value: DockerFile volumes: - csi: driver: csi.sharedresource.openshift.io readOnly: true1 volumeAttributes: sharedSecret: <sharedsecret_object_name>2 name: etc-pki-entitlement output: image: <output_image_location>3 EOF