Skip to content

feat: add TLS support for Redis templates#260

Merged
joshrotenberg merged 1 commit into
mainfrom
feat/issue-244-redis-tls
Jun 11, 2026
Merged

feat: add TLS support for Redis templates#260
joshrotenberg merged 1 commit into
mainfrom
feat/issue-244-redis-tls

Conversation

@joshrotenberg

Copy link
Copy Markdown
Owner

What

Adds TLS support to the Redis templates, so a TLS Redis no longer needs hand-rolled RunCommand plumbing with cert volume mounts and --tls-* args.

Single-node RedisTemplate

  • .tls(certs_dir) -- bind-mounts the host cert directory read-only at /tls and starts redis-server with --tls-port, --tls-cert-file, --tls-key-file, --tls-ca-cert-file. Expects the conventional redis.crt / redis.key / ca.crt file names (documented).
  • Plaintext stays open alongside TLS by default. TLS listens on container port 6380, published on a configurable host port (.tls_port(port), default 6380).
  • .tls_only() -- disables the plaintext port via --port 0 and stops publishing it.
  • Connection helpers account for TLS: tls_connection_string() returns the rediss:// URL; connection_string() falls back to the rediss:// endpoint in TLS-only mode (since plaintext is closed). TLS composes with password auth.

RedisClusterTemplate

  • .tls(certs_dir) -- every node runs TLS-only on its data port with --tls-cluster yes / --tls-replication yes, mirroring Redis's documented cluster-over-TLS layout (the gossip protocol cannot mix plaintext and TLS nodes). Readiness polling, redis-cli --cluster create, cluster info, and node_role all connect with redis-cli --tls and the mounted certificates.

No new default dependencies

Self-signed cert generation is not pulled in as a heavyweight default. Instead the tls() rustdoc documents an openssl one-liner recipe, and the integration test generates throwaway certs with openssl in a temp dir.

Why

Closes the gap noted in the issue: redis-tower keeps TLS coverage on its process-based harness because the containerized templates could not exercise TLS. Template TLS lets the containerized version-matrix tier cover TLS paths too.

Evidence / test plan

  • Unit tests for arg construction on both templates (TLS flags, cert mount, --port 0 in TLS-only, custom TLS port, password coexistence, rediss:// connection strings, cluster redis-cli --tls flag assembly). cargo test --lib --all-features: 841 passed.
  • New tests/redis_tls_integration.rs: generates a self-signed CA + server cert with openssl, starts a TLS Redis, and asserts a redis-cli --tls ping returns PONG; a second test asserts plaintext is refused in TLS-only mode. Skipped automatically when Docker or openssl is unavailable. Both pass against a live Docker daemon (29.4.3).
  • Existing tests/redis_template_integration.rs (7 tests incl. password and Redis Stack, which share the refactored build_command path) pass against live Docker -- no regression.
  • Full gate green: cargo fmt --all, cargo clippy --all-targets --all-features -- -D warnings, cargo clippy --all-targets --no-default-features -- -D warnings, cargo doc --no-deps --all-features, cargo test --doc --all-features (422 passed).

Closes #244.

Add a `.tls(certs_dir)` builder to RedisTemplate and RedisClusterTemplate
that bind-mounts a host certificate directory read-only into the
container and starts redis-server with `--tls-port`, `--tls-cert-file`,
`--tls-key-file` and `--tls-ca-cert-file`. Certs are read from a fixed
`/tls` mount using the conventional `redis.crt`/`redis.key`/`ca.crt`
file names.

Single-node RedisTemplate keeps both plaintext and TLS open by default
(TLS on container port 6380, published on a configurable host `tls_port`,
default 6380). A `.tls_only()` toggle disables plaintext via `--port 0`
and stops publishing it. `connection_string()` returns the `rediss://`
endpoint in TLS-only mode; `tls_connection_string()` exposes the TLS URL
otherwise. TLS composes with password auth.

RedisClusterTemplate runs nodes TLS-only on the data port with
`--tls-cluster yes`/`--tls-replication yes`, mirroring Redis's documented
cluster-over-TLS layout (the gossip protocol cannot mix plaintext and
TLS). Readiness, `--cluster create`, info and role checks connect with
`redis-cli --tls` and the mounted certificates.

No new default dependencies: throwaway certs are generated with a
documented `openssl` recipe in the rustdoc and in the integration test.
The test starts a TLS Redis, connects with `redis-cli --tls`, and
verifies plaintext is refused in TLS-only mode; it is skipped when Docker
or openssl is unavailable.

Closes #244.
@joshrotenberg joshrotenberg merged commit d4b0a6e into main Jun 11, 2026
11 checks passed
@joshrotenberg joshrotenberg deleted the feat/issue-244-redis-tls branch June 11, 2026 20:54
@github-actions github-actions Bot mentioned this pull request Jun 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: TLS support for Redis templates

1 participant