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

X.509 による内部認証の保護

このガイドでは、次の設定方法について説明します。

  • クラスター内の MongoDB ノード間の X.509 内部認証。

  • クライアントから MongoDB インスタンスへの X.509 認証。

Kubernetes Operator は、クラスター内の MongoDB ノード間の他の認証スキームをサポートしていません。

注意

Kubernetes クラスターでは MongoDB のスタンドアロン インスタンスを保護することはできません。

TLS暗号化を使用して MongoDB 配置のいずれかを保護する前に、次の手順を完了してください。

プロジェクト レベルで X.509 認証を有効にすると、すべてのエージェントが MongoDB 配置で通信するときに X.509 クライアント認証を使用するように構成されます。

X.509 を使用してレプリカセットを保護する前に、TLS で暗号化されたレプリカセットをデプロイします。

1

このkubectl コマンドを実行して新しい シークレット を作成します レプリカセットの証明書を保存する

kubectl create secret tls <prefix>-<metadata.name>-clusterfile \
--cert=<replica-set-clusterfile-tls-cert> \
--key=<replica-set-clusterfile-tls-key>

注意

シークレットの前に<prefix>-<metadata.name>を付ける必要があります。

For example, if you call your deployment my-deployment and you set the prefix to mdb, you must name the TLS secret for the client TLS communications mdb-my-deployment-cert. Also, you must name the TLS secret for internal cluster authentication (if enabled) mdb-my-deployment-clusterfile.

2

このYAMLファイルの設定を、必要なレプリカセット構成に合わせて変更します。

1---
2apiVersion: mongodb.com/v1
3kind: MongoDB
4metadata:
5 name: <my-replica-set>
6spec:
7 members: 3
8 version: "8.0.0"
9 opsManager:
10 configMapRef:
11 # Must match metadata.name in ConfigMap file
12 name: <configMap.metadata.name>
13 credentials: <mycredentials>
14 type: ReplicaSet
15 persistent: true
16 security:
17 tls:
18 ca: <custom-ca>
19 certsSecretPrefix: <prefix>
20 authentication:
21 enabled: true
22 modes: ["X509"]
23 internalCluster: "X509"
24...
3

Open your preferred text editor and paste the object specification at the end of your resource file in the spec section.

4

配置で TLS と X.509 を有効にするには、 Kubernetesオブジェクトで次の設定を構成します。

キー
タイプ
必要性
説明

spec.security
.authentication
.enabled

ブール値

必須

MongoDB 配置で認証を有効にするには、この値をtrueに設定します。

true

spec.security
.authentication
.modes

配列

条件付き

この値を["X509"]に設定します。

["X509"]

5

To enable TLS and X.509 in your deployment, configure the following settings in your Kubernetes object:

キー
タイプ
必要性
説明

spec.security
.authentication
.internalCluster

string

必須

この設定を使用して、 X.509 内部クラスター認証 を有効にします。

重要:内部クラスター認証が有効になっている場合は、無効にすることはできません。

X509

6
7

レプリカセットを更新するには、次の Kubernetes コマンドを呼び出します。

kubectl apply -f <replica-set-conf>.yaml
8

MongoDBリソースのステータスを確認するには、次のコマンドを使用します。

kubectl get mdb <resource-name> -o yaml -w

-w (監視)フラグが設定されている場合、構成が変更されると、ステータスフェーズがRunning状態に達するまで出力が直ちに更新されます。 リソース配置ステータスの詳細については、 「 Kubernetes 演算子のトラブルシューティング 」を参照してください。

すでに証明書を作成している場合は、次の手順で定期的に更新することをお勧めします。

1

まだ作成していない場合は、次のコマンドを実行して、作成した名前空間ですべてのkubectlコマンドを実行します

注意

MongoDB Ops Manager リソースを複数の Kubernetes クラスター MongoDB 配置に配置している場合、次の手順に従います。

  • context を演算子クラスターの名前に設定します(kubectl config set context "$MDB_CENTRAL_CLUSTER_FULL_NAME" など)。

  • MongoDB のマルチ配置に使用したのと同じスコープ(例: kubectl config --namespace "mongodb"--namespaceを設定します。

kubectl config set-context $(kubectl config current-context) --namespace=<metadata.namespace>
2

既存の シークレット を更新するには、このkubectl コマンドを実行します レプリカセットの証明書を保存する

kubectl create secret tls <prefix>-<metadata.name>-cert \
--cert=<replica-set-tls-cert> \
--key=<replica-set-tls-key> \
--dry-run=client \
-o yaml |
kubectl apply -f -
3

既存の シークレット を更新するには、このkubectl コマンドを実行します レプリカセットの証明書を保存する

kubectl create secret tls <prefix>-<metadata.name>-clusterfile \
--cert=<replica-set-clusterfile-tls-cert> \
--key=<replica-set-clusterfile-tls-key> \
--dry-run=client \
-o yaml |
kubectl apply -f -
4

kubectlエージェントの X.509 証明書を保存する既存のシークレットを更新するには、次の コマンドを実行します。

kubectl create secret tls <prefix>-<metadata.name>-agent-certs \
--cert=<agent-tls-cert> \
--key=<agent-tls-key> \
--dry-run=client \
-o yaml |
kubectl apply -f -

X.509 を使用してシャーディングされたクラスターを保護する前に、 TLS で暗号化されたシャーディングされたクラスターをデプロイしてください。

1

次の kubectl コマンドを実行して、シャーディングされたクラスターシャードの証明書を保存する新しいシークレットを作成します。

kubectl -n mongodb create secret tls <prefix>-<metadata.name>-0-clusterfile \
--cert=<shard-0-clusterfile-tls-cert> \
--key=<shard-0-clusterfile-tls-cert>
kubectl -n mongodb create secret tls <prefix>-<metadata.name>-1-clusterfile \
--cert=<shard-1-clusterfile-tls-cert> \
--key=<shard-1-clusterfile-tls-cert>
2

このkubectl コマンドを実行して新しい シークレット を作成します シャーディングされたクラスター コンフィギュレーションサーバー の証明書を保存する:

kubectl -n mongodb create secret tls <prefix>-<metadata.name>-config-clusterfile \
--cert=<config-clusterfile-tls-cert> \
--key=<config-clusterfile-tls-cert>
3

次のkubectl コマンドを実行して、シャーディングされたクラスター mongos証明書を保存する新しいシークレットを作成します。

kubectl -n mongodb create secret tls <prefix>-<metadata.name>-mongos-clusterfile \
--cert=<mongos-clusterfile-tls-cert> \
--key=<mongos-clusterfile-tls-cert>
4

このYAMLファイルの設定を、シャーディングされたクラスターの構成に合わせて変更します。

1---
2apiVersion: mongodb.com/v1
3kind: MongoDB
4metadata:
5 name: <my-sharded-cluster>
6spec:
7 shardCount: 2
8 mongodsPerShardCount: 3
9 mongosCount: 2
10 configServerCount: 3
11 version: "8.0.0"
12 opsManager:
13 configMapRef:
14 name: <configMap.metadata.name>
15 # Must match metadata.name in ConfigMap file
16 credentials: <mycredentials>
17 type: ShardedCluster
18 persistent: true
19 security:
20 tls:
21 ca: <custom-ca>
22 certsSecretPrefix: <prefix>
23 authentication:
24 enabled: true
25 modes: ["X509"]
26 internalCluster: "X509"
27...
5

Open your preferred text editor and paste the object specification at the end of your resource file in the spec section.

6

To enable TLS and X.509 in your deployment, configure the following settings in your Kubernetes object:

キー
タイプ
必要性
説明

spec.security
.authentication
.enabled

ブール値

必須

MongoDB 配置で認証を有効にするには、この値をtrueに設定します。

true

spec.security
.authentication
.modes

配列

条件付き

この値を["X509"]に設定します。

["X509"]

7

To enable TLS and X.509 in your deployment, configure the following settings in your Kubernetes object:

キー
タイプ
必要性
説明

spec.security
.authentication
.internalCluster

string

必須

Use this setting to enable X.509 internal cluster authentication.

重要:内部クラスター認証が有効になっている場合は、無効にすることはできません。

X509

8
9

任意のディレクトリで、次の Kubernetes コマンドを呼び出して、シャーディングされたクラスターを更新して再起動します。

kubectl apply -f <sharded-cluster-conf>.yaml
10

MongoDBリソースのステータスを確認するには、次のコマンドを使用します。

kubectl get mdb <resource-name> -o yaml -w

-w (監視)フラグが設定されている場合、構成が変更されると、ステータスフェーズがRunning状態に達するまで出力が直ちに更新されます。 リソース配置ステータスの詳細については、 「 Kubernetes 演算子のトラブルシューティング 」を参照してください。

すでに証明書を作成している場合は、次の手順で定期的に更新することをお勧めします。

1

まだ作成していない場合は、次のコマンドを実行して、作成した名前空間ですべてのkubectlコマンドを実行します

注意

MongoDB Ops Manager リソースを複数の Kubernetes クラスター MongoDB 配置に配置している場合、次の手順に従います。

  • context を演算子クラスターの名前に設定します(kubectl config set context "$MDB_CENTRAL_CLUSTER_FULL_NAME" など)。

  • MongoDB のマルチ配置に使用したのと同じスコープ(例: kubectl config --namespace "mongodb"--namespaceを設定します。

kubectl config set-context $(kubectl config current-context) --namespace=<metadata.namespace>
2

既存の シークレット を更新するには、このkubectl コマンドを実行します シャーディングされたクラスター シャードの証明書を保存する:

kubectl -n mongodb create secret tls <prefix>-<metadata.name>-0-cert \
--cert=<shard-0-tls-cert> \
--key=<shard-0-tls-key> \
--dry-run=client \
-o yaml |
kubectl apply -f -
kubectl -n mongodb create secret tls <prefix>-<metadata.name>-1-cert \
--cert=<shard-1-tls-cert> \
--key=<shard-1-tls-key> \
--dry-run=client \
-o yaml |
kubectl apply -f -
3

シャーディングされたクラスターコンフィギュレーションサーバーの証明書を保存する既存のシークレットを更新するには、次の kubectl コマンドを実行します。

kubectl -n mongodb create secret tls <prefix>-<metadata.name>-config-cert \
--cert=<config-tls-cert> \
--key=<config-tls-key> \
--dry-run=client \
-o yaml |
kubectl apply -f -
4

Run this kubectl command to renew an existing secret that stores the sharded cluster mongos certificates:

kubectl -n mongodb create secret tls <prefix>-<metadata.name>-mongos-cert \
--cert=<mongos-tls-cert> \
--key=<mongos-tls-key> \
--dry-run=client \
-o yaml |
kubectl apply -f -
5

既存の シークレット を更新するには、このkubectl コマンドを実行します シャーディングされたクラスター シャードの証明書を保存する:

kubectl -n mongodb create secret tls <prefix>-<metadata.name>-0-clusterfile \
--cert=<shard-0-clusterfile-tls-cert> \
--key=<shard-0-clusterfile-tls-cert> \
--dry-run=client \
-o yaml |
kubectl apply -f -
kubectl -n mongodb create secret tls <prefix>-<metadata.name>-1-clusterfile \
--cert=<shard-1-clusterfile-tls-cert> \
--key=<shard-1-clusterfile-tls-cert> \
--dry-run=client \
-o yaml |
kubectl apply -f -
6

シャーディングされたクラスターコンフィギュレーションサーバー の証明書を保存する既存のシークレットを更新するには、次の kubectl コマンドを実行します。

kubectl -n mongodb create secret tls <prefix>-<metadata.name>-config-clusterfile \
--cert=<config-clusterfile-tls-cert> \
--key=<config-clusterfile-tls-cert> \
--dry-run=client \
-o yaml |
kubectl apply -f -
7

Run this kubectl command to renew an existing secret that stores the sharded cluster mongos certificates:

kubectl -n mongodb create secret tls <prefix>-<metadata.name>-mongos-clusterfile \
--cert=<mongos-clusterfile-tls-cert> \
--key=<mongos-clusterfile-tls-cert> \
--dry-run=client \
-o yaml |
kubectl apply -f -
8

Run this kubectl command to renew an existing secret that stores the agents' X.509 certificates:

kubectl create secret tls <prefix>-<metadata.name>-agent-certs \
--cert=<agent-tls-cert> \
--key=<agent-tls-key> \
--dry-run=client \
-o yaml |
kubectl apply -f -