fix(postgres): support client certificate authentication (mTLS) - #666
Conversation
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (35 files)Rust (backend)
TypeScript / React (frontend)
i18n locales (12)
Tests
Previous Review Summary (commit 6bb4e9b)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 6bb4e9b)Status: No Issues Found | Recommendation: Merge Files Reviewed (3 files)
Reviewed by glm-5.2 · Input: 96.9K · Output: 19.3K · Cached: 918.1K |
|
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.
|
Thanks @debba! Updated:
|
|
@adisusilayasa Thank you for addressing the requested changes! Everything looks good now, so I’ll proceed with the merge. You’re more than welcome to keep contributing to Tabularis. If you’d like, you can also join us on Discord — we’d be happy to have you there! |
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.