Skip to content

feat: add redis-compatible tls support - #58

Merged
kacy merged 8 commits into
mainfrom
feat/tls-support
Feb 8, 2026
Merged

feat: add redis-compatible tls support#58
kacy merged 8 commits into
mainfrom
feat/tls-support

Conversation

@kacy

@kacy kacy commented Feb 8, 2026

Copy link
Copy Markdown
Owner

summary

  • adds redis-compatible TLS support using tokio-rustls
  • TLS runs on a separate port (--tls-port) alongside plain TCP
  • supports optional client certificate verification (mTLS) via --tls-ca-cert-file and --tls-auth-clients
  • both TCP and TLS connections share the same engine, connection limits, and graceful shutdown

test plan

  • all existing tests pass (283 tests)
  • manual testing with self-signed certs:
    # generate certs
    openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodes -subj "/CN=localhost"
    
    # start server
    ./target/release/ember-server --tls-port 6380 --tls-cert-file cert.pem --tls-key-file key.pem
    
    # test plain TCP still works
    redis-cli -p 6379 PING
    
    # test TLS
    redis-cli -p 6380 --tls --insecure PING
    redis-cli -p 6380 --tls --insecure SET foo bar
    redis-cli -p 6380 --tls --insecure GET foo

design considerations

  • separate port model: matches redis behavior. simpler than protocol detection on a single port
  • generic handlers: handle() accepts any AsyncRead + AsyncWrite + Unpin, enabling code reuse between TCP and TLS
  • shared resources: both listeners use the same semaphore, ServerContext, pubsub manager, etc.
  • handshake in task: TLS handshake happens in the spawned task after TCP accept, avoiding blocking the accept loop
  • aws-lc-rs by default: rustls 0.23 uses aws-lc-rs crypto provider (requires C compiler)

kacy added 8 commits February 8, 2026 10:06
add tokio-rustls, rustls, and rustls-pemfile for upcoming tls support.
uses rustls 0.23 with aws-lc-rs crypto backend by default.
new tls.rs module provides:
- TlsConfig struct for cert/key paths and mTLS settings
- load_tls_acceptor() to build tokio-rustls TlsAcceptor
- clear error messages for common issues (file not found, invalid PEM)
- optional client certificate verification via ca_cert_file
add redis-compatible tls flags:
- --tls-port: port for tls connections
- --tls-cert-file: server certificate path
- --tls-key-file: server private key path
- --tls-ca-cert-file: ca cert for client verification
- --tls-auth-clients: require client certs (yes/no)

validates that cert and key are provided when tls-port is set.
update handle() in connection.rs and concurrent_handler.rs to accept
any type implementing AsyncRead + AsyncWrite + Unpin. this enables
the same handler code to work with both TcpStream and TlsStream.

moved set_nodelay() call to server.rs accept loop so it applies to
the underlying tcp socket before any tls handshake.
- run() and run_concurrent() now accept optional TLS config
- when TLS is configured:
  - loads certificate and key via load_tls_acceptor()
  - binds separate TLS listener on --tls-port
  - performs TLS handshake after TCP accept
  - passes TlsStream to generic connection handler
- both plain TCP and TLS share the same:
  - connection semaphore (combined limit)
  - ServerContext and metrics
  - graceful shutdown handling
- TLS handshake failures logged as warnings, connection dropped
- add tls to features list
- document all tls cli flags in configuration table
- add tls server startup example
- add redis-cli tls connection examples
the doc comment for glob_match was accidentally placed above format_float.
moved it to the correct location.
@kacy
kacy merged commit 967fc65 into main Feb 8, 2026
5 checks passed
@kacy
kacy deleted the feat/tls-support branch February 8, 2026 15:21
kacy added a commit that referenced this pull request Feb 11, 2026
* feat: add tls dependencies

add tokio-rustls, rustls, and rustls-pemfile for upcoming tls support.
uses rustls 0.23 with aws-lc-rs crypto backend by default.

* feat: add tls config module

new tls.rs module provides:
- TlsConfig struct for cert/key paths and mTLS settings
- load_tls_acceptor() to build tokio-rustls TlsAcceptor
- clear error messages for common issues (file not found, invalid PEM)
- optional client certificate verification via ca_cert_file

* feat: add tls cli arguments

add redis-compatible tls flags:
- --tls-port: port for tls connections
- --tls-cert-file: server certificate path
- --tls-key-file: server private key path
- --tls-ca-cert-file: ca cert for client verification
- --tls-auth-clients: require client certs (yes/no)

validates that cert and key are provided when tls-port is set.

* refactor: make connection handlers generic over stream type

update handle() in connection.rs and concurrent_handler.rs to accept
any type implementing AsyncRead + AsyncWrite + Unpin. this enables
the same handler code to work with both TcpStream and TlsStream.

moved set_nodelay() call to server.rs accept loop so it applies to
the underlying tcp socket before any tls handshake.

* feat: add tls listener to server

- run() and run_concurrent() now accept optional TLS config
- when TLS is configured:
  - loads certificate and key via load_tls_acceptor()
  - binds separate TLS listener on --tls-port
  - performs TLS handshake after TCP accept
  - passes TlsStream to generic connection handler
- both plain TCP and TLS share the same:
  - connection semaphore (combined limit)
  - ServerContext and metrics
  - graceful shutdown handling
- TLS handshake failures logged as warnings, connection dropped

* docs: add tls configuration to readme

- add tls to features list
- document all tls cli flags in configuration table
- add tls server startup example
- add redis-cli tls connection examples

* fix: correct misplaced doc comment for glob_match

the doc comment for glob_match was accidentally placed above format_float.
moved it to the correct location.

* style: apply cargo fmt to tls.rs
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.

1 participant