Rotate X.509 Certificates without clusterAuthX509 Attributes on Self-Managed Clusters
Members of a replica set or a sharded cluster can use X.509
certificates for membership authentication to
identify other servers in the same deployment. This tutorial describes how to
perform a rolling update to rotate X.509 certificates on a cluster
that doesn't use the net.tls.clusterAuthX509
settings
to configure Distinguished Name (DN) attributes.
注意
To perform a rolling update to rotate certificates on a cluster that uses
the net.tls.clusterAuthX509
settings or on a cluster that will use
these settings after the update, see Rotate X.509 Certificates with clusterAuthX509 Attributes on Self-Managed Clusters.
当服务器节点收到连接请求时,它会将所提供证书的 subject
字段中的标识名 (DN) 属性与其自身证书的主题 DN 属性进行比较。 如果证书的主题包含相同的组织 (O
)、组织单位 (OU
) 和域组件 (DC
) 属性值,则证书匹配。 服务器的配置文件还可以指定备用 DN 属性,用于在tlsX509ClusterAuthDNOverride
参数中进行匹配。如果服务器的主题 DN 属性或配置的 值与所提供证书的主题 DNtlsX509ClusterAuthDNOverride
属性匹配,则服务器节点会将该连接视为集群成员。
在某些情况下,您可能需要将成员证书更新为具有新的主题标识名 (DN) 属性的新证书,例如,如果组织更改了名称。 在 滚动更新中,一次更新一个成员证书,并且您的部署不会导致任何停机。
在证书轮换过程中,采用新证书的集群可以使用tlsX509ClusterAuthDNOverride
509参数接受具有不同主题 DN 属性的 x. 证书。一旦所有成员都使用具有新值的证书,删除覆盖以开始拒绝现已过期的证书。
关于此任务
Consider a replica set where each member's X.509 certificates,
set using the clusterFile
and certificateKeyFile
settings,
have subject DN attributes of "OU=10gen Server,O=10gen"
.
此副本集的成员具有以下配置文件:
net.tls.mode: requireTLS net.tls.certificateKeyFile: "./mycerts/10gen-server1.pem" net.tls.CAFile: "./mycerts/ca.pem" security.clusterAuthMode: x509 net.tls.clusterFile: "./mycerts/10gen-cluster1.pem" net.tls.clusterCAFile: "./mycerts/ca.pem"
以下过程将每个成员的证书更新为主题 DN 属性为 "OU=MongoDB Server, O=MongoDB"
的新证书。
注意
The following procedure assumes that the new X.509 certificates meet membership certificate and all other requirements and that the cluster configuration identifies peer certificates using Distinguished Name (DN) values. For more information, see 成员证书要求.
步骤
在所有成员上设置覆盖参数。
在滚动更新期间,成员一次会使用新配置重新启动。 要允许具有旧主题 DN 属性的服务器节点将具有新主题 DN 属性的节点标识为集群成员,设立在所有运行节点上将覆盖参数设置为新主题 DN 属性。
为此,请修改每个服务器的配置文件,将 参数设立为使用新证书的主题 DNtlsX509ClusterAuthDNOverride
属性:
net.tls.mode: requireTLS net.tls.certificateKeyFile: "./mycerts/10gen-server1.pem" net.tls.CAFile: "./mycerts/ca.pem" security.clusterAuthMode: x509 net.tls.clusterFile: "./mycerts/10gen-cluster1.pem" net.tls.clusterCAFile: "./mycerts/ca.pem" setParameter: tlsX509ClusterAuthDNOverride: "OU=MongoDB Server,O=MongoDB"
在重新启动每个成员之前,不会考虑此配置。
重新启动所有成员。
要对所有成员执行滚动重启,请重启每个从节点(secondary node from replica set),然后重启主节点 (primary node in the replica set)。
对于每个从节点(secondary node frommongosh
replica set)节点,将 连接到该节点,然后:
使用
db.shutdownServer()
方法关闭成员:use admin db.shutdownServer() 重新启动成员。
在重新启动下一个从从节点(secondary node from replica set)之前,请确保该节点已达到
SECONDARY
状态。要确定成员状态,运行rs.status()
并读取stateStr
字段的值。rs.status().members
对于主节点 (primary node mongosh
in the replica set)节点,将 连接到该节点,然后:
使用
rs.stepDown()
降级该节点:rs.stepDown() 使用
db.shutdownServer()
方法关闭成员:use admin db.shutdownServer() 重新启动成员。
副本集集中的所有服务器现在都可以使用覆盖参数接受来自使用具有新主题 DN 属性的证书的成员的对等连接。
修改所有成员的配置。
更新每个服务器的配置文件:
net.tls.certificateKeyFile
将 设置更改为新证书。net.tls.clusterFile
将 设置更改为新证书。将
tlsX509ClusterAuthDNOverride
参数设置为使用旧证书的 标识名 属性。
例如:
net.tls.mode: requireTLS net.tls.certificateKeyFile: "./mycerts/mongodb-server1.pem" net.tls.CAFile: "./mycerts/ca.pem" security.clusterAuthMode: x509 net.tls.clusterFile: "./mycerts/mongodb-cluster1.pem" net.tls.clusterCAFile: "./mycerts/ca.pem" setParameter: tlsX509ClusterAuthDNOverride: "OU=10Gen Server,O=10Gen"
在重新启动每个成员之前,不会考虑此配置。
重新启动所有成员。
应用更新后的配置应用于每个成员,请重复从步骤 2 开始的过程,以滚动重启服务器节点。
在此进程中,使用新证书重新启动的节点将使用 中存储的旧 DNtlsX509ClusterAuthDNOverride
属性来识别提供旧证书的节点。仍具有旧证书的节点将使用存储在 中的新 DNtlsX509ClusterAuthDNOverride
来识别提供新证书的节点。
从所有成员中删除覆盖参数。
要防止更新的服务器节点将提供旧证书的客户端视为对等节点,请从所有服务器节点配置文件中删除tlsX509ClusterAuthDNOverride
参数。
例如:
net.tls.mode: requireTLS net.tls.certificateKeyFile: "./mycerts/mongodb-server1.pem" net.tls.CAFile: "./mycerts/ca.pem" security.clusterAuthMode: x509 net.tls.clusterFile: "./mycerts/mongodb-cluster1.pem" net.tls.clusterCAFile: "./mycerts/ca.pem"
在重新启动每个成员之前,不会考虑此配置。