2.8.3.3. Azure Key Vault からのシークレットのマウント


Secrets Store CSI Driver Operator を使用して、Microsoft Azure Key Vault から OpenShift Container Platform の Container Storage Interface (CSI) ボリュームにシークレットをマウントできます。Azure Key Vault からシークレットをマウントするには、以下を実行します。

前提条件

  • Azure にクラスターをインストールした。
  • cluster-admin ロールを持つユーザーとしてクラスターにアクセスできる。
  • Azure CLI (az) がインストールされている。
  • Secrets Store CSI Driver Operator がインストールされている。手順は、「Secrets Store CSI ドライバーのインストール」を参照してください。
  • 必要なシークレットを保存するように Azure Key Vault を設定している。

手順

  1. Azure Key Vault プロバイダーをインストールします。

    1. ServiceAccount リソース設定を定義する、azure-provider.yaml という名前の YAML ファイルを作成します。次の設定例を参照してください。

      重要

      Secrets Store CSI ドライバーの Azure Key Vault プロバイダーは、アップストリームプロバイダーです。

      この設定は、OpenShift Container Platform で適切に動作するように、アップストリームの Azure ドキュメント で提供されている設定から変更されています。この設定を変更すると、機能に影響が出る場合があります。

      azure-provider.yaml ファイルの例

      apiVersion: v1
      kind: ServiceAccount
      metadata:
        name: csi-secrets-store-provider-azure
        namespace: openshift-cluster-csi-drivers
      ---
      apiVersion: rbac.authorization.k8s.io/v1
      kind: ClusterRole
      metadata:
        name: csi-secrets-store-provider-azure-cluster-role
      rules:
      - apiGroups: [""]
        resources: ["serviceaccounts/token"]
        verbs: ["create"]
      - apiGroups: [""]
        resources: ["serviceaccounts"]
        verbs: ["get"]
      - apiGroups: [""]
        resources: ["pods"]
        verbs: ["get"]
      - apiGroups: [""]
        resources: ["nodes"]
        verbs: ["get"]
      ---
      apiVersion: rbac.authorization.k8s.io/v1
      kind: ClusterRoleBinding
      metadata:
        name: csi-secrets-store-provider-azure-cluster-rolebinding
      roleRef:
        apiGroup: rbac.authorization.k8s.io
        kind: ClusterRole
        name: csi-secrets-store-provider-azure-cluster-role
      subjects:
      - kind: ServiceAccount
        name: csi-secrets-store-provider-azure
        namespace: openshift-cluster-csi-drivers
      ---
      apiVersion: apps/v1
      kind: DaemonSet
      metadata:
        namespace: openshift-cluster-csi-drivers
        name: csi-secrets-store-provider-azure
        labels:
          app: csi-secrets-store-provider-azure
      spec:
        updateStrategy:
          type: RollingUpdate
        selector:
          matchLabels:
            app: csi-secrets-store-provider-azure
        template:
          metadata:
            labels:
              app: csi-secrets-store-provider-azure
          spec:
            serviceAccountName: csi-secrets-store-provider-azure
            hostNetwork: true
            containers:
              - name: provider-azure-installer
                image: mcr.microsoft.com/oss/azure/secrets-store/provider-azure:v1.4.1
                imagePullPolicy: IfNotPresent
                args:
                  - --endpoint=unix:///provider/azure.sock
                  - --construct-pem-chain=true
                  - --healthz-port=8989
                  - --healthz-path=/healthz
                  - --healthz-timeout=5s
                livenessProbe:
                  httpGet:
                    path: /healthz
                    port: 8989
                  failureThreshold: 3
                  initialDelaySeconds: 5
                  timeoutSeconds: 10
                  periodSeconds: 30
                resources:
                  requests:
                    cpu: 50m
                    memory: 100Mi
                  limits:
                    cpu: 50m
                    memory: 100Mi
                securityContext:
                  allowPrivilegeEscalation: false
                  readOnlyRootFilesystem: true
                  runAsUser: 0
                  capabilities:
                    drop:
                    - ALL
                volumeMounts:
                  - mountPath: "/provider"
                    name: providervol
            affinity:
              nodeAffinity:
                requiredDuringSchedulingIgnoredDuringExecution:
                  nodeSelectorTerms:
                  - matchExpressions:
                    - key: type
                      operator: NotIn
                      values:
                      - virtual-kubelet
            volumes:
              - name: providervol
                hostPath:
                  path: "/var/run/secrets-store-csi-providers"
            tolerations:
            - operator: Exists
            nodeSelector:
              kubernetes.io/os: linux

    2. 次のコマンドを実行して、csi-secrets-store-provider-azure サービスアカウントへの特権アクセスを付与します。

      $ oc adm policy add-scc-to-user privileged -z csi-secrets-store-provider-azure -n openshift-cluster-csi-drivers
    3. 次のコマンドを実行して、プロバイダーリソースを作成します。

      $ oc apply -f azure-provider.yaml
  2. Key Vault にアクセスするためのサービスプリンシパルを作成します。

    1. 次のコマンドを実行して、サービスプリンシパルのクライアントシークレットを環境変数として設定します。

      $ SERVICE_PRINCIPAL_CLIENT_SECRET="$(az ad sp create-for-rbac --name https://$KEYVAULT_NAME --query 'password' -otsv)"
    2. 次のコマンドを実行して、サービスプリンシパルのクライアント ID を環境変数として設定します。

      $ SERVICE_PRINCIPAL_CLIENT_ID="$(az ad sp list --display-name https://$KEYVAULT_NAME --query '[0].appId' -otsv)"
    3. 次のコマンドを実行して、サービスプリンシパルのクライアントシークレットと ID を使用して汎用シークレットを作成します。

      $ oc create secret generic secrets-store-creds -n my-namespace --from-literal clientid=${SERVICE_PRINCIPAL_CLIENT_ID} --from-literal clientsecret=${SERVICE_PRINCIPAL_CLIENT_SECRET}
    4. secrets-store.csi.k8s.io/used=true ラベルを適用して、プロバイダーがこの nodePublishSecretRef シークレットを検索できるようにします。

      $ oc -n my-namespace label secret secrets-store-creds secrets-store.csi.k8s.io/used=true
  3. シークレットプロバイダークラスを作成して、シークレットストアプロバイダーを定義します。

    1. SecretProviderClass オブジェクトを定義する YAML ファイルを作成します。

      secret-provider-class-azure.yaml の例

      apiVersion: secrets-store.csi.x-k8s.io/v1
      kind: SecretProviderClass
      metadata:
        name: my-azure-provider                 
      1
      
        namespace: my-namespace                 
      2
      
      spec:
        provider: azure                         
      3
      
        parameters:                             
      4
      
          usePodIdentity: "false"
          useVMManagedIdentity: "false"
          userAssignedIdentityID: ""
          keyvaultName: "kvname"
          objects: |
            array:
              - |
                objectName: secret1
                objectType: secret
          tenantId: "tid"

      1
      シークレットプロバイダークラスの名前を指定します。
      2
      シークレットプロバイダークラスの namespace を指定します。
      3
      プロバイダーを azure として指定します。
      4
      プロバイダー固有の設定パラメーターを指定します。
    2. 次のコマンドを実行して SecretProviderClass オブジェクトを作成します。

      $ oc create -f secret-provider-class-azure.yaml
  4. このシークレットプロバイダークラスを使用するデプロイメントを作成します。

    1. Deployment オブジェクトを定義する YAML ファイルを作成します。

      deployment.yaml の例

      apiVersion: apps/v1
      kind: Deployment
      metadata:
        name: my-azure-deployment                            
      1
      
        namespace: my-namespace                              
      2
      
      spec:
        replicas: 1
        selector:
          matchLabels:
            app: my-storage
        template:
          metadata:
            labels:
              app: my-storage
          spec:
            containers:
            - name: busybox
              image: k8s.gcr.io/e2e-test-images/busybox:1.29
              command:
                - "/bin/sleep"
                - "10000"
              volumeMounts:
              - name: secrets-store-inline
                mountPath: "/mnt/secrets-store"
                readOnly: true
            volumes:
              - name: secrets-store-inline
                csi:
                  driver: secrets-store.csi.k8s.io
                  readOnly: true
                  volumeAttributes:
                    secretProviderClass: "my-azure-provider" 
      3
      
                  nodePublishSecretRef:
                    name: secrets-store-creds                
      4

      1
      デプロイメントの名前を指定します。
      2
      デプロイメントの namespace を指定します。これは、シークレットプロバイダークラスと同じ namespace である必要があります。
      3
      シークレットプロバイダークラスの名前を指定します。
      4
      Azure Key Vault にアクセスするためのサービスプリンシパル認証情報を含む Kubernetes シークレットの名前を指定します。
    2. 次のコマンドを実行して、Deployment オブジェクトを作成します。

      $ oc create -f deployment.yaml

検証

  • Pod ボリュームマウント内の Azure Key Vault からシークレットにアクセスできることを確認します。

    1. 次のコマンドを実行して、Pod マウント内のシークレットをリスト表示します。

      $ oc exec my-azure-deployment-<hash> -n my-namespace -- ls /mnt/secrets-store/

      出力例

      secret1

    2. 次のコマンドを実行して、Pod マウント内のシークレットを表示します。

      $ oc exec my-azure-deployment-<hash> -n my-namespace -- cat /mnt/secrets-store/secret1

      出力例

      my-secret-value

Red Hat logoGithubredditYoutubeTwitter

詳細情報

試用、購入および販売

コミュニティー

会社概要

Red Hat は、企業がコアとなるデータセンターからネットワークエッジに至るまで、各種プラットフォームや環境全体で作業を簡素化できるように、強化されたソリューションを提供しています。

多様性を受け入れるオープンソースの強化

Red Hat では、コード、ドキュメント、Web プロパティーにおける配慮に欠ける用語の置き換えに取り組んでいます。このような変更は、段階的に実施される予定です。詳細情報: Red Hat ブログ.

Red Hat ドキュメントについて

Legal Notice

Theme

© 2026 Red Hat
トップに戻る