Skip to content

Redis TLS encryption for client and replication traffic

Issue certificates, configure tls-port and tls-cert-file, enable replication and cluster bus TLS, and connect clients with redis-cli --tls and a CA bundle.

Redis since 6.0 supports TLS natively — no stunnel sidecar, no ghetto wrappers. Once configured, the daemon accepts TLS connections on tls-port (in parallel with or instead of plaintext port), and replication, cluster bus, and Sentinel traffic can all be encrypted with the same certificate set. This article covers issuing the certificates, the tls-* configuration lines that matter, mutual TLS for client authentication, and the verification steps before traffic is migrated.

How to verify

# Confirm TLS is enabled
redis-cli CONFIG GET tls-port
redis-cli CONFIG GET tls-cert-file
redis-cli CONFIG GET tls-replication

# Probe with openssl
openssl s_client -connect redis.example.com:6380 -servername redis.example.com -showcerts </dev/null | head -20

# Connect via redis-cli
redis-cli --tls --cacert /etc/ssl/redis/ca.crt \
  -h redis.example.com -p 6380 -a "$PASS" PING

What’s happening

Redis TLS uses OpenSSL under the hood and operates at three points in the protocol:

  1. Client connections. tls-port listens for TLS-wrapped RESP traffic. Setting port 0 disables plaintext entirely; leaving both ports open is the migration mode.
  2. Replication. tls-replication yes tells replicas to connect to the master over TLS — important because the replication stream carries every write in plaintext otherwise.
  3. Cluster bus. tls-cluster yes encrypts the gossip traffic between cluster nodes on port 16379.

All three share the same certificate set: tls-cert-file, tls-key-file, tls-ca-cert-file (the CA that signs both server and, in mTLS, client certs). The tls-auth-clients knob controls whether the server requires a client certificate (yes), accepts one if present (optional), or never asks (no).

The package matters: Ubuntu’s Redis builds since 22.04 include TLS by default. If you compiled from source you must make BUILD_TLS=yes, and the binary will say tls-cert-file: required on any TLS line if it was not built with TLS.

The certificate identity must match the client’s connection hostname. A self-signed CA is fine for internal traffic, but the CN/SAN on the server cert must match how clients connect (DNS name or IP).

The procedure

  1. Issue a self-signed CA for internal use (or use your existing PKI).

    sudo mkdir -p /etc/ssl/redis && cd /etc/ssl/redis
    openssl genrsa -out ca.key 4096
    openssl req -x509 -new -nodes -sha256 -days 3650 -key ca.key \
      -subj "/CN=Internal Redis CA" -out ca.crt
  2. Issue a server certificate with SANs for every name and IP clients will use:

    openssl genrsa -out server.key 2048
    openssl req -new -key server.key -out server.csr \
      -subj "/CN=redis-01.internal"
    cat >server.ext <<EOF
    subjectAltName = DNS:redis-01.internal, DNS:redis.example.com, IP:10.0.0.11
    EOF
    openssl x509 -req -in server.csr -CA ca.crt -CAkey ca.key \
      -CAcreateserial -out server.crt -days 825 -sha256 -extfile server.ext
    sudo chown -R redis:redis /etc/ssl/redis
    sudo chmod 0600 /etc/ssl/redis/*.key
  3. Configure redis.conf for TLS on 6380, keeping plaintext 6379 open during migration:

    port 6379
    tls-port 6380
    tls-cert-file /etc/ssl/redis/server.crt
    tls-key-file /etc/ssl/redis/server.key
    tls-ca-cert-file /etc/ssl/redis/ca.crt
    tls-dh-params-file /etc/ssl/redis/dhparam.pem
    tls-auth-clients no
    tls-protocols "TLSv1.2 TLSv1.3"
    tls-ciphers HIGH:!aNULL:!MD5
    tls-prefer-server-ciphers yes

    Generate the DH params (slow):

    openssl dhparam -out /etc/ssl/redis/dhparam.pem 2048
  4. Restart and connect over TLS:

    sudo systemctl restart redis-server
    redis-cli --tls --cacert /etc/ssl/redis/ca.crt -h redis-01.internal -p 6380 ping
  5. Enable TLS for replication and cluster when the topology has converged on TLS:

    tls-replication yes
    tls-cluster yes
  6. Switch off plaintext once every client has been migrated:

    port 0

    Restart, verify with ss -tlnp | grep redis that only 6380 is listening.

  7. Add mutual TLS for clients in zero-trust environments. Issue client certificates from the same CA and:

    tls-auth-clients yes

    Clients then need --cert client.crt --key client.key.

Common pitfalls

  • A certificate whose CN/SAN does not match the connection hostname fails TLS verification at the client. redis-cli reports it clearly; library errors can be cryptic.
  • Forgetting tls-replication yes means the application traffic is encrypted but replication is still in plaintext — same secrets, leaking on the wire.
  • Self-signed CAs require --cacert on every client. A client that does not provide one falls back to system CAs and rejects the connection. Distribute the CA bundle alongside the credentials.
  • Certificate expiry takes the daemon down at the next restart and fails new TLS handshakes immediately on the running daemon. Rotate at 30 days before expiry and reload (Redis supports CONFIG SET tls-cert-file and CONFIG SET tls-key-file at runtime, but a DEBUG TLS reload is the documented path on newer versions).
  • TLS handshake CPU cost is non-trivial — short-lived connections that handshake repeatedly burn CPU. Use connection pooling on the client.

In the engagements we run, every Redis-with-TLS comes with the CA bundle in a config-management repo, certificate rotation on a 60-day cycle from an internal CA, and a Prometheus alert when any certificate is within 14 days of expiry. We operate that under Managed Operations — and for client-side patterns see Redis ACLs.