rotateCertificates
定义
版本 5.0 中的新增功能。
rotateCertificates
轮换
mongod
或mongos
当前使用的TLS 证书,以使用配置文件中定义的这些证书的更新值。
兼容性
此命令可用于以下环境中托管的部署:
MongoDB Atlas:用于云中 MongoDB 部署的完全托管服务
注意
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 版本
语法
该命令具有以下语法:
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
rotateCertificates
command to rotate the certificates used by themongod
ormongos
instance.
当证书轮换发生时:
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
进程。
如果mongod
或mongos
在--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" } )