If your Valkey/Redis deployments use SSL/TLS, you will eventually need to rotate the TLS certificates. Perhaps it is because the certificates are expiring, or you made mistakes when creating them, or it could be that the private key has been leaked. This article explains the process of rotating the TLS/SSL certificates used by Valkey/Redis deployments without affecting service availability.

Environment and configurations

In this post, we will rotate TLS certificates for a 6-node Valkey cluster (the process will also apply to standalone or Sentinel deployments)

Our working directory will have the following files: the server-new.pem and server-new-key.pem files will be the key pair used to replace server.pem and server-key.pem (You can quickly create TLS key pairs by following our guide on GitHub)

The configuration files for each node will have the following parameters related to TLS (in addition to other parameters required for clustering):

Back up the TLS certificates currently being used

Before we do anything, it is ideal to have a backup ready. In the event that anything goes wrong, we can still revert to the previous configurations.

Overwrite the currently used certificates with the new ones

We will replace the content of the old certificates with the new ones (server-new.pem and server-new-key.pem), and Valkey/Redis instances will pick it up when they reload the configuration

“Why can’t I just update the configs to point to the new key pair?”

If you execute a CONFIG SET to point the tls-*-file configs to the new location, it will not work. This is because Valkey/Redis will reconfigure itself with every CONFIG SET command, and since you cannot update multiple parameters at once, updating it sequentially will result in a key pair mismatch error:

And the log file will show the following entries:

Reload the TLS configuration in Valkey instances

After overwriting the key pair contents, we can instruct Valkey instances to pick up the new keys by executing CONFIG SET on a TLS-related parameter (we can set it to the existing value, no need to change anything here):

Note: Please remember to run the CONFIG SET command on all nodes in the cluster

We can confirm that no loss of service occurred by grepping the instances’ log files for errors, or by querying the cluster’s status:

As we can see, after rotating, the instances can still communicate with each other.

On the Client’s side

If your Valkey/Redis instances have their new TLS certificates signed by the old Certificate Authority (CA), then your clients can still connect to the deployment normally. However, if you do not have a CA (i.e., using self-signed certificates) or use another CA, ensure that your clients’ truststores have the relevant public keys imported to maintain service connectivity.

Conclusion

In this article, we have discussed the procedure for rotating SSL/TLS certificates in a Valkey/Redis deployment without incurring any downtime. However, as always, please test the procedure before applying it to your production environment.

 

Redis vs Valkey: Choosing the Right Fit for Your Organization

Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments