How do you configure a Redis server to accept only TLS clients, and what does tls-auth-clients decide about who may connect?
answer
- compile time before config time
- the TLS listener is added, not swapped
- default demands a client certificate
- certificate is not an ACL login
basics
~10 sBuild with BUILD_TLS=yes, set tls-port, tls-cert-file, tls-key-file and a CA, and set port 0 to close the plain listener. tls-auth-clients then decides whether clients must present a certificate: yes by default, optional, or no.
solid answer
~40 sTLS is a compile-time option, so the binary needs `make BUILD_TLS=yes`, or `BUILD_TLS=module` plus `--loadmodule`. At runtime `tls-port` adds a TLS listener beside the plain one, so TLS-only also takes `port 0`; leave `port` alone and plaintext stays open on its own port. The server needs `tls-cert-file` and `tls-key-file`, plus `tls-ca-cert-file` or `tls-ca-cert-dir` whenever it verifies peers, which is the default. `tls-auth-clients` defaults to `yes`, so every client on that port, replicas included, must present a certificate that verifies against that CA. `optional` validates a certificate only if one is offered, and `no` accepts none. That decides who may finish the handshake. What the connection may then do is still decided by `AUTH` and ACLs, unless `tls-auth-clients-user` maps the certificate to an ACL user.
code
conf · 7 linesport 0
tls-port 6379
tls-cert-file /etc/redis/tls/redis.crt
tls-key-file /etc/redis/tls/redis.key
tls-ca-cert-file /etc/redis/tls/ca.crt
# tls-auth-clients stays at its default, yes
requirepass change-this-long-random-secretgo deeper
Recall that TLS needs a build flag, a separate tls-port, and a certificate, key and CA, and that port 0 is what closes the plaintext listener.
Walk through the listener table, explain why a config with no CA fails to start under the default tls-auth-clients yes, and give the three values of that directive with their effects.
Separate the handshake from authorization: certificates decide who connects, ACLs decide what they do. Mention replicas needing certificates, the Unix socket staying plain, and reloading files with CONFIG SET instead of restarting.
Client certificates add an issuing and renewal burden to every application team. Decide whether that identity layer earns its keep compared with server-side TLS plus ACL users, and write the choice down.
## TLS is a build option first Redis's TLS support needs OpenSSL development libraries and has to be compiled in: - `make BUILD_TLS=yes` builds it into the server. - `make BUILD_TLS=module` builds it as a module, loaded with `--loadmodule src/redis-tls.so`. Sentinel mode does not support the module form. A binary built without it cannot be configured into TLS. Starting one with `tls-port` set logs `Failed finding TLS support.` and exits, and `CONFIG SET tls-port` replies that TLS support is not compiled in. ## Two listeners, not one `tls-port` defaults to `0`, meaning off. Setting it adds a listener; it does not convert the existing one. `port` keeps its own default of `6379` until you change it. | Settings | Plain TCP | TLS | |---|---|---| | Neither touched | 6379 | none | | `tls-port 6380` | 6379 | 6380 | | `port 0` and `tls-port 6379` | none | 6379 | The middle row is the common half-finished hardening: TLS works, the team believes traffic is encrypted, and any client can still use plaintext on the old port. `bind` and `protected-mode` are not replaced by any of this. Both listeners use the same `bind` addresses, and protected mode still applies to a TLS connection. ## Certificate settings - **`tls-cert-file`, `tls-key-file`:** the server's PEM certificate and key, both required. `tls-key-file-pass` holds a passphrase if the key is encrypted. - **`tls-ca-cert-file` or `tls-ca-cert-dir`:** the CA used to verify peers. Redis will not implicitly use the system-wide store. - **`tls-client-cert-file`, `tls-client-key-file`:** an optional separate certificate for outgoing connections, for certificates issued as server-only or client-only. Without them the server certificate plays both roles. - **`tls-dh-params-file`:** required only by OpenSSL older than 3.0, and recommended against on newer versions. - **`tls-protocols`:** by default only TLSv1.2 and TLSv1.3 are enabled. A CA is mandatory when `tls-auth-clients` is anything but `no`, or when `tls-replication` or `tls-cluster` is on. Because `tls-auth-clients` defaults to `yes`, a configuration with a certificate and key but no CA does not start. The log says `Either tls-ca-cert-file or tls-ca-cert-dir must be specified`. ## What tls-auth-clients decides | Value | Client without a certificate | Client with one | |---|---|---| | `yes` (default) | Handshake fails | Must verify against the CA | | `optional` | Accepted | Must verify against the CA | | `no` | Accepted | Not accepted as a credential; none is requested | Two scope points are worth saying aloud: 1. A primary treats a connecting replica as a client, so with the default a replica needs a certificate too. 2. The directive governs the client port only. It cannot relax the Redis Cluster bus, which always requires a verified peer certificate once `tls-cluster` is on. ## A certificate is not a Redis user Finishing the handshake proves the client holds a certificate from that CA. It says nothing about which keys or commands the connection may use. Afterwards the usual rules apply: - If `default` is enabled with `nopass`, an accepted connection runs as `default` with everything `default` is allowed. - If `default` has a password, the client must still `AUTH`. - Setting `tls-auth-clients-user CN` maps a validated certificate's Common Name to an ACL user of that exact name, so the client is authenticated without `AUTH`. If no such user exists, it is connected as the unauthenticated default user. TLS does repair one weakness: without it, the `AUTH` command and its password cross the network unencrypted. ## Connecting and rotating `redis-cli` needs `--tls` and `--cacert`, plus `--cert` and `--key` when client certificates are required. A client speaking plain RESP to the TLS port cannot complete a handshake. Certificate files can be replaced without a restart. These settings are marked volatile, so `CONFIG SET tls-cert-file` with the same path is applied even though the value did not change, and Redis rebuilds its TLS context from the files. That also discards the TLS session cache held on the old context. ## Half-finished setups to look for - `tls-port` set but `port` untouched, so plaintext is still served. Check with `CONFIG GET port`. - `tls-auth-clients no` set to get a client working, then forgotten, so anyone reaching the port can finish the handshake. - A TLS listener with no password on `default`, where remote clients with good certificates still receive `-DENIED` from protected mode. - A `unixsocket` listener left in place, which `port 0` does not close.
- When would you choose tls-auth-clients no over the default?When you want encryption and server identity but clients authenticate with Redis passwords or ACL users, and issuing a certificate to every client would be more work than it is worth. The cost is that anyone who can reach the port can complete the handshake, so `AUTH` carries the whole burden of proving identity. It also means a CA is no longer required, unless `tls-replication` or `tls-cluster` is on.
- After renewing certificate files on disk, do you need to restart Redis?No. `tls-cert-file`, `tls-key-file` and the CA settings are marked volatile, so `CONFIG SET` with the same path is applied even though the string is unchanged, and Redis rebuilds its TLS context from the files. Set the certificate and key in one command so they stay a matching pair. The rebuild discards the session cache held on the old context, so clients that reconnect soon afterwards lose that shortcut.
- Does port 0 stop a local process from connecting without TLS?`port 0` removes the TCP listener only. If `unixsocket` is configured, that listener is separate and stays open, and local clients on it do not use TLS. Check the configuration for `unixsocket` before you claim the server is TLS-only.
- Setting tls-port moves the existing plain listener over to TLS
- Redis falls back to the system CA store when none is configured
- A valid client certificate logs the client in as a named ACL user automatically
- tls-auth-clients no also relaxes certificate checks on the cluster bus
- TLS can be enabled by configuration alone on any Redis binary