Skip to content

Configure TLS

Valkey GLIDE supports secure TLS connections to a data store.

It’s important to note that TLS support in Valkey GLIDE relies on rustls. Currently, Valkey GLIDE employs the default rustls settings with no option for customization.

Enabling TLS is as simple as setting use_tls=True in your configuration. The client will use your system’s default certificate trust store to verify the server.

from glide import (
GlideClusterClient,
GlideClusterClientConfiguration,
NodeAddress
)
addresses = [NodeAddress(host="address.example.com", port=6379)]
client_config = GlideClusterClientConfiguration(addresses, use_tls=True)
client = await GlideClusterClient.create(client_config)
from glide import (
GlideClient,
GlideClientConfiguration,
NodeAddress
)
addresses = [
NodeAddress(host="primary.example.com", port=6379),
NodeAddress(host="replica1.example.com", port=6379),
NodeAddress(host="replica2.example.com", port=6379)
]
client_config = GlideClientConfiguration(addresses, use_tls=True)
client = await GlideClient.create(client_config)

Insecure TLS mode bypasses certificate verification. This is useful when connecting to servers using self-signed certificates or when DNS entries don’t match certificate hostnames.

from glide import (
AdvancedGlideClusterClientConfiguration,
GlideClusterClient,
GlideClusterClientConfiguration,
NodeAddress,
TlsAdvancedConfiguration,
)
tls_config = TlsAdvancedConfiguration(use_insecure_tls=True)
advanced_config = AdvancedGlideClusterClientConfiguration(tls_config=tls_config)
client_config = GlideClusterClientConfiguration(
addresses=[NodeAddress(host="address.example.com", port=6379)],
use_tls=True,
advanced_config=advanced_config,
)
client = await GlideClusterClient.create(client_config)
from glide import (
AdvancedGlideClientConfiguration,
GlideClient,
GlideClientConfiguration,
NodeAddress,
TlsAdvancedConfiguration,
)
tls_config = TlsAdvancedConfiguration(use_insecure_tls=True)
advanced_config = AdvancedGlideClientConfiguration(tls_config=tls_config)
client_config = GlideClientConfiguration(
addresses=[NodeAddress(host="primary.example.com", port=6379)],
use_tls=True,
advanced_config=advanced_config,
)
client = await GlideClient.create(client_config)

You can provide custom root certificates for TLS connections. This is useful when connecting to servers with self-signed certificates or corporate certificate authorities.

Certificate Behavior:

  • If root_pem_cacerts is None (default), the system’s default certificate trust store is used
  • If root_pem_cacerts is an empty bytes object, an error will be returned
  • Certificates must be in PEM format as a bytes object
  • Multiple certificates can be provided by concatenating them in PEM format

Example - Connecting with Custom Root Certificate from File

Section titled “Example - Connecting with Custom Root Certificate from File”
from glide import (
GlideClusterClient,
GlideClusterClientConfiguration,
NodeAddress,
TlsAdvancedConfiguration,
AdvancedGlideClusterClientConfiguration
)
# Read certificate file
with open("/path/to/ca-cert.pem", "rb") as f:
root_cert = f.read()
tls_config = TlsAdvancedConfiguration(root_pem_cacerts=root_cert)
advanced_config = AdvancedGlideClusterClientConfiguration(
tls_config=tls_config
)
addresses = [NodeAddress(host="address.example.com", port=6379)]
client_config = GlideClusterClientConfiguration(
addresses,
use_tls=True,
advanced_config=advanced_config
)
client = await GlideClusterClient.create(client_config)
from glide import (
GlideClient,
GlideClientConfiguration,
NodeAddress,
TlsAdvancedConfiguration,
AdvancedGlideClientConfiguration
)
cert_data = b"""-----BEGIN CERTIFICATE-----
MIIDXTCCAkWgAwIBAgIJAKL0UG+mRKmzMA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNV
...
-----END CERTIFICATE-----"""
tls_config = TlsAdvancedConfiguration(root_pem_cacerts=cert_data)
advanced_config = AdvancedGlideClientConfiguration(
tls_config=tls_config
)
addresses = [NodeAddress(host="primary.example.com", port=6379)]
client_config = GlideClientConfiguration(
addresses,
use_tls=True,
advanced_config=advanced_config
)
client = await GlideClient.create(client_config)

