定义
版本 5.0 中的新增功能。
rotateCertificatesRotates the currently used TLS certificates for a
mongodormongosto use the updated values for these certificates defined in the configuration file.
兼容性
此命令可用于以下环境中托管的部署:
- MongoDB Atlas: The fully managed service for MongoDB deployments in the cloud
注意
This command is supported in all MongoDB Atlas clusters. For information on Atlas support for all commands, see Unsupported Commands.
MongoDB Enterprise:基于订阅、自我管理的 MongoDB 版本
MongoDB Community:源代码可用、免费使用且可自行管理的 MongoDB 版本
注意
Atlas会自动轮换证书。使用Atlas时,无需运行rotateCertificates 命令。仅当您想手动轮换证书时才使用 rotateCertificates 命令。
语法
该命令具有以下语法:
db.runCommand( { rotateCertificates: 1, message: "<optional log message>" } )
命令字段
该命令采用以下可选字段:
Parameter | 类型 | 说明 |
|---|---|---|
| 字符串 | 可选服务器记录到日志文件和审核文件中的消息。 |
输出
The rotateCertificates command returns a document with the following field:
字段 | 类型 | 说明 |
|---|---|---|
| bool | 包含命令的执行状态。 成功则为 |
行为
轮换包括以下证书:
CRL (Certificate Revocation List) files(在 Linux 和 Windows 平台上)
轮换一个或多个证书:
替换您要在文件系统中轮换的证书,并注意以下限制:
每个新证书的文件名和文件路径必须与被替换的证书相同。
如果轮换加密的
TLS Certificate,其密码必须与旧证书的密码相同(如certificateKeyFilePassword配置文件设置所指定)。证书轮换不支持交互式密码提示。
Run the
rotateCertificatescommand to rotate the certificates used by themongodormongosinstance.
当证书轮换发生时:
所有新连接都将使用新证书。
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 配置失效或终止正在运行的 mongod 或 mongos 进程。
If the mongod or mongos is running with --tlsCertificateSelector set to thumbprint, rotateCertificates will fail and write a warning message to the log file.
日志记录
成功轮换后,主题名称、指纹以及服务器和集群证书指纹的有效期都会记录到配置的日志目标中。 如果已启用审核,此信息也会写入审核日志。
在 Linux 和 Windows 平台上,如果存在CRL file ,其指纹和有效期也会记录到这些位置。
必需的访问权限
You must have the rotateCertificates action 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" } )