fix(postgres): support client certificate authentication (mTLS) - #666
fix(postgres): support client certificate authentication (mTLS)#666adisusilayasa wants to merge 2 commits into
Conversation
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (3 files)
Reviewed by glm-5.2 · Input: 53.9K · Output: 12.7K · Cached: 311.6K |
|
Tested this locally against a Postgres 16 container with One edge case worth addressing before merge: let client_auth = if ssl_mode == "disable" {
None
} else {
match (user_cert, user_key) {
// ...
}
};Small nit on Nothing else blocking from my side, the rest looks good. |
ConnectionParams already carried ssl_cert and ssl_key, but build_tls_connector never read them -- every TLS branch called .with_no_client_auth() unconditionally, so servers requiring client-certificate auth (e.g. Google Cloud SQL with mTLS enabled) rejected connections with "connection requires a valid client certificate," the same bug fixed upstream in the builtin driver (TabularisDB/tabularis#666). Added load_client_cert_from_pem, reusing the same rustls::pki_types::pem::PemObject machinery as the existing load_roots_from_pem rather than reintroducing rustls-pemfile (removed in #21 for being unmaintained, RUSTSEC-2025-0134) -- PrivateKeyDer supports PKCS1/SEC1/PKCS8 via the same trait, so no new dependency is needed. Both TLS branches now present the client cert via .with_client_auth_cert(...) when ssl_cert/ssl_key are set, and build_tls_connector errors clearly if only one of the pair is provided. Left connection_key unchanged -- it doesn't currently key on ssl_mode/ssl_ca either, so folding in just ssl_cert/ssl_key would be inconsistent scope creep beyond "client certs don't work at all." Fixes #34.
Description
Fixes PostgreSQL TLS connections when client certificates (
ssl_cert) and private keys (ssl_key) are provided.Previously,
build_postgres_tls_connectorinsrc-tauri/src/pool_manager.rshardcoded.with_no_client_auth()across all SSL modes, causing PostgreSQL servers requiring client-side certificate authentication (e.g. Google Cloud SQL with mTLS enabled) to reject connections withconnection requires a valid client certificate.Changes
load_client_auth_from_pemto parse client certificates and private keys from PEM files usingrustls_pemfile.build_postgres_tls_connectorto attach client credentials via.with_client_auth_cert(...)whenssl_certandssl_keyare supplied.ssl_certandssl_keyinbuild_connection_keyfor PostgreSQL connection pool keying.