Security

TLS and encryption

Where Raft DB has TLS (the MySQL, MariaDB, SQL Server and PostgreSQL front-ends) and how to turn it on, which links are still in clear text, and what to do about them.

The statement#

The client connections of the MySQL, MariaDB, SQL Server and PostgreSQL front-ends, and the HTTP API (on its own HTTPS port), can be encrypted. The binary protocol and the other links cannot. The front-ends use rustls (pure Rust TLS, the ring crypto provider; TLS 1.2 and 1.3) through the small crate raftdb-tls, behind a build feature of the release. It is the one place where the project takes third-party code; the engine crates still have none (decision D96). TLS is off until you configure a certificate (or ssl = auto).

LinkProtection
MySQL and MariaDB clients to raftdb-mysqlWith ssl_cert and ssl_key set (or ssl = auto) the handshake offers TLS and the connection can be encrypted (ssl_mode = required refuses clients that do not). Without them the SSL capability is not offered: the login proves the password without sending it, but statements and results are in clear text.
SQL Server clients to the TDS front-end (raftdb-tds)The same settings; the library offers TLS 1.2 when built with the tls feature, negotiated in PRELOGIN as SQL Server does. The SQL Server engine front-end (raftdb-mssql, written against the library) has to pass its settings through TlsServer::from_settings. Without TLS the server answers "encryption not supported" and the password of LOGIN7 is only obfuscated.
HTTP API and Studio of raftdb-serverHTTPS on a second port when you set https-addr (see below). The main port (7480) stays plain HTTP, so anything that reaches it sends passwords and tokens in clear text.
Native clients to raftdb-server (binary protocol)Passwords and tokens are sent in clear text (Hello carries user NUL password).
UDP datagramsEach is authenticated with an HMAC-SHA-256 tag (keyed with a session secret, covering direction, header and body; replays and forgeries get no reply). The payload is not encrypted.
Replication (a follower reading the primary's log)A normal login, then the log in clear text.
Watcher to watcherAuthenticated with cluster_secret (HMAC); not encrypted.
Watcher webhooks and error reportsPlain http://. For HTTPS use notify_command or RAFTDB_ERROR_REPORT_COMMAND with curl.
Data at restNot encrypted by Raft DB.

Turning TLS on in raftdb-mysql#

# mysql.conf
ssl_cert = /etc/raftdb/server.pem     # PEM certificate chain (the server certificate first)
ssl_key  = /etc/raftdb/server.key     # PEM private key
ssl_mode = required                # off | preferred | required
  • ssl_mode: off (the default when there is no certificate), preferred (the default when there is one: TLS is offered, a client may stay in clear), required (a client that does not use TLS is refused with error 3159, Insecure transport is refused when --require_secure_transport=ON is in effect.).
  • ssl = auto with no certificate makes a self-signed certificate in memory at start (subject raftdb-mysql auto-generated, ten years, names localhost, 127.0.0.1, ::1). It is new at every start, so clients can encrypt with it but cannot verify it (--ssl-mode=REQUIRED, sslMode=REQUIRED).
  • To let clients verify the server, make a certificate with openssl (openssl req -x509 -newkey ec -pkeyopt ec_paramgen_curve:prime256v1 -nodes -days 3650 -keyout key.pem -out cert.pem -subj "/CN=db.example.com" -addext "subjectAltName=DNS:db.example.com,IP:10.0.0.5"), give cert.pem and key.pem to the server and cert.pem to the client as its CA file. A certificate from a CA works the same way (put the intermediates after the server certificate).
  • SELECT @@have_ssl is YES when TLS is offered; @@require_secure_transport is 1 with ssl_mode = required; SHOW STATUS LIKE 'Ssl_cipher' and 'Ssl_version' show the cipher suite and protocol of your own connection (empty in clear).
  • A build without the tls feature refuses these settings at start.

Turning HTTPS on for the HTTP API#

# raftdb-server.conf
https-addr = 0.0.0.0:7443
https-cert = /etc/raftdb/server.pem     # PEM certificate chain (the server certificate first)
https-key  = /etc/raftdb/server.key     # PEM private key
  • https-addr opens a second listener. It speaks TLS (1.2 and 1.3) and then exactly the same HTTP as the main port: the same routes, the same login, the same Studio, the same limits. The main port keeps serving plain HTTP and the binary protocol; HTTPS is added, nothing is switched off.
  • With https-addr and no certificate, a self-signed certificate is made in memory at every start. Clients can encrypt with it but cannot verify it; use a real certificate (or one you made with openssl, as above) for anything but a trial.
  • https-cert and https-key go together and need https-addr; the server refuses to start otherwise, or if the files cannot be read.
  • To make the traffic safe, bind the main port to 127.0.0.1 (the single profile does) and let only the HTTPS port listen on the network. A server whose main port listens on the network is still reachable in clear text there.
  • The connection's address is the real peer's. HTTP/2, client certificates and certificate reloading without a restart are not there.

Client programs#

Tested against raftdb-mysql with TLS (see D96): mysql 9.7 (--ssl-mode=REQUIRED, VERIFY_CA and VERIFY_IDENTITY with the server certificate as --ssl-ca), the mariadb 11.4 client (connects with no TLS option at all; --ssl-verify-server-cert --ssl-ca=cert.pem verifies), MySQL Connector/J 26 (sslMode=REQUIRED, and VERIFY_CA with a trust store holding the certificate).

  • Without a certificate on the server, the MySQL command-line client connects in clear in its default mode and --ssl-mode=REQUIRED fails; the MariaDB 11.4 client wants --skip-ssl; drivers need the equivalent (useSSL=false in MySQL Connector/J).
  • With TLS configured none of that is needed. A client that verifies the certificate needs the certificate (as CA) and a host name or address the certificate names.

SQL Server clients#

The TDS server follows [MS-TDS] 3.2.5.1: the PRELOGIN encryption option is answered according to ssl_mode (login: only the login is encrypted unless the client asks for more; preferred: everything for clients that can; required: everything, a client that cannot is disconnected), the TLS handshake runs inside TDS packets, and then TLS records carry the TDS packets. Tested: sqlcmd with ODBC Driver 17 (-N -C), mssql-jdbc 13.6.2 (encrypt=true;trustServerCertificate=true, and encrypt=true with a trust store holding the certificate). The server offers TLS 1.2 only: mssql-jdbc on TLS 1.3 cannot finish the handshake inside TDS packets. ODBC Driver 18 and .NET SqlClient were not tried.

  1. Keep every port on loopback or a private network (see Network exposure).
  2. For any path you do not fully control, use TLS on the front-ends where it exists, and a tunnel for the rest: an SSH port forward (ssh -N -L ...) for a client, WireGuard or a VPN for node-to-node traffic (replication and watcher peers).
  3. For data at rest use full-disk or file-system encryption.
  4. Use a different password for every account and never reuse one across links that are in clear text.

Not built#

  • TLS on the binary protocol, HTTP and the Studio, UDP, replication between nodes, the watcher's messages and webhooks (the plan documents say rustls as an optional build feature for the watcher's HTTPS webhooks, and QUIC from a vetted library for an encrypted UDP mode, decision D40; none of it is scheduled).
  • Client certificates (mutual TLS) and REQUIRE SSL / X509 on accounts; reloading a certificate without a restart; a configurable cipher list; TLS 1.3 for the SQL Server protocol.
  • Encryption of data at rest.

Do not plan around what is not built.

See also#