Securing connections using TLS

This page explains how to create a Redis instance that uses the TLS protocol and gives instructions for tasks needed to manage a Redis instance that has TLS enabled.

For information on the general behavior and benefits of TLS, see TLS encryption.

For a list of permissions that a user needs in order to perform the management tasks on this page, see TLS permissions.

Creating a Redis instance with TLS

Console

Select Enable Transport Layer Security (TLS) when Creating a Redis instance.

gcloud

To create a Redis instance with TLS enter the following command, replacing variables with appropriate values:

gcloud beta redis instances create instance-id --transit-encryption-mode=SERVER_AUTHENTICATION --size=size --region=region-id

Where:

  • --transit-encryption-mode=SERVER_AUTHENTICATION enables TLS for your instance.

Downloading the Certificate Authority

Console

  1. Go to the Memorystore for Redis page in the Cloud Console.

    Memorystore for Redis

  2. View your instance's Instance details page by clicking on your Instance ID.

  3. Click the Download or Download All button under TLS server certificate.

gcloud

If TLS is enabled on your instance, you see the contents of the Certificate Authority(ies) when you run the following command:

gcloud beta redis instances describe instance-id --region=region

The response body will include all applicable Certificate Authorities. The following is an example Certificate Authority (CA) for Memorystore for Redis:

-----BEGIN CERTIFICATE-----
MIIDnTCCAoWgAwIBAgIBADANBgkqhkiG9w0BAQsFADCBhTEtMCsGA1UELhMkNzYx
NTc4OGMtMTI2Yi00Nzk0LWI2MWMtY2YxOWE2Y2Y1ZjNiMTEwLwYDVQQDEyhHb29n
bGUgQ2xvdWQgTWVtb3J5c3RvcmUgUmVkaXMgU2VydmVyIENBMRQwEgYDVQQKEwtH
b29nbGUsIEluYzELMAkGA1UEBhMCVVMwHhcNMjAwOTE3MjEzNDE1WhcNMzAwOTE1
MjEzNTE1WjCBhTEtMCsGA1UELhMkNzYxNTc4OGMtMTI2Yi00Nzk0LWI2MWMtY2Yx
OWE2Y2Y1ZjNiMTEwLwYDVQQDEyhHb29nbGUgQ2xvdWQgTWVtb3J5c3RvcmUgUmVk
aXMgU2VydmVyIENBMRQwEgYDVQQKEwtHb29nbGUsIEluYzELMAkGA1UEBhMCVVMw
ggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCyDKmDHZm6tzMhNtKOnp8H
8+zTv1qA6OkBToVqCjKTTMGO18ovNtAAMjbGvclLuJNLbA2WTTWVttHen6Cn82h0
3gG9HMk9AwK1cVT7gW072h++TRsYddIRlwnSweRWL8jUX+PNt7CjFqH+sma/Hb1m
CktHdBOa897JiYHrMVNTcpS8SFwwz05yHUTEVGlHdkvlaJXfHLe6keCMABLyjaMh
1Jl4gZI2WqLMV680pJusK6FI6q/NmqENFc9ywMEg395lHTK9w9e014WIXg0q7sU3
84ChVVS2yYOMEUWeov4Qx6XeVfA4ss5t7OCqsMQkvslkE90mJZcVvhBj3QvTH9Rz
AgMBAAGjFjAUMBIGA1UdEwEB/wQIMAYBAf8CAQAwDQYJKoZIhvcNAQELBQADggEB
AJkn+MDE4V10DZn4uEc0s0Mg4FEMC1fDewmDYwSNnxRlzfEi+wAX2AaqrJ4m4Qa7
xIyuSYxArEOY6QeyJyw7/06dom8aAv4aO2p8hE04Ih6QwaTMFIlT2Jf6TidVd3eT
wfjwFJVoJ+dgxsaCv2uMFZWee5aRHmKzj9LhqPwpWnTs9Q/qmOheUNoe2/1i8yvn
662M7RZMR7fZH6ETsdz5w1nPXXiRqJ7K0EGKoPNjMlYK3/U1X3sazI4tpMNgTdxG
rnNh9Sd9REMBmDCPj9dUI9k4hQX4yQZp96fnLT6cet22OPajEKnpzyqJs1s4iX/g
lEtWs4V/YBhKA56CW6ASZS8=
-----END CERTIFICATE-----

