10.5. 使用 SharedSecret 对象运行授权构建
您可以在一个可以安全地使用来自另外一个命名空间中的一个Secret 中的 RHEL 权利的命名空间中,配置和执行构建。
您仍可通过在与 Build 对象相同的命名空间中,创建包含订阅凭证的 Secret 对象来从 OpenShift 构建中访问 RHEL 权利。但是,在 OpenShift Container Platform 4.10 及之后的版本中,您可以从 OpenShift Container Platform 系统命名空间中的一个 Secret 对象来访问您的凭证和证书。您可以使用引用 Secret 对象的 SharedSecret 自定义资源(CR)实例的 CSI 卷挂载运行授权构建。
此流程依赖于新引入的 Shared Resources CSI Driver 功能,该功能可用于在 OpenShift Container Platform 构建中声明 CSI 卷挂载。它还依赖于 OpenShift Container Platform Insights Operator。
共享资源 CSI 驱动程序和构建 CSI 卷都是技术预览功能,在红帽产品服务等级协议(SLA)中不支持,且可能无法正常工作。红帽不推荐在生产环境中使用它们。这些技术预览功能可以使用户提早试用新的功能,并有机会在开发阶段提供反馈意见。
有关红帽技术预览功能支持范围的更多信息,请参阅技术预览功能支持范围。
Shared Resources CSI Driver 和 Build CSI Volumes 功能还属于 TechPreviewNoUpgrade 功能集,它是当前技术预览功能的子集。您可以在测试集群中启用 TechPreviewNoUpgrade 功能集,您可以在生产环境集群中禁用这些功能时完全测试它们。启用此功能集无法撤消并阻止次版本更新。不建议在生产环境集群中使用此功能集。请参阅以下 "Additional resources" 部分,请参阅使用功能门"启用技术预览功能"。
先决条件
-
已使用功能门启用
TechPreviewNoUpgrade功能集。 -
您有一个
SharedSecret自定义资源(CR)实例,它引用 Insights Operator 存储订阅凭证的Secret对象。 您必须具有执行以下操作的权限:
- 创建构建配置和启动构建。
-
输入
oc get sharedsecrets命令并返回非空列表来发现哪些SharedSecretCR 实例可用。 -
确定命名空间中的
builder服务帐户是否可以使用给定的SharedSecretCR 实例。换句话说,您可以运行oc adm policy who-can use <identifier of specific SharedSecret>来查看是否列出命名空间中的builder服务帐户。
如果没有满足此列表中的最后两个先决条件,则建立或询问某人建立所需的基于角色的访问控制(RBAC),以便您可以发现 SharedSecret CR 实例,并启用服务帐户使用 SharedSecret CR 实例。
流程
使用带有 YAML 内容的
oc apply命令,为builder服务帐户 RBAC 权限授予使用SharedSecretCR 实例:注意目前,
kubectl和oc具有硬编码的特殊大小写逻辑,以便将use动词的使用限制为只限于 pod 安全性相关的角色。因此,您无法使用oc create role …创建使用SharedSecretCR 实例所需的角色。使用带有 YAML
角色对象定义的oc apply -f命令示例oc apply -f - <<EOF apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: name: shared-resource-my-share namespace: my-namespace rules: - apiGroups: - sharedresource.openshift.io resources: - sharedsecrets resourceNames: - my-share verbs: - use EOF$ oc apply -f - <<EOF apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: name: shared-resource-my-share namespace: my-namespace rules: - apiGroups: - sharedresource.openshift.io resources: - sharedsecrets resourceNames: - my-share verbs: - use EOFCopy to Clipboard Copied! Toggle word wrap Toggle overflow 使用
oc命令创建与角色关联的RoleBinding:oc create rolebinding命令示例oc create rolebinding shared-resource-my-share --role=shared-resource-my-share --serviceaccount=my-namespace:builder
$ oc create rolebinding shared-resource-my-share --role=shared-resource-my-share --serviceaccount=my-namespace:builderCopy to Clipboard Copied! Toggle word wrap Toggle overflow 创建可访问 RHEL 权利的
BuildConfig对象。YAML
BuildConfig对象定义示例apiVersion: build.openshift.io/v1 kind: BuildConfig metadata: name: my-csi-bc namespace: my-csi-app-namespace spec: runPolicy: Serial source: dockerfile: | FROM registry.redhat.io/ubi9/ubi:latest RUN ls -la /etc/pki/entitlement RUN rm /etc/rhsm-host RUN yum repolist --disablerepo=* RUN subscription-manager repos --enable rhocp-4.9-for-rhel-8-x86_64-rpms RUN yum -y update RUN yum install -y openshift-clients.x86_64 strategy: type: Docker dockerStrategy: volumes: - mounts: - destinationPath: "/etc/pki/entitlement" name: my-csi-shared-secret source: csi: driver: csi.sharedresource.openshift.io readOnly: true volumeAttributes: sharedSecret: my-share-bc type: CSIapiVersion: build.openshift.io/v1 kind: BuildConfig metadata: name: my-csi-bc namespace: my-csi-app-namespace spec: runPolicy: Serial source: dockerfile: | FROM registry.redhat.io/ubi9/ubi:latest RUN ls -la /etc/pki/entitlement RUN rm /etc/rhsm-host RUN yum repolist --disablerepo=* RUN subscription-manager repos --enable rhocp-4.9-for-rhel-8-x86_64-rpms RUN yum -y update RUN yum install -y openshift-clients.x86_64 strategy: type: Docker dockerStrategy: volumes: - mounts: - destinationPath: "/etc/pki/entitlement" name: my-csi-shared-secret source: csi: driver: csi.sharedresource.openshift.io readOnly: true volumeAttributes: sharedSecret: my-share-bc type: CSICopy to Clipboard Copied! Toggle word wrap Toggle overflow 从
BuildConfig对象启动一个构建,并使用oc命令跟踪日志。oc start-build 命令示例
oc start-build my-csi-bc -F
$ oc start-build my-csi-bc -FCopy to Clipboard Copied! Toggle word wrap Toggle overflow 例 10.1. oc start-build 命令的输出示例
注意以下输出的一些部分已被
…替换build.build.openshift.io/my-csi-bc-1 started Caching blobs under "/var/cache/blobs". Pulling image registry.redhat.io/ubi9/ubi:latest ... Trying to pull registry.redhat.io/ubi9/ubi:latest... Getting image source signatures Copying blob sha256:5dcbdc60ea6b60326f98e2b49d6ebcb7771df4b70c6297ddf2d7dede6692df6e Copying blob sha256:8671113e1c57d3106acaef2383f9bbfe1c45a26eacb03ec82786a494e15956c3 Copying config sha256:b81e86a2cb9a001916dc4697d7ed4777a60f757f0b8dcc2c4d8df42f2f7edb3a Writing manifest to image destination Storing signatures Adding transient rw bind mount for /run/secrets/rhsm STEP 1/9: FROM registry.redhat.io/ubi9/ubi:latest STEP 2/9: RUN ls -la /etc/pki/entitlement total 360 drwxrwxrwt. 2 root root 80 Feb 3 20:28 . drwxr-xr-x. 10 root root 154 Jan 27 15:53 .. -rw-r--r--. 1 root root 3243 Feb 3 20:28 entitlement-key.pem -rw-r--r--. 1 root root 362540 Feb 3 20:28 entitlement.pem time="2022-02-03T20:28:32Z" level=warning msg="Adding metacopy option, configured globally" --> 1ef7c6d8c1a STEP 3/9: RUN rm /etc/rhsm-host time="2022-02-03T20:28:33Z" level=warning msg="Adding metacopy option, configured globally" --> b1c61f88b39 STEP 4/9: RUN yum repolist --disablerepo=* Updating Subscription Management repositories. ... --> b067f1d63eb STEP 5/9: RUN subscription-manager repos --enable rhocp-4.9-for-rhel-8-x86_64-rpms Repository 'rhocp-4.9-for-rhel-8-x86_64-rpms' is enabled for this system. time="2022-02-03T20:28:40Z" level=warning msg="Adding metacopy option, configured globally" --> 03927607ebd STEP 6/9: RUN yum -y update Updating Subscription Management repositories. ... Upgraded: systemd-239-51.el8_5.3.x86_64 systemd-libs-239-51.el8_5.3.x86_64 systemd-pam-239-51.el8_5.3.x86_64 Installed: diffutils-3.6-6.el8.x86_64 libxkbcommon-0.9.1-1.el8.x86_64 xkeyboard-config-2.28-1.el8.noarch Complete! time="2022-02-03T20:29:05Z" level=warning msg="Adding metacopy option, configured globally" --> db57e92ff63 STEP 7/9: RUN yum install -y openshift-clients.x86_64 Updating Subscription Management repositories. ... Installed: bash-completion-1:2.7-5.el8.noarch libpkgconf-1.4.2-1.el8.x86_64 openshift-clients-4.9.0-202201211735.p0.g3f16530.assembly.stream.el8.x86_64 pkgconf-1.4.2-1.el8.x86_64 pkgconf-m4-1.4.2-1.el8.noarch pkgconf-pkg-config-1.4.2-1.el8.x86_64 Complete! time="2022-02-03T20:29:19Z" level=warning msg="Adding metacopy option, configured globally" --> 609507b059e STEP 8/9: ENV "OPENSHIFT_BUILD_NAME"="my-csi-bc-1" "OPENSHIFT_BUILD_NAMESPACE"="my-csi-app-namespace" --> cab2da3efc4 STEP 9/9: LABEL "io.openshift.build.name"="my-csi-bc-1" "io.openshift.build.namespace"="my-csi-app-namespace" COMMIT temp.builder.openshift.io/my-csi-app-namespace/my-csi-bc-1:edfe12ca --> 821b582320b Successfully tagged temp.builder.openshift.io/my-csi-app-namespace/my-csi-bc-1:edfe12ca 821b582320b41f1d7bab4001395133f86fa9cc99cc0b2b64c5a53f2b6750db91 Build complete, no image push requested
build.build.openshift.io/my-csi-bc-1 started Caching blobs under "/var/cache/blobs". Pulling image registry.redhat.io/ubi9/ubi:latest ... Trying to pull registry.redhat.io/ubi9/ubi:latest... Getting image source signatures Copying blob sha256:5dcbdc60ea6b60326f98e2b49d6ebcb7771df4b70c6297ddf2d7dede6692df6e Copying blob sha256:8671113e1c57d3106acaef2383f9bbfe1c45a26eacb03ec82786a494e15956c3 Copying config sha256:b81e86a2cb9a001916dc4697d7ed4777a60f757f0b8dcc2c4d8df42f2f7edb3a Writing manifest to image destination Storing signatures Adding transient rw bind mount for /run/secrets/rhsm STEP 1/9: FROM registry.redhat.io/ubi9/ubi:latest STEP 2/9: RUN ls -la /etc/pki/entitlement total 360 drwxrwxrwt. 2 root root 80 Feb 3 20:28 . drwxr-xr-x. 10 root root 154 Jan 27 15:53 .. -rw-r--r--. 1 root root 3243 Feb 3 20:28 entitlement-key.pem -rw-r--r--. 1 root root 362540 Feb 3 20:28 entitlement.pem time="2022-02-03T20:28:32Z" level=warning msg="Adding metacopy option, configured globally" --> 1ef7c6d8c1a STEP 3/9: RUN rm /etc/rhsm-host time="2022-02-03T20:28:33Z" level=warning msg="Adding metacopy option, configured globally" --> b1c61f88b39 STEP 4/9: RUN yum repolist --disablerepo=* Updating Subscription Management repositories. ... --> b067f1d63eb STEP 5/9: RUN subscription-manager repos --enable rhocp-4.9-for-rhel-8-x86_64-rpms Repository 'rhocp-4.9-for-rhel-8-x86_64-rpms' is enabled for this system. time="2022-02-03T20:28:40Z" level=warning msg="Adding metacopy option, configured globally" --> 03927607ebd STEP 6/9: RUN yum -y update Updating Subscription Management repositories. ... Upgraded: systemd-239-51.el8_5.3.x86_64 systemd-libs-239-51.el8_5.3.x86_64 systemd-pam-239-51.el8_5.3.x86_64 Installed: diffutils-3.6-6.el8.x86_64 libxkbcommon-0.9.1-1.el8.x86_64 xkeyboard-config-2.28-1.el8.noarch Complete! time="2022-02-03T20:29:05Z" level=warning msg="Adding metacopy option, configured globally" --> db57e92ff63 STEP 7/9: RUN yum install -y openshift-clients.x86_64 Updating Subscription Management repositories. ... Installed: bash-completion-1:2.7-5.el8.noarch libpkgconf-1.4.2-1.el8.x86_64 openshift-clients-4.9.0-202201211735.p0.g3f16530.assembly.stream.el8.x86_64 pkgconf-1.4.2-1.el8.x86_64 pkgconf-m4-1.4.2-1.el8.noarch pkgconf-pkg-config-1.4.2-1.el8.x86_64 Complete! time="2022-02-03T20:29:19Z" level=warning msg="Adding metacopy option, configured globally" --> 609507b059e STEP 8/9: ENV "OPENSHIFT_BUILD_NAME"="my-csi-bc-1" "OPENSHIFT_BUILD_NAMESPACE"="my-csi-app-namespace" --> cab2da3efc4 STEP 9/9: LABEL "io.openshift.build.name"="my-csi-bc-1" "io.openshift.build.namespace"="my-csi-app-namespace" COMMIT temp.builder.openshift.io/my-csi-app-namespace/my-csi-bc-1:edfe12ca --> 821b582320b Successfully tagged temp.builder.openshift.io/my-csi-app-namespace/my-csi-bc-1:edfe12ca 821b582320b41f1d7bab4001395133f86fa9cc99cc0b2b64c5a53f2b6750db91 Build complete, no image push requestedCopy to Clipboard Copied! Toggle word wrap Toggle overflow