Docs 菜单

rotateCertificates

版本 5.0 中的新增功能

rotateCertificates

轮换mongodmongos当前使用的TLS 证书,以使用配置文件中定义的这些证书的更新值。

此命令可用于以下环境中托管的部署:

注意

This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.

该命令具有以下语法:

db.runCommand(
{
rotateCertificates: 1,
message: "<optional log message>"
}
)

该命令采用以下可选字段:

Parameter
类型
说明

message

字符串

可选服务器记录到日志文件和审核文件中的消息。

The rotateCertificates command returns a document with the following field:

字段
类型
说明

ok

bool

包含命令的执行状态。 成功则为true ,如果发生错误则为false 。 如果为false ,则另外向errmsg字段提供详细的错误消息。

轮换包括以下证书:

轮换一个或多个证书:

  1. 替换您要在文件系统中轮换的证书,并注意以下限制:

    • 每个新证书的文件名文件路径必须与被替换的证书相同。

    • 如果轮换加密的 TLS Certificate,其密码必须与旧证书的密码相同(如 certificateKeyFilePassword 配置文件设置所指定)。证书轮换不支持交互式密码提示。

  2. mongosh 连接到您想执行证书轮换的 mongodmongos 实例。

  3. Run the rotateCertificates command to rotate the certificates used by the mongod or mongos instance.

当证书轮换发生时:

  • mongod}mongos 实例的现有连接不会终止,并将继续使用旧证书。

  • 所有新连接都将使用新证书。

If you have configured OCSP for your deployment, the rotateCertificates command will also fetch stapled OCSP responses during rotation.

The rotateCertificates command may be run on a running mongod or mongos regardless of replication status.

Only one instance of db.rotateCertificates() or rotateCertificates may run on each mongod or mongos process at a time. Attempting to initiate a second instance while one is already running will result in an error.

证书文件错误、过期、撤销或丢失会导致证书轮换失败,但不会导致现有 TLS 配置失效或终止正在运行的 mongodmongos 进程。

如果mongodmongos--tlsCertificateSelector设置为thumbprint的情况下运行, rotateCertificates将失败并向日志文件写入一条警告消息。

成功轮换后,主题名称、指纹以及服务器和集群证书指纹的有效期都会记录到配置的日志目标中。 如果已启用审核,此信息也会写入审核日志。

在 Linux 和 Windows 平台上,如果存在CRL file ,其指纹和有效期也会记录到这些位置。

You must have the rotateCertificates 操作 in order to use the rotateCertificates command. The rotateCertificates action is part of the hostManager role.

对配置文件进行适当更新以指定更新的证书信息后,以下操作将在运行中的mongod实例上轮换证书:

db.adminCommand( { rotateCertificates: 1 } )

以下操作的执行与上述操作相同,但还会在轮换时将自定义日志消息写入日志文件审核文件:

db.adminCommand( { rotateCertificates: 1, message: "Rotating certificates" } )