10.5. SharedSecret オブジェクトを使用したビルドの実行
SharedSecret オブジェクトを使用すると、ビルドでクラスターのエンタイトルメントキーにセキュアにアクセスできます。
SharedSecret オブジェクトを使用すると、namespace 間でシークレットを共有および同期できます。
Shared Resource CSI Driver 機能は、Red Hat OpenShift 1.1 のビルド で一般提供されました。この機能は OpenShift Container Platform 4.18 以降で削除されました。この機能を使用するには、Red Hat OpenShift 1.1 以降の Builds を使用している必要があります。
前提条件
-
フィーチャーゲートを使用して
TechPreviewNoUpgrade機能セットを有効にしている。詳細は、フィーチャーゲートを使用した機能の有効化 を参照してください。 次のアクションを実行するためのパーミッションがある。
- ビルド設定を作成し、ビルドを開始します。
-
oc get sharedsecretsコマンドを入力し、空でないリストを取得して、使用可能なSharedSecretCR インスタンスを見つけます。 -
namespace で使用可能な
builderサービスアカウントが、指定されたSharedSecretCR インスタンスの使用を許可されているかどうかを確認します。つまり、oc adm policy who-can use <identifier of specific SharedSecret>を使用して、namespace のbuilderサービスアカウントがリスト表示されているか確認できます。
このリストの最後の 2 つの前提条件のいずれも満たされない場合は、必要なロールベースアクセス制御 (RBAC) を自身で確立するか、誰かに依頼して確立します。これにより、SharedSecret CR インスタンスを検出し、サービスアカウントを有効にして SharedSecret CR インスタンスを使用できるようになります。
手順
oc applyを使用して、クラスターのエンタイトルメントシークレットでSharedSecretオブジェクトインスタンスを作成します。重要SharedSecretオブジェクトを作成するには、クラスター管理者の権限が必要です。YAML
Roleオブジェクト定義を使用したoc apply -fコマンドの例oc apply -f - <<EOF kind: SharedSecret apiVersion: sharedresource.openshift.io/v1alpha1 metadata: name: etc-pki-entitlement spec: secretRef: name: etc-pki-entitlement namespace: openshift-config-managed EOF$ oc apply -f - <<EOF kind: SharedSecret apiVersion: sharedresource.openshift.io/v1alpha1 metadata: name: etc-pki-entitlement spec: secretRef: name: etc-pki-entitlement namespace: openshift-config-managed EOFCopy to Clipboard Copied! Toggle word wrap Toggle overflow SharedSecretオブジェクトにアクセスするための権限をbuilderサービスアカウントに付与するロールを作成します。oc apply -fコマンドの例oc apply -f - <<EOF apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: name: builder-etc-pki-entitlement namespace: build-namespace rules: - apiGroups: - sharedresource.openshift.io resources: - sharedsecrets resourceNames: - etc-pki-entitlement verbs: - use EOF$ oc apply -f - <<EOF apiVersion: rbac.authorization.k8s.io/v1 kind: Role metadata: name: builder-etc-pki-entitlement namespace: build-namespace rules: - apiGroups: - sharedresource.openshift.io resources: - sharedsecrets resourceNames: - etc-pki-entitlement verbs: - use EOFCopy to Clipboard Copied! Toggle word wrap Toggle overflow 次のコマンドを実行して、
builderサービスアカウントにSharedSecretオブジェクトにアクセスするための権限を付与するRoleBindingオブジェクトを作成します。oc create rolebindingコマンドの例oc create rolebinding builder-etc-pki-entitlement --role=builder-etc-pki-entitlement --serviceaccount=build-namespace:builder
$ oc create rolebinding builder-etc-pki-entitlement --role=builder-etc-pki-entitlement --serviceaccount=build-namespace:builderCopy to Clipboard Copied! Toggle word wrap Toggle overflow CSI ボリュームマウントを使用して、エンタイトルメントシークレットを
BuildConfigオブジェクトに追加します。YAML
BuildConfigオブジェクト定義の例apiVersion: build.openshift.io/v1 kind: BuildConfig metadata: name: uid-wrapper-rhel9 namespace: build-namespace spec: runPolicy: Serial source: dockerfile: | FROM registry.redhat.io/ubi9/ubi:latest RUN rm -rf /etc/rhsm-host RUN yum --enablerepo=codeready-builder-for-rhel-9-x86_64-rpms install \ nss_wrapper \ uid_wrapper -y && \ yum clean all -y RUN ln -s /run/secrets/rhsm /etc/rhsm-host strategy: type: Docker dockerStrategy: volumes: - mounts: - destinationPath: "/etc/pki/entitlement" name: etc-pki-entitlement source: csi: driver: csi.sharedresource.openshift.io readOnly: true volumeAttributes: sharedSecret: etc-pki-entitlement type: CSIapiVersion: build.openshift.io/v1 kind: BuildConfig metadata: name: uid-wrapper-rhel9 namespace: build-namespace spec: runPolicy: Serial source: dockerfile: | FROM registry.redhat.io/ubi9/ubi:latest RUN rm -rf /etc/rhsm-host1 RUN yum --enablerepo=codeready-builder-for-rhel-9-x86_64-rpms install \2 nss_wrapper \ uid_wrapper -y && \ yum clean all -y RUN ln -s /run/secrets/rhsm /etc/rhsm-host3 strategy: type: Docker dockerStrategy: volumes: - mounts: - destinationPath: "/etc/pki/entitlement" name: etc-pki-entitlement source: csi: driver: csi.sharedresource.openshift.io readOnly: true4 volumeAttributes: sharedSecret: etc-pki-entitlement5 type: CSICopy to Clipboard Copied! Toggle word wrap Toggle overflow - 1
yumまたはdnfコマンドを実行する前に、/etc/rhsm-hostディレクトリーとそのすべての内容を削除するコマンドを Dockerfile に含める必要があります。- 2
- Red Hat Package Browser を使用して、インストールされているパッケージの正しいリポジトリーを見つけます。
- 3
- イメージと他の Red Hat コンテナーイメージとの互換性を維持するために、
/etc/rhsm-hostのシンボリックリンクを復元する必要があります。 - 4
- ビルドで共有リソースをマウントするには、
readOnlyをtrueに設定する必要があります。 - 5
- ビルドに含める
SharedSecretオブジェクトの名前を参照します。
BuildConfigオブジェクトからビルドを開始し、ocコマンドを使用してログを追跡します。oc start-build uid-wrapper-rhel9 -n build-namespace -F
$ oc start-build uid-wrapper-rhel9 -n build-namespace -FCopy to Clipboard Copied! Toggle word wrap Toggle overflow