Skip to content

Support client certificate authentication (mTLS) #34

Description

@aesslinger

Summary

The built-in driver's mTLS bug was fixed upstream in tabularis#666: build_postgres_tls_connector in src-tauri/src/pool_manager.rs hardcoded .with_no_client_auth() across all SSL modes, so PostgreSQL servers requiring client-side certificate authentication (e.g. Google Cloud SQL with mTLS enabled) rejected connections with connection requires a valid client certificate. That PR added load_client_auth_from_pem and wires ssl_cert/ssl_key into .with_client_auth_cert(...).

This plugin has the same gap. ConnectionParams already carries ssl_cert and ssl_key (src/models.rs:19-20, populated at src/models.rs:47-48), but build_tls_connector in src/client.rs:418-447 never reads them — every branch ends in .with_no_client_auth() regardless of ssl_mode. So client-cert/mTLS connections fail here the same way the built-in driver failed before #666.

Proposed fix

Port the approach from tabularis#666 into src/client.rs:

  • Add a load_client_auth_from_pem (or similar) helper that parses ssl_cert/ssl_key PEM files via rustls_pemfile/rustls::pki_types, mirroring the existing load_roots_from_pem helper (src/client.rs:451-469).
  • In build_tls_connector, when both ssl_cert and ssl_key are supplied, call .with_client_auth_cert(...) instead of .with_no_client_auth() on the relevant ClientConfig::builder() chains (there are two: the verify-ca/verify-full custom-verifier branch and the platform-verifier branch).
  • Add unit tests covering client cert loading and connector configuration, matching src-tauri/src/pool_manager_tests.rs from the upstream PR.
  • Confirm whether ssl_cert/ssl_key should also factor into connection pool cache keying (per src/client.rs's pool caching by host:port:database:user:startup_script, noted in this repo's CLAUDE.md) — the upstream PR included ssl_cert/ssl_key in build_connection_key.

Per this repo's parity mandate, behavior should match the built-in driver's fixed implementation exactly, not diverge from it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions