Rolling Update of x.509 Cluster Certificates that Contain New DN
Members of a replica set or a sharded cluster can use x.509certificates for membership authentication toidentify each other as memers of the same deployment.
To identify each others as members of the same deployment, theOrganization attributes (O
’s), the Organizational Unit attributes(OU
’s), and the Domain Components (DC
’s) from thecertificates must match.
In some situations, you may need to update the member certificates tonew certificates with the new Distinguished Name (DN
), such as ifan organization changes its name. Starting in version 4.2, MongoDBprovides a new tlsX509ClusterAuthDNOverride
parameter toset an alternative DN
to use in matching. Using this parameter, youcan perform a rolling update of the certificates to new certificateswith different DN
.
The following tutorial describes the process to update thecertificates for a replica set without downtime.
Consider a replica set where each member’s certificates(clusterFile
andcertificateKeyFile
) with DN
value that contains"OU=10gen Server,O=10gen"
(additional attributes are not consideredas part of the comparison):
- 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"
The following procedure updates the members’ certificates(clusterFile
andcertificateKeyFile
) to new certificates that have aDN
value with "OU=MongoDB Server,O=MongoDB"
.
Note
The following procedure assumes that the new x.509 certificates meetmembership certificate all other requirements. For details, seeMember Certificate Requirements
Procedure
0. Optional. Set Override Parameter on Running Members
The procedure requires that all members of the deployment berestarted. As the settings will not take into consideration untilyou restart all members, your instances may log messages until theprocedure completes.
To avoid these messages, you can set the override parameter onrunning members.
Connect a mongo
shell directly to each member of thedeployment and set the tlsX509ClusterAuthDNOverride
parameter to the new certificate DN
:
- db.adminCommand( { setParameter: 1, tlsX509ClusterAuthDNOverride: "OU=MongoDB Server,O=MongoDB" } )
1. Modify the Configuration of ALL Members
Modify each member’s configuration:
- Update
net.tls.certificateKeyFile
to the new certificate. - Update
net.tls.clusterFile
to the new certificate. - Set
tlsX509ClusterAuthDNOverride
parameter to the newcertificateDN
.
For example:
- 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=MongoDB Server,O=MongoDB"
The settings will not take into consideration until you restart eachmember (see next step).
2. Restart Each Member
Once you have modified the configuration for all the members,restart each secondaries and then the primary.
For each secondary member, connect a mongo
shell to themember and:
- Use the
db.shutdownServer()
method to shut down the member:
- use admin
- db.shutdownServer()
- Restart the member.
Ensure the member has reached SECONDARY
state beforerestarting the next secondary.
For the primary, connect a mongo
shell to the member and
- Use
rs.stepDown()
to step down the member:
- rs.stepDown()
- Use the
db.shutdownServer()
method to shut down the member:
- use admin
- db.shutdownServer()
- Restart the member.
3. Remove the tlsX509ClusterAuthDNOverride Setting
Once all the members have been restarted with the new certificate,you can remove the tlsX509ClusterAuthDNOverride
parameter fromthe configuration.
For example:
- 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"
The settings will not take into consideration until you restart eachmember.