Example - Multiple Certificates (Certificate Chain)

Section titled “Example - Multiple Certificates (Certificate Chain)”
from glide import (
GlideClusterClient,
GlideClusterClientConfiguration,
NodeAddress,
TlsAdvancedConfiguration,
AdvancedGlideClusterClientConfiguration
)
# Read multiple certificate files
with open("/path/to/cert1.pem", "rb") as f:
cert1 = f.read()
with open("/path/to/cert2.pem", "rb") as f:
cert2 = f.read()
with open("/path/to/cert3.pem", "rb") as f:
cert3 = f.read()
# Concatenate certificates
combined_certs = cert1 + cert2 + cert3
tls_config = TlsAdvancedConfiguration(root_pem_cacerts=combined_certs)
advanced_config = AdvancedGlideClusterClientConfiguration(
tls_config=tls_config
)
addresses = [NodeAddress(host="address.example.com", port=6379)]
client_config = GlideClusterClientConfiguration(
addresses,
use_tls=True,
advanced_config=advanced_config
)
client = await GlideClusterClient.create(client_config)

Mutual TLS has the client present its own certificate and private key to the server, so the server can authenticate the client in addition to the client authenticating the server. GLIDE supports three mTLS modes: in-memory PEM bytes (loaded once), path-based with automatic reload at the core’s default cadence, and path-based with a custom reload interval.

mTLS still requires TLS to be enabled on the top-level client configuration (use_tls=True in Python, .useTLS(true) in Java, useTLS: true in Node.js, .WithUseTLS(true) in Go). The advanced TLS configuration only supplies the client-side material; it does not enable TLS on its own.

Reload behavior applies to path-based modes only. The GLIDE core reads the certificate and key from disk at connect time and re-reads them on a schedule so a rotated certificate is picked up on the next reconnect. Open connections keep their current material. If a reload fails (missing file, mismatched key, unreadable), the last known-good material is kept until a subsequent read succeeds. Byte-based mTLS is inherently static: the material is read once at connect time and does not reload.

Path-based and byte-based mTLS are mutually exclusive within a single configuration. Supplying both is rejected at configuration time in every SDK.

A custom reload interval must be a positive whole number of seconds no greater than 4,294,967,295 (the maximum value of an unsigned 32-bit integer, roughly 136 years). Sub-second, zero, negative, and oversized values are rejected at configuration time.

Use the byte-based entry point when the client certificate and key are already loaded as PEM bytes (for example, fetched from a secret store). The material is read once at connect time and does not reload.

from glide import (
AdvancedGlideClusterClientConfiguration,
GlideClusterClient,
GlideClusterClientConfiguration,
NodeAddress,
TlsAdvancedConfiguration,
)
# Load PEM bytes from a secret store, not from source.
client_cert: bytes = ...
client_key: bytes = ...
tls_config = TlsAdvancedConfiguration(
client_cert_pem=client_cert,
client_key_pem=client_key,
)
advanced_config = AdvancedGlideClusterClientConfiguration(tls_config=tls_config)
client_config = GlideClusterClientConfiguration(
addresses=[NodeAddress(host="address.example.com", port=6379)],
use_tls=True,
advanced_config=advanced_config,
)
client = await GlideClusterClient.create(client_config)

Point at PEM files on disk and let the core reload them at its default cadence. Rotated material is picked up on the next reconnect after a successful reload.

from glide import (
AdvancedGlideClusterClientConfiguration,
GlideClusterClient,
GlideClusterClientConfiguration,
NodeAddress,
TlsAdvancedConfiguration,
)
tls_config = TlsAdvancedConfiguration(
client_cert_path="/etc/glide/client.pem",
client_key_path="/etc/glide/client.key",
)
advanced_config = AdvancedGlideClusterClientConfiguration(tls_config=tls_config)
client_config = GlideClusterClientConfiguration(
addresses=[NodeAddress(host="address.example.com", port=6379)],
use_tls=True,
advanced_config=advanced_config,
)
client = await GlideClusterClient.create(client_config)