Copy and save all of the CAs temporarily so you can install them on clients accessing the Redis instance.

Installing a Certificate Authority on your client

You must install your Redis instance's Certificate Authority(ies) on the connecting client. CA installation can vary depending on the client type. The steps below explain how to install a CA on a Compute Engine Linux VM.

  1. Connect with SSH to your Compute Engine Linux client. This client must be in the same region as your Redis instance in order to connect to it.

  2. Create a file called server_ca.pem in your client by running the following command:

    sudo vim /tmp/server_ca.pem
    
  3. Download the Certificate Authority and paste it into the previously created server_ca.pem file.

    The text of the CA must be formatted correctly:

    • Copy the entire Certificate Authority including the -----BEGIN CERTIFICATE----- and -----END CERTIFICATE----- lines.
    • Make sure that the text of the CA is completely left justified. There should be no spaces in front of any line of the CA.

Configuring your client for TLS

The client you use to connect to the Redis instance with must support TLS or use a third-party sidecar to enable TLS support.

If your client supports TLS, configure it to point to your Redis instance's IP, port 6378, and the file containing the Certificate Authority. If you choose to use a sidecar, we recommend using Stunnel

Additional client configuration

Some clients do not accept self-signed certificates by default and will require additional configuration.

For example, Lettuce is a popular Java client for Redis. Their documentation provides an example for connecting natively with TLS (see Example 47). Given that the Java Security Manager does not allow self-signed certificates by default, an additional option needs to be specified in the Redis URI construction .withVerifyPeer(false).

Securely connecting to a Redis instance using Stunnel and telnet

For instructions on using Stunnel to enable TLS on a Compute Engine client, see Securely connecting to a Redis instance using Stunnel and telnet.

Managing Certificate Authority rotation

You should install all downloadable Certificate Authorities on clients accessing the Redis instance.

Installing the new CA, in addition to the previous CA, once it becomes available is the simplest form of ensuring that you have the necessary CA when the Certificate Authority rotation event occurs.

Run the following command once a new Certificate Authority is introduced to view the contents of the new CA:

gcloud beta instances describe instance-id --region=region

Next, copy and paste the newest Certificate Authority into the file in your client in which you saved the previous CA.

The file should use the following format. The order of the CAs does not matter:

-----BEGIN CERTIFICATE-----
MIIDnTCCAoWgAwIBAgIBADANBgkqhkiG9w0BAQsFADCBhTEtMCsGA1UELhMkNzYx
NTc4OGMtMTI2Yi00Nzk0LWI2MWMtY2YxOWE2Y2Y1ZjNiMTEwLwYDVQQDEyhHb29n
bGUgQ2xvdWQgTWVtb3J5c3RvcmUgUmVkaXMgU2VydmVyIENBMRQwEgYDVQQKEwtH
b29nbGUsIEluYzELMAkGA1UEBhMCVVMwHhcNMjAwOTE3MjEzNDE1WhcNMzAwOTE1
MjEzNTE1WjCBhTEtMCsGA1UELhMkNzYxNTc4OGMtMTI2Yi00Nzk0LWI2MWMtY2Yx
OWE2Y2Y1ZjNiMTEwLwYDVQQDEyhHb29nbGUgQ2xvdWQgTWVtb3J5c3RvcmUgUmVk
aXMgU2V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----END CERTIFICATE-----

All you need to do to make sure that you have the required CA is to make sure that the CAs saved in your client file match those shown by gcloud redis instances describe. After a rotation event begins there are multiple CAs to ensure ample time for rotations with minimal downtime.

What's next