Skip to content

feat(bigquery-jdbc): respect standard JVM trustStore properties by default#13435

Open
keshavdandeva wants to merge 5 commits into
mainfrom
jdbc/add-jvm-trustStore-support
Open

feat(bigquery-jdbc): respect standard JVM trustStore properties by default#13435
keshavdandeva wants to merge 5 commits into
mainfrom
jdbc/add-jvm-trustStore-support

Conversation

@keshavdandeva

@keshavdandeva keshavdandeva commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

b/515129164

Problem

In enterprise corporate networks (e.g. Zscaler), outbound HTTPS traffic is intercepted by transparent proxies doing SSL MITM (man-in-the-middle) decryption. The proxy signs its re-encrypted connections with dynamically generated root CA certificates.

The BigQuery JDBC driver failed to establish TLS connections under these environments because the underlying client library ignored JVM trust stores (the standard Java cacerts file or custom system properties set via -Djavax.net.ssl.trustStore).
This happened because when direct connections had empty SSL/proxy settings, the driver returned null for HttpTransportOptions. This fallback triggered classpath SPI overrides or legacy defaults which invoked GoogleNetHttpTransport.newTrustedTransport(). That convenience constructor hardcodes trust exclusively to a bundled google.p12 keystore, completely overriding JVM system properties.

Solution

Simplified the driver's transport instantiation to align with the core Google Cloud Java SDK's network defaults:

  1. Direct Connections: Modified getHttpTransportOptions(...) to unconditionally return a transport factory configured with a single NetHttpTransport instance (new NetHttpTransport.Builder().build()). This allows JSSE to handle TLS certificate validation using standard JVM system properties and cacerts natively. Bypassing the SPI loader prevents classpath hijacking.
  2. Explicit Proxy Connections: Configured the Apache HTTP client builder inside getHttpTransportFactory(...) to unconditionally call httpClientBuilder.useSystemProperties(). This ensures that even when a proxy is set in the JDBC URL, Apache HttpClient still honors system-level properties like -Djavax.net.ssl.trustStore.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates BigQueryJdbcProxyUtility to configure a default NetHttpTransport with a MergedTrustManager (trusting both the JVM's default trust store and Google's bundled certificate store) when no proxy or custom SSL settings are provided. The review feedback focuses on critical performance and robustness improvements: caching the merged SSLContext using a thread-safe lazy initialization holder pattern to avoid high CPU and latency overhead from re-creating it, handling potential null returns from getAcceptedIssuers() to prevent NullPointerException, and preserving debugging context by suppressing the initial CertificateException when falling back to Google's trust manager.

@keshavdandeva

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates BigQueryJdbcProxyUtility to return default HttpTransportOptions with a default NetHttpTransport instead of null when no proxy or SSL settings are configured, and updates the corresponding tests. The reviewer pointed out that the default transport factory implementation recreates a new NetHttpTransport on every call, which can cause socket leaks and prevent connection reuse, and also lacks MergedTrustManager integration. It is recommended to instantiate the transport once and reuse it.

@keshavdandeva

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request modifies BigQueryJdbcProxyUtility to return default HttpTransportOptions configured with a NetHttpTransport when no proxy or SSL settings are specified, rather than returning null. Additionally, it ensures that httpClientBuilder.useSystemProperties() is always called in getHttpTransportFactory. Corresponding unit tests have been updated to reflect these changes. There are no review comments, and I have no additional feedback to provide.

@keshavdandeva keshavdandeva marked this pull request as ready for review June 11, 2026 18:28
@keshavdandeva keshavdandeva requested review from a team as code owners June 11, 2026 18:28
@keshavdandeva keshavdandeva changed the title feat(bigquery-jdbc): respect JVM trustStore properties and default to JVM cacerts with google.p12 fallback feat(bigquery-jdbc): respect standard JVM trustStore properties by default Jun 11, 2026

@logachev logachev left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, but before approving I'd want us to have an environment where we could validate it

getHttpTransportFactory(
proxyProperties, sslTrustStorePath, sslTrustStorePassword, callerClassName));
} else {
final HttpTransport defaultTransport = new NetHttpTransport.Builder().build();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why using final here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants