AI エージェント向け: ドキュメントインデックスは https://www.mongodb.com/ja-jp/docs/llms.txt で利用できます。すべてのページの markdown バージョンは、いずれかの URL パスに .md を追加することで利用できます。
Docs Menu

シークレット ストレージの構成

Kubernetes Operator の シークレット ストレージ ツール を選択できます。 シークレット ストレージ ツールは、Kubernetes Operator が管理するコンポーネントの機密情報を保存する安全な場所です。 これには、 MongoDBデータベース、 MongoDB Ops Manager 、 AppDB のシークレットが含まれます。

シークレット ストレージを構成すると、Kubernetes Operator は ツールにアクセスしてシークレットを取得し、それらを使用して接続を安全に確立します。

Kubernetes Operator は次のシークレット ストレージ ツールをサポートしています。

  • Kubernetes : 機密情報を シークレット として保存します( Kubernetesの組み込みシークレットストレージ)。Kubernetes secrets は認証資格情報を保存し、 Kubernetesのみがアクセスできるようにします。

  • HashiCorp Vault : 秘密管理用のサードパーティ サービスである Vault に機密情報を保存する。

Kubernetes Operator 用のMongoDBコントロール のドキュメント内の任意のシークレットには、サポートされている任意のシークレットストレージツールを使用できます。ただし、制限にリストされているものは対象外です。

重要

After configuration, Kubernetes Operator uses your selected secret storage tool for all secrets except those listed in the limitations. You can't mix and match secret storage tools.

サポートされているシークレット ストレージ ツールには、次の制限があります。

シークレット ストレージ ツールを設定するには、次のいずれかのオプションを選択します。

このMongoDB Controls for Kubernetes Operator ドキュメントのすべてのチュートリアルでは、デフォルトでKubernetes シークレットを使用します。Kubernetes secret を使用してKubernetes Operator のシークレットを保存するには、 Kubernetes Operator のインストールに進み、チュートリアルの手順に従います。

HashiCorp Vault を使用してKubernetes Operator のシークレットを保存するには、次の手順を実行します。

始める前に、以下の操作を行う必要があります。

  • Vault インスタンスを設定します。 Kubernetes Operator が実行されている Kubernetes クラスターは、Vault インスタンスへのアクセス権を持つ必要があります。

    注意

    Ensure that Vault is not running in dev mode and that your Vault installation follows any applicable configuration recommendations.

  • Kubernetes 認証の 有効化 (Vault インスタンスの場合)。これにより、Vault で認証できるようになります。

  • Kubernetesクラスターに Vault Agent サイドカー インジェクションを配置します。これにより、Vault からKubernetesポッドにシークレットを挿入できるようになります。

  • Kubernetes Operator、 MongoDBデータベース、 MongoDB Ops Manager、および AppDB の 4 つの Vault ポリシー ファイル をダウンロードします。

  • Create a role in Vault with the name mongodbenterprise. The configuration of secrets in the Kubernetes Operator relies on the presence of this role and its exact name.

1

次のコマンドを使用して、 Kubernetes Operator、 MongoDB database、 MongoDB Ops Manager 、および AppDB リソースのポリシーを Vault に書き込み、変数を表内の値に置き換えます。

プレースホルダー
説明

{PolicyName}

Vault で作成しているポリシーを識別する、人間に判読可能なラベル。

{PathToPolicyFile}

ダウンロードしたポリシー ファイルへの絶対パス。

vault policy write {PolicyName} {PathToPolicyFile}

Vault に追加するすべてのリソースに対して、 コマンドを繰り返します。

2

次の 4 つのコマンドを使用して、 Kubernetes Operator、 MongoDB database、 MongoDB Ops Manager 、および AppDB リソースのポリシーに Vault ロールをバインドし、変数を表内の値に置き換えます。

プレースホルダー
説明

{OperatorPolicyName}

Vault 内の Kubernetes Operator ポリシーを識別する、人間が判読可能なラベル。

{DatabasePolicyName}

Vault 内の MongoDB database ポリシーを識別する、人間が判読可能なラベル。

{Ops ManagerPolicyName}

Vault 内のMongoDB Ops Managerポリシーを識別する、人間が判読可能なラベル。

{AppDBPolicyName}

Vault 内の AppDB ポリシーを識別する、人間が判読可能なラベル。

{ServiceAccountNamespace}

ポッドにバインドされたサービス アカウントの名前空間を識別するラベル。

vault write auth/kubernetes/role/{OperatorPolicyName}
bound_service_account_names=enterprise-operator bound_service_account_namespaces={ServiceAccountNamespace}
vault write auth/kubernetes/role/{DatabasePolicyName}
bound_service_account_names=mongodb-kubernetes-database-pods bound_service_account_namespaces={ServiceAccountNamespace}
vault write auth/kubernetes/role/{OpsManagerPolicyName}
bound_service_account_names=mongodb-kubernetes-ops-manager bound_service_account_namespaces={ServiceAccountNamespace}
vault write auth/kubernetes/role/{AppDBPolicyName}
bound_service_account_names=mongodb-kubernetes-appdb bound_service_account_namespaces={ServiceAccountNamespace}

これらのコマンドは、各コンポーネントのポッドがポリシーで指定されたアクセスのみを持つことを可能にします。

注意

この手順により、Kubernetes Operator に Vault へのアクセスが許可されます。 Kubernetes Operator が管理しないアプリケーションで Vault を使用するには、それらのアプリケーションの Vault ポリシーを作成してバインドする必要があります。

You can adapt the commands in this step to bind other policies by replacing the name of the service accounts. To configure other applications to use Vault, replace the {ServiceAccountName} in the following command with the service account used for the application's pod:

vault write auth/kubernetes/role/{PolicyName}
bound_service_account_names={ServiceAccountName} bound_service_account_namespaces={ServiceAccountNamespace}
3

Before running commands in this step, ensure that you have created a Vault role with the name mongodbenterprise.

次の強調表示された行を Kubernetes Operator 配置ファイルのspec.template.metadata.annotationsセクションに追加します。 ほとんどのユーザーでは、このファイルの名前はmongodb-kubernetes.yamlまたはmongodb-kubernetes-openshift.yamlです。

注意

Helm を使用して Kubernetes Operator をインストールし、 Operator.vaultSecretBackend.enabledtrueに設定した場合、Kubernetes Operator は次の注釈を追加します。 次の手順に進むことができます。

apiVersion: apps/v1
kind: Deployment
metadata:
name: mongodb-kubernetes-operator
namespace: production
spec:
replicas: 1
template:
metadata:
annotations:
vault.hashicorp.com/agent-inject: "true"
vault.hashicorp.com/role: "mongodbenterprise"

If you're running Vault in TLS mode, and specified the operator.vaultSecretBackend.tlsSecretRef value, the Kubernetes Operator adds the following annotations. Otherwise, add the following highlighted line to the file, replacing {TLSSecret} with the name of the secret containing a ca.crt entry. The content of the ca.crt entry must match the certificate of the CA used to generate the Vault TLS certificates.

annotations:
vault.hashicorp.com/agent-inject: "true"
vault.hashicorp.com/role: "mongodbenterprise"
vault.hashicorp.com/tls-secret: {TLSSecret}
vault.hashicorp.com/ca-cert: /vault/tls/ca.crt
4

次の強調表示された行を Kubernetes Operator 配置ファイルのspec.envセクションに追加します。 ほとんどのユーザーでは、このファイルの名前はmongodb-kubernetes.yamlまたはmongodb-kubernetes-openshift.yamlです。

apiVersion: apps/v1
kind: Deployment
metadata:
name: mongodb-kubernetes-operator
namespace: production
spec:
env:
- name: OPERATOR_ENV
value: ENVIRONMENT_NAME
- name: SECRET_BACKEND
value: VAULT_BACKEND

これ は、環境変数を定義します (Kubernetes の Vault 用)。

5

お好みのテキスト編集アプリケーションを使用して、 configという名前のファイルを作成します。 以下のテキストを ファイルに貼り付けます。

apiVersion: v1
kind: ConfigMap
metadata:
name: secret-configuration
namespace: {Namespace}
data:
VAULT_SERVER_ADDRESS: {VaultServerAddress}
OPERATOR_SECRET_BASE_PATH: mongodbenterprise/operator
DATABASE_SECRET_BASE_PATH: mongodbenterprise/database
OPS_MANAGER_SECRET_BASE_PATH: mongodbenterprise/opsmanager
APPDB_SECRET_BASE_PATH: mongodbenterprise/appdb

このファイル内のパスはデフォルトのパスです。 Kubernetes Operator の構成をカスタマイズした場合は、これらをベース パスに置き換えることができます。

Vault をTLSモードで実行している場合は、 ファイルに次の強調表示された行も追加する必要があります。

OPS_MANAGER_SECRET_BASE_PATH: mongodbenterprise/opsmanager
APPDB_SECRET_BASE_PATH: mongodbenterprise/appdb
TLS_SECRET_REF: {TLSSecret}
6

Replace the placeholders in the config file with these values. Save the file with a YAML file type by replacing the .txt file extension with .yaml.

プレースホルダー
説明

{Namespace}

Kubernetes Operator の作成した名前空間。 デフォルトの名前空間はmongodbです。

{VaultServerAddress}

Kubernetes Operator が Vault に接続するために使用するアドレス。

{TLSsecret}

ca.crtエントリを含むシークレットの名前。 ca.crtエントリの内容は、Vault TLS 証明書の生成に使用されるCAの証明書と一致する必要があります。

7

次のコマンドを発行して、 ConfigMap を作成します Vault 情報を含む:

kubectl create configmap secret-configuration --from-file=config.yaml

This creates a ConfigMap named secret-configuration. This ConfigMap contains the contents of the config file.

8

次のシークレットを Vault に保存するには、手動で移行する必要があります。

新しいシークレットを手動で移行または作成するには、 Vault に追加します。 これらを Vault に追加した後、Kubernetes から削除できます。

Kubernetes Operator が作成する他のすべてのシークレットは自動的に移行され、Kubernetes Operator は新しいシークレットに Vault を使用します。 ユーザーが作成したシークレットはVault に追加する必要があります。

注意

cert-manager は Kubernetes シークレットを 自動的に再作成し、 これらを Kubernetes から削除すると生成されます。これらのシークレットの削除は、Kubernetes に保存されないように手動で管理するか、cert-manager の使用を停止する必要があります。

MongoDB Controls for Kubernetes Operator のシークレットストレージツールを構成すると、次のことが可能になります。