Skip to content

refactor(bigquery-jdbc): extract SSL TrustStore helpers and unify proxy checks - #15340

Closed
keshavdandeva wants to merge 1 commit into
mainfrom
fix/jdbc-telemetry-1-proxy-ssl-utils
Closed

keshavdandeva wants to merge 1 commit into
mainfrom
fix/jdbc-telemetry-1-proxy-ssl-utils

Conversation

@keshavdandeva

Copy link
Copy Markdown
Contributor

Summary

Extracts shared SSL TrustStore and proxy detection helpers in BigQueryJdbcProxyUtility so upcoming OpenTelemetry exporter changes can reuse the same TrustStore and proxy logic without duplication, and cleans up inconsistent proxy checks.

Key Decisions

  • Separate TLS provider selection in createSslConfig: The 4-arg package-private createSslConfig(...) uses the JDK default TLS provider (matching getTransportChannelProvider for gRPC), while getHttpTransportFactory passes CONSCRYPT_PROVIDER to keep post-quantum named groups on Apache HttpClient 5.
  • Deduplicated TrustStore loading: Extracted createTrustManagerFactory(...) shared by both HTTP (createSslConfig) and gRPC (getTransportChannelProvider).
  • Unified proxy predicates: Standardized hasProxy(...) (ProxyHost and ProxyPort present) and hasProxyAuth(...) (ProxyUid and ProxyPwd present) across all transport call sites, and removed a duplicate addAuthToProxyIfPresent(...) invocation.

Behavior Changes

  • Blank ProxyHost rejection: parseProxyProperties(...) now rejects whitespace-only ProxyHost values immediately with IllegalArgumentException instead of deferring failure to HTTP route construction.
  • Transport-neutral error message: createSslConfig(...) throws "Failed to configure SSL TrustStore" instead of "Failed to configure SSL TrustStore for HTTP transport".

@keshavdandeva
keshavdandeva requested review from a team as code owners December 1, 2026 18:02

@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 refactors SSL truststore configuration and proxy property parsing in BigQueryJdbcProxyUtility, introducing helper methods like hasProxy and hasProxyAuth and consolidating SSL context creation into a new SslConfig class. Feedback points out that hasProxy incorrectly requires ProxyPort to be present, which deviates from the original behavior where the port was optional. Additionally, it is recommended to store the truststore file content in memory rather than passing the file path to prevent redundant disk reads and race conditions.

Comment on lines +257 to +261
static boolean hasProxy(Map<String, String> proxyProperties) {
return proxyProperties != null
&& proxyProperties.containsKey(BigQueryJdbcUrlUtility.PROXY_HOST_PROPERTY_NAME)
&& proxyProperties.containsKey(BigQueryJdbcUrlUtility.PROXY_PORT_PROPERTY_NAME);
}

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.

high

The helper method hasProxy now requires both ProxyHost and ProxyPort to be present. However, in the original implementation (and as supported by HttpHost configuration in getHttpTransportFactory), the proxy port is optional and defaults to -1 if not specified. Requiring ProxyPort to be present will cause proxy configurations that omit the port to be silently ignored.

Please update hasProxy to only check for the presence of ProxyHost (matching the original behavior of explicitProxySet).

  static boolean hasProxy(Map<String, String> proxyProperties) {
    return proxyProperties != null
        && proxyProperties.containsKey(BigQueryJdbcUrlUtility.PROXY_HOST_PROPERTY_NAME);
  }

Comment on lines +171 to +173
Map<String, String> hostOnly = new HashMap<>();
hostOnly.put(BigQueryJdbcUrlUtility.PROXY_HOST_PROPERTY_NAME, "127.0.0.1");
assertFalse(BigQueryJdbcProxyUtility.hasProxy(hostOnly));

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.

medium

Since hasProxy should return true when only ProxyHost is specified (with the port defaulting to -1), this assertion should be updated to assertTrue.

Suggested change
Map<String, String> hostOnly = new HashMap<>();
hostOnly.put(BigQueryJdbcUrlUtility.PROXY_HOST_PROPERTY_NAME, "127.0.0.1");
assertFalse(BigQueryJdbcProxyUtility.hasProxy(hostOnly));
Map<String, String> hostOnly = new HashMap<>();
hostOnly.put(BigQueryJdbcUrlUtility.PROXY_HOST_PROPERTY_NAME, "127.0.0.1");
assertTrue(BigQueryJdbcProxyUtility.hasProxy(hostOnly));

Comment on lines +124 to +130
private static SslConfig createSslConfig(
String sslTrustStorePath,
String sslTrustStorePassword,
String sslTrustStoreType,
String sslTrustStoreProvider,
Provider sslProvider) {
try {

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.

medium

To prevent downstream code from performing redundant disk reads and to avoid race conditions during file rotation, we should store the truststore file content in memory within our data holder classes and avoid keeping or passing the file path sslTrustStorePath.

References
  1. To prevent downstream code from performing redundant disk reads and to avoid race conditions during file rotation, store the file content (such as certificate chains) in memory within data holder classes and avoid keeping the file path.

@keshavdandeva

Copy link
Copy Markdown
Contributor Author

Superseded by the redesigned 4-PR stack (#15361 -> #15363 -> #15367 -> #15368). Closing this PR.

@keshavdandeva
keshavdandeva deleted the fix/jdbc-telemetry-1-proxy-ssl-utils branch December 1, 2026 23:27
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.

1 participant