Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Sovereign, high-performance data protection

Securing database connections with TLS / mTLS

The KMS supports TLS-encrypted connections and mutual TLS (mTLS) client-certificate authentication for PostgreSQL and MySQL-compatible databases. All TLS parameters are configured directly in the database-url as query parameters — no extra CLI flags or TOML keys are needed.

KMS connecting to PostgreSQL and MySQL over TLS or mTLS

Production certificates must be issued by a trusted Certificate Authority

For production deployments, all TLS certificates (CA, server, and client certificates) must be issued by a trusted Certificate Authority (CA). Self-signed certificates should only be used for testing and development environments.

Using certificates from an untrusted or self-signed CA may expose your KMS deployment to man-in-the-middle (MITM) attacks and should never be done in production.

PostgreSQL TLS / mTLS

PostgreSQL TLS is configured using the standard libpq-style query parameters in the connection URL.

ParameterDescription
sslmodeTLS mode: disable, allow, prefer (default), require, verify-ca, verify-full
sslrootcertPath to the CA certificate (PEM) used to verify the server
sslcertPath to the client certificate (PEM) for mTLS
sslkeyPath to the client private key (PEM) for mTLS

Server-authenticated TLS only (encrypt the connection and verify the server certificate):

[db]
database_type = "postgresql"
database_url = "postgres://kms:kms@pgsql-server:5432/kms?sslmode=verify-ca&sslrootcert=/path/to/ca.crt"

Mutual TLS (mTLS) (encrypt + verify server certificate + present a client certificate):

[db]
database_type = "postgresql"
database_url = "postgres://kms:kms@pgsql-server:5432/kms?sslmode=verify-full&sslrootcert=/path/to/ca.crt&sslcert=/path/to/client.crt&sslkey=/path/to/client.key"

sslmode behaviour

  • disable – no TLS at all.
  • allow / prefer (default) – TLS is used if the server offers it, otherwise the connection silently falls back to plaintext. The server certificate is not verified.
  • require – the connection fails if the server does not support TLS. The server certificate is not verified, unless sslrootcert is also set, in which case it is verified against that CA (the hostname is still not checked).
  • verify-ca – the server certificate is verified against the sslrootcert CA but the hostname is not checked. sslrootcert is mandatory: as with libpq, the KMS refuses to start with verify-ca and no sslrootcert.
  • verify-full – the server certificate is verified against the CA and the hostname must match. This is the recommended mode for production.

Any other sslmode value is rejected at startup. When sslrootcert is set, only that CA is trusted (the system CA store is not consulted); verify-full without sslrootcert verifies against the system CA store. All certificates must be in PEM format.

MySQL / MariaDB TLS / mTLS

MySQL TLS is configured using query parameters in the connection URL. Both dash (ssl-mode) and underscore (ssl_mode) variants are accepted.

ParameterDescription
ssl-modeTLS mode: DISABLED, PREFERRED, REQUIRED, VERIFY_CA, VERIFY_IDENTITY
ssl-caPath to the CA certificate (PEM) for server verification
ssl-client-identityPath to the client PKCS#12 (.p12) bundle for mTLS
ssl-client-identity-passwordPassword protecting the PKCS#12 bundle

Server-authenticated TLS only (encrypt the connection and verify the server certificate):

[db]
database_type = "mysql"
database_url = "mysql://kms:kms@mysql-server:3306/kms?ssl-mode=VERIFY_CA&ssl-ca=/path/to/ca.crt"

Mutual TLS (mTLS) (encrypt + verify server certificate + present a client certificate):

[db]
database_type = "mysql"
database_url = "mysql://kms:kms@mysql-server:3306/kms?ssl-mode=VERIFY_CA&ssl-ca=/path/to/ca.crt&ssl-client-identity=/path/to/client.p12&ssl-client-identity-password=secret"

ssl-mode behaviour

  • DISABLED – no TLS at all.
  • PREFERRED / REQUIRED – TLS is used but the server certificate is not verified.
  • VERIFY_CA – the server certificate is verified against the CA. When ssl-ca is set, only that CA is trusted (the system CA store is not consulted); the file must contain the root CA of the server chain. Without ssl-ca, the system CA store is used.
  • VERIFY_IDENTITY – the server certificate is verified against the CA and the hostname must match.

PKCS#12 client identity

MySQL client-certificate authentication requires the certificate and private key bundled as a PKCS#12 (.p12) file — PEM files are not supported.

You can create the bundle using OpenSSL:

openssl pkcs12 -export \
    -in client.crt -inkey client.key \
    -out client.p12 -passout pass:secret

FIPS mode restriction

PKCS#12 client identity (ssl-client-identity) is not available in FIPS mode. MySQL mTLS with client certificates requires the non-fips feature.

See also