Rotate Keys for Self-Managed Sharded Clusters
Sharded cluster members can use keyfiles to authenticate each other as memers of the same deployment.
キーファイルには複数のキーを含めることができ、少なくとも 1 つのキーがメンバー間で共通の場合、メンバーシップ認証が確立されます。 これにより、ダウンタイムなしでキーのローリング アップグレードが可能になります。
The following tutorial steps through the process to update, without any downtime, the key for a sharded cluster. [1]
警告
The example keys in this tutorial are for illustrative purposes
only. Do NOT use for your deployement. Instead, generate a
keyfile using any method you choose (e.g. openssl rand -base64
756
, etc.).
Consider a sharded cluster where each member's keyfile contains the following key:

The following procedure updates the sharded cluster members to use a new key:

[1] | このチュートリアルは、 MongoDB の暗号化されたストレージ エンジン のローカル キー管理に使用される キー ファイルには適用されません。そのキーファイルには1つのキーしか入れることができません。 |
始める前に
MongoDB 8.0以降では、 directShardOperations
ロールを使用して、シャードに対してコマンドを直接実行する必要があるメンテナンス操作を実行できます。
警告
directShardOperations
ロールを使用して コマンドを実行すると、クラスターが正しく動作しなくなり、データが破損する可能性があります。 directShardOperations
ロールは、メンテナンス目的で、または MongoDB サポートのガイダンスに必ず従う必要があります。 メンテナンス操作を実行したら、 directShardOperations
ロールの使用を停止します。
手順
1. キーファイルを変更して、古いキーと新しいキーを含める
Modify each member's keyfile to include both the old and new keys.
警告
The example keys in this tutorial are for illustrative purposes
only. Do NOT use for your deployement. Instead, generate a
keyfile using any method you choose (e.g. openssl rand -base64
756
, etc.).
You can specify multiple key strings as a sequence of key strings (optionally enclosed in quotes):
1. Restart Each Member
すべてのキーファイルに古いキーと新しいキーの両方が含まれたら、各ノードを一度に 1 つずつ再起動します。
コンフィギュレーションサーバー
For each secondary of the config server replica set (CSRS),
connect mongosh
to the member and:
ノードをシャットダウンするには、
db.shutdownServer()
メソッドを使用します。use admin db.shutdownServer() ノードを再起動します。
プライマリの場合は、 mongosh
をノードに接続し、
rs.stepDown()
を使用してメンバーを降格します。rs.stepDown() ノードをシャットダウンするには、
db.shutdownServer()
メソッドを使用します。use admin db.shutdownServer() ノードを再起動します。
Shard Replica Sets
For each secondary member of the shard replica sets, connect
mongosh
to the member and:
ノードをシャットダウンするには、
db.shutdownServer()
メソッドを使用します。use admin db.shutdownServer() ノードを再起動します。
For the primary of each shard replica set, connect
mongosh
to the member and
rs.stepDown()
を使用してメンバーを降格します。rs.stepDown() ノードをシャットダウンするには、
db.shutdownServer()
メソッドを使用します。use admin db.shutdownServer() ノードを再起動します。
mongos
Routers
For each mongos/router instance, connect
mongosh
to the mongos
instance and:
ノードをシャットダウンするには、
db.shutdownServer()
メソッドを使用します。use admin db.shutdownServer() ノードを再起動します。
Once all members have been restarted, the members now accept either the old or new key for membership authentication.
3. キーファイルの内容を新しいキーのみに更新する
警告
The example keys in this tutorial are for illustrative purposes
only. Do NOT use for your deployement. Instead, generate a
keyfile using any method you choose (e.g. openssl rand -base64
756
, etc.).
各ノードのキーファイルを変更して、新しいパスワードのみを含めます。
4. 各ノードを再起動する
すべてのキーファイルに新しいキーのみが含まれたら、各ノードを一度に 1 つずつ再起動します。
コンフィギュレーションサーバー
For each secondary of the config server replica set (CSRS),
connect mongosh
to the member and:
ノードをシャットダウンするには、
db.shutdownServer()
メソッドを使用します。use admin db.shutdownServer() ノードを再起動します。
プライマリの場合は、 mongosh
をノードに接続し、
rs.stepDown()
を使用してメンバーを降格します。rs.stepDown() ノードをシャットダウンするには、
db.shutdownServer()
メソッドを使用します。use admin db.shutdownServer() ノードを再起動します。
Shard Replica Sets
For each secondary member of the shard replica sets, connect
mongosh
to the member and:
ノードをシャットダウンするには、
db.shutdownServer()
メソッドを使用します。use admin db.shutdownServer() ノードを再起動します。
For the primary of each shard replica set, connect
mongosh
to the member and
rs.stepDown()
を使用してメンバーを降格します。rs.stepDown() ノードをシャットダウンするには、
db.shutdownServer()
メソッドを使用します。use admin db.shutdownServer() ノードを再起動します。
mongos
Routers
For each mongos/router instance, connect
mongosh
to the mongos
instance and:
ノードをシャットダウンするには、
db.shutdownServer()
メソッドを使用します。use admin db.shutdownServer() ノードを再起動します。
Once all members have been restarted, the members now accept only the new key for membership authentication.