Expired TLS certificates can prevent new client connections and, when X.509 is used for Percona Server for MongoDB internal authentication, also prevent members of a replica set or sharded cluster from authenticating to one another.
In this post we will discuss performing a same-CA renewal: replacement certificates for server, member, and client leaf are issued by the existing trusted CA, and the X.509 attributes used for cluster membership do not change. In this scenario, the rotateCertificates command reloads TLS material for new connections without restarting mongod or mongos.
Important: Do not apply this hot-reload procedure when replacing the issuing CA, changing a certificate subject DN, or changing cluster-membership attributes. Those are not ordinary renewals.
Percona Server for MongoDB can reload the files configured through the following TLS options:
|
1 2 3 4 5 6 |
net: tls: mode: requireTLS certificateKeyFile: /etc/mongod/tls/server.pem CAFile: /etc/mongod/tls/ca.pem clusterFile: /etc/mongod/tls/cluster.pem |
The certificateKeyFile contains the certificate and private key presented to normal clients. The clusterFile holds the certificate and key that a mongod or mongos process presents when connecting to other cluster members. If clusterFile is not configured, certificateKeyFile is also used for member authentication.
The rotateCertificates command affects new TLS connections. It does not terminate established client sessions or force a replica-set election.
Begin this process well in advance of the certificate expiry, and avoid performing your first attempt in a production environment.
Stage a renewed server or member certificate
There are a few limitations for rotating certificates online:
If CAFile, a CRL, or another configured TLS input is being renewed as part of the same operation, replace it before invoking the reload command. The command reloads the configured TLS inputs as a set; a missing or invalid input causes the reload to fail.
Luckily, incorrect certificate files will cause the rotation to fail, but will not invalidate the existing configuration or have any other side effects.
Connect directly to the specific mongod or mongos with an administrative user and execute the following command:
|
1 |
db.getSiblingDB("admin").runCommand({rotateCertificates: 1, message: "Renewed TLS certificate"})' |
Immediately validate a new TLS connection to that process with a renewed client certificate. Also inspect the log for the successful certificate-rotation message and any TLS errors. Check our documentation for guidelines to perform the procedure on a replica set or sharded cluster.
After completing the procedure, it is a good idea to reconfirm the expiry date and SANs of the certificate presented by every mongod and mongos. Retain the old certificates only for the approved overlap period, then remove or revoke them. Don’t forget to record the new expiry dates and create alerts with enough lead time before the expiration date of the new certificates.
A different procedure is required when any of the following changes:
This is a topic for another time.
Resources
RELATED POSTS