Pass a positive whole number of seconds to override the core default cadence.

from glide import (
AdvancedGlideClusterClientConfiguration,
GlideClusterClient,
GlideClusterClientConfiguration,
NodeAddress,
TlsAdvancedConfiguration,
)
tls_config = TlsAdvancedConfiguration(
client_cert_path="/etc/glide/client.pem",
client_key_path="/etc/glide/client.key",
cert_reload_interval_seconds=60,
)
advanced_config = AdvancedGlideClusterClientConfiguration(tls_config=tls_config)
client_config = GlideClusterClientConfiguration(
addresses=[NodeAddress(host="address.example.com", port=6379)],
use_tls=True,
advanced_config=advanced_config,
)
client = await GlideClusterClient.create(client_config)

When static, byte-based mTLS is desired but the material lives on disk, each SDK offers a helper that reads the PEM files and returns the bytes. Feed those bytes into the byte-based entry point shown above.

The same file-loading helpers work for both GlideClient (standalone) and GlideClusterClient (cluster-mode). The examples below show the standalone client; substitute the cluster variant if you are connecting to a cluster.

from glide import (
AdvancedGlideClientConfiguration,
GlideClient,
GlideClientConfiguration,
NodeAddress,
TlsAdvancedConfiguration,
)
from glide import load_client_certificate_and_key_from_file
cert, key = load_client_certificate_and_key_from_file(
"/etc/glide/client.pem",
"/etc/glide/client.key",
)
tls_config = TlsAdvancedConfiguration(client_cert_pem=cert, client_key_pem=key)
advanced_config = AdvancedGlideClientConfiguration(tls_config=tls_config)
client_config = GlideClientConfiguration(
addresses=[NodeAddress(host="primary.example.com", port=6379)],
use_tls=True,
advanced_config=advanced_config,
)
client = await GlideClient.create(client_config)
  • mTLS still needs TLS enabled at the top level. The advanced TLS configuration only supplies the client-side material; without TLS on the base client configuration (use_tls=True, .useTLS(true), useTLS: true, or .WithUseTLS(true)), the client connects in plaintext and the mTLS material is not used.
  • Path-based and byte-based mTLS are mutually exclusive. Supplying both a certificate/key path and inline PEM bytes on the same configuration is a configuration error in every SDK.
  • Sub-second, zero, negative, and oversized reload intervals are rejected. The custom interval is validated at configuration time: it must be a positive whole number of seconds no greater than 4,294,967,295 (the maximum value of an unsigned 32-bit integer, roughly 136 years). If you want static mTLS from files, load the bytes yourself with the file-loading helper and use the byte-based mode.
  • Byte-based mTLS is static. The material is read once at connect time and never reloads. Use a path-based mode when the certificate rotates.
  • Reload cadence is a lower bound. The interval bounds how stale the on-disk material can be before the next reload attempt; the next successful reload takes effect on the next reconnect, not on open connections.
  • Reload failures keep the last known-good material. A path that becomes unreadable, a mismatched key, or a corrupt certificate causes the reload to fail. The core keeps the last successfully loaded material and retries at the next tick.
  • File permissions matter. The process user must have read access to the certificate and key files. Restrict the key file to that user; do not commit it or log it.

All certificates must be in PEM format. A PEM certificate looks like this:

-----BEGIN CERTIFICATE-----
MIIDXTCCAkWgAwIBAgIJAKL0UG+mRKmzMA0GCSqGSIb3DQEBCwUAMEUxCzAJBgNV
...
-----END CERTIFICATE-----

Common Issues:

  1. Certificate Verification Failed

    • Ensure the certificate is valid and not expired
    • Verify the hostname matches the certificate’s Common Name (CN) or Subject Alternative Name (SAN)
    • Check that the certificate chain is complete
  2. Connection Refused

    • Verify the server is configured to accept TLS connections
    • Ensure the port number is correct (typically 6379 for TLS)
  3. Empty Certificate Error

    • Do not provide empty certificate data
    • Either provide valid certificates or use the default system certificates
  4. File Not Found

    • Verify the certificate file path is correct
    • Ensure the file is accessible with proper read permissions