TLS

This page describes how the server loads certificates, how each wire negotiates TLS, what require_tls does, and how far mutual TLS goes. For the operator summary see Security, section 3. Encryption of stored data is in Encryption at rest internals.

TLS is built on rustls with the ring crypto provider, through tokio-rustls. Certificates and keys are parsed with rustls-pemfile; development certificates are made with rcgen (source: src/protocol/tls.rs).

Configuration

[tls] in the config file maps to TlsConfigFile (source: src/config.rs, TlsConfigFile).

Key Default Meaning
enabled cfg!(debug_assertions): on in debug builds, off in release builds Serve TLS
auto_generate_dev_cert Same as enabled Generate a self-signed certificate when none is configured
cert_path, key_path none PEM certificate chain and private key
require_tls false Refuse plaintext from non-loopback peers on wires that support both
require_client_cert false Require a client certificate (mTLS)
ca_cert_path none CA bundle for client certificates

(source: src/config.rs, TlsConfigFile; src/protocol/tls.rs, TlsConfig)

Validation rejects enabled without certificates (unless generation is on) and require_client_cert without a CA (source: src/config.rs; test tls_enabled_without_certificates_is_rejected). Every key can also be set with SYNERGYDB_TLS_<KEY> (source: src/config.rs).

Loading and building

resolve_tls_config runs once at start and its result is passed to every wire handler with with_tls (source: src/protocol/tls.rs, resolve_tls_config; src/server/mod.rs).

Case Result
TLS disabled No TLS anywhere
cert_path and key_path set Those files are loaded
Neither set, generation on generate_self_signed_cert writes data_dir/certs/server.crt and server.key
Neither set, generation off Configuration error

(source: src/protocol/tls.rs, resolve_tls_config)

  • load_certs and load_private_key return an error for an empty or unreadable file (source: src/protocol/tls.rs, load_certs, load_private_key).
  • The generated certificate is ECDSA P-256, valid 365 days, with subject alternative names localhost, the configured common name, 127.0.0.1 and ::1 (source: src/protocol/tls.rs, generate_self_signed_cert).
  • Not verified: the generated key file is written without setting its permissions; no test checks its mode (source: src/protocol/tls.rs, generate_self_signed_cert).
  • install_default_crypto_provider installs ring as the process-wide rustls provider (source: src/protocol/tls.rs).
  • build_server_config uses ServerConfig::builder() defaults, so the protocol versions are those rustls enables by default (source: src/protocol/tls.rs, build_server_config).
  • build_acceptor_with(versions, tickets, alpn) lets a wire pick versions, session tickets and ALPN (source: src/protocol/tls.rs).

Unit tests: test_tls_config_default, test_tls_config_new, test_tls_config_with_client_auth (source: src/protocol/tls.rs). These cover the config struct, not a handshake.

Per-wire modes

Once TLS is configured, each wire uses one of three modes.

flowchart TD A["TCP accept"] --> B{"Wire mode"} B -- "implicit" --> C["TLS handshake on every connection"] B -- "accept_auto" --> D{"First byte is 0x16?"} D -- yes --> C D -- no --> E{"plaintext_allowed(peer)?"} E -- yes --> F["Plaintext"] E -- no --> G["Close"] B -- "in-protocol" --> H["Wire's own upgrade request"] H --> C

(source: src/protocol/tls.rs, TlsListener::accept, TlsListener::accept_auto, plaintext_allowed)

Mode Wires Plaintext once TLS is on require_tls
Implicit TLS Redis, MongoDB, Bolt, Cassandra, Elasticsearch, CouchDB, DynamoDB, ClickHouse native, ClickHouse HTTP, Snowflake, InfluxDB, Prometheus, Memcached Never, including from loopback Has no effect
First-byte detection (accept_auto) HTTP API, Kafka, S3, Schema Registry, SQLite Hrana, Oracle, Gremlin Allowed unless require_tls Plaintext only from loopback
gRPC (grpc_incoming) gRPC, Arrow Flight Same as accept_auto Plaintext only from loopback
In-protocol upgrade PostgreSQL, MySQL, SQL Server Allowed unless require_tls Plaintext only from loopback

(source: src/protocol/tls.rs; the with_tls handling in each src/protocol/<wire>/mod.rs)

accept_auto waits up to 30 s for the first byte; 0x16 (a TLS handshake record) starts TLS (source: src/protocol/tls.rs, accept_auto).

plaintext_allowed returns true when require_tls is off, or when the peer is loopback. A connection with an unknown peer address is refused (source: src/protocol/tls.rs, plaintext_allowed).

grpc_incoming offers TLS 1.3 and 1.2 with ALPN h2 (source: src/protocol/tls.rs, grpc_incoming).

PostgreSQL

An SSLRequest (code 80877103) gets S and a TLS handshake when TLS is configured, else N. With require_tls, a plaintext startup from a peer that is not allowed plaintext gets FATAL 28000; a cancel request (80877102) is still accepted (source: src/protocol/postgres/mod.rs). Not verified: no in-tree test drives a PostgreSQL TLS handshake.

MySQL

The server advertises CLIENT_SSL only when TLS is configured. With require_tls, a handshake response without CLIENT_SSL is refused (source: src/protocol/mysql/mod.rs). The login after the upgrade is covered by auth_reply_after_ssl_request_uses_sequence_three (source: src/protocol/mysql/mod.rs).

SQL Server

TDS negotiates encryption in PRELOGIN (source: src/protocol/mssql/tls.rs):

  • TDS 7: the TLS handshake is tunnelled inside PRELOGIN packets, capped at TLS 1.2 with no session tickets.
  • A client that asks for ENCRYPT_OFF gets login-only encryption: the LOGIN7 packet is encrypted and the rest is not.
  • TDS 8 strict: detected by a first byte of 0x16, with ALPN tds/8.0.
  • require_tls is honoured.

Tests: negotiation_table, reads_encryption_option (source: src/protocol/mssql/tls.rs).

Mutual TLS

With require_client_cert, build_server_config installs a WebPkiClientVerifier built from the roots in ca_cert_path, so a client must present a certificate that chains to that CA (source: src/protocol/tls.rs, build_server_config).

No wire reads peer_certificates. The certificate is checked for trust only and is never mapped to a user; the client must still log in with a password (source: grep of peer_certificates under src/protocol/). Not verified: no test performs an mTLS handshake.

Gaps

  • There is no minimum-version setting in [tls]. The internal TlsConfig has a min_version field, but nothing applies it: build_server_config uses the rustls defaults. The TlsVersion enum defaults to TLS 1.3 while TlsConfig defaults to TLS 1.2 (source: src/config.rs, TlsConfigFile; src/protocol/tls.rs, TlsConfig, TlsVersion, build_server_config).
  • On the thirteen implicit-TLS wires, turning TLS on removes plaintext entirely, including for loopback clients and tools that do not speak TLS (source: src/protocol/tls.rs; per-wire with_tls).
  • Debug builds turn TLS on with a generated certificate unless the config says otherwise (source: src/config.rs, TlsConfigFile).
  • The status entry docs/status/2026-11-30-tls-remaining-wires.md reports 17 of 17 official-client checks passing with test-scripts/tls/official_clients.py. Not verified: that script is not in the reviewed snapshot (source: docs/status/2026-11-30-tls-remaining-wires.md).