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 > 命令检查服务帐户是否可以使用 SharedSecret CR,并且服务帐户列在命名空间中。
注意

如果您无法完成最后的两个先决条件,集群管理员可以建立必要的 RBAC 权限,以便您可以授予服务帐户以使用 SharedSecret CR。

流程

  1. 运行以下命令,使用集群的授权 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
  2. 创建 ClusterRole 对象,以授予使用以下示例配置访问 SharedSecret 对象的权限:

    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRole
    metadata:
      name: use-share-etc-pki-entitlement 
    1
    
    rules:
      - apiGroups:
          - sharedresource.openshift.io
        resources:
          - sharedsecrets
        resourceNames:
          - etc-pki-entitlement
        verbs:
          - use
    1
    ClusterRole CR 的名称。
  3. 创建 RoleRoleBinding 对象,为 Shared Resource CSI 驱动程序授予访问 SharedSecret 对象的权限:

    Role 对象示例

    apiVersion: rbac.authorization.k8s.io/v1
    kind: Role
    metadata:
      name: share-etc-pki-entitlement 
    1
    
      namespace: openshift-config-managed
    rules:
      - apiGroups:
          - ""
        resources:
          - secrets
        resourceNames:
          - etc-pki-entitlement
        verbs:
          - get
          - list
          - watch

    1
    Role CR 的名称。

    RoleBinding 对象示例

    apiVersion: rbac.authorization.k8s.io/v1
    kind: RoleBinding
    metadata:
      name: share-etc-pki-entitlement 
    1
    
      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-builds 
    2

    1
    RoleBinding CR 的名称。
    2
    安装 openshift-builds 的命名空间的名称。
  4. 为运行构建的命名空间中 构建器和 管道 服务帐户创建 RoleBinding 对象:

    apiVersion: rbac.authorization.k8s.io/v1
    kind: RoleBinding
    metadata:
      name: use-share-etc-pki-entitlement 
    1
    
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: ClusterRole
      name: use-share-etc-pki-entitlement
    subjects:
      - kind: ServiceAccount
        name: pipeline
      - kind: ServiceAccount
        name: builder
    1
    构建器 和管道 服务帐户的 RoleBinding CR 的名称。
    注意

    使用 SharedSecret 对象的服务帐户由 OpenShift 控制器创建和管理。

  5. 使用 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: true 
    1
    
          volumeAttributes:
            sharedSecret: <sharedsecret_object_name> 
    2
    
        name: etc-pki-entitlement
      output:
        image: <output_image_location> 
    3
    
    EOF
    1
    您必须将 readOnly 设置为 true,以便在构建中挂载共享资源。
    2
    <sharedsecret_object_name > 替换为 SharedSecret 对象的名称,使其包含在构建中。
    3
    <output_image_location > 替换为您要推送构建的镜像的位置。
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2026 Red Hat
返回顶部