Repository navigation
refactor(bigquery-jdbc): extract SSL TrustStore helpers and unify proxy checks - #15340
keshavdandeva wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
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.
| static boolean hasProxy(Map<String, String> proxyProperties) { | ||
| return proxyProperties != null | ||
| && proxyProperties.containsKey(BigQueryJdbcUrlUtility.PROXY_HOST_PROPERTY_NAME) | ||
| && proxyProperties.containsKey(BigQueryJdbcUrlUtility.PROXY_PORT_PROPERTY_NAME); | ||
| } |
There was a problem hiding this comment.
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);
}| Map<String, String> hostOnly = new HashMap<>(); | ||
| hostOnly.put(BigQueryJdbcUrlUtility.PROXY_HOST_PROPERTY_NAME, "127.0.0.1"); | ||
| assertFalse(BigQueryJdbcProxyUtility.hasProxy(hostOnly)); |
There was a problem hiding this comment.
Since hasProxy should return true when only ProxyHost is specified (with the port defaulting to -1), this assertion should be updated to assertTrue.
| 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)); |
| private static SslConfig createSslConfig( | ||
| String sslTrustStorePath, | ||
| String sslTrustStorePassword, | ||
| String sslTrustStoreType, | ||
| String sslTrustStoreProvider, | ||
| Provider sslProvider) { | ||
| try { |
There was a problem hiding this comment.
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
- 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.
Summary
Extracts shared SSL TrustStore and proxy detection helpers in
BigQueryJdbcProxyUtilityso upcoming OpenTelemetry exporter changes can reuse the same TrustStore and proxy logic without duplication, and cleans up inconsistent proxy checks.Key Decisions
createSslConfig: The 4-arg package-privatecreateSslConfig(...)uses the JDK default TLS provider (matchinggetTransportChannelProviderfor gRPC), whilegetHttpTransportFactorypassesCONSCRYPT_PROVIDERto keep post-quantum named groups on Apache HttpClient 5.createTrustManagerFactory(...)shared by both HTTP (createSslConfig) and gRPC (getTransportChannelProvider).hasProxy(...)(ProxyHostandProxyPortpresent) andhasProxyAuth(...)(ProxyUidandProxyPwdpresent) across all transport call sites, and removed a duplicateaddAuthToProxyIfPresent(...)invocation.Behavior Changes
ProxyHostrejection:parseProxyProperties(...)now rejects whitespace-onlyProxyHostvalues immediately withIllegalArgumentExceptioninstead of deferring failure to HTTP route construction.createSslConfig(...)throws"Failed to configure SSL TrustStore"instead of"Failed to configure SSL TrustStore for HTTP transport".