Repository navigation
fix(bigquery-jdbc): limit DatabaseMetaData.getURL to the endpoint, redact getPropertyInfo, and remove legacy URL round-trip helpers - #15291
Conversation
…nd validate property keys
…ns connect pipeline Stack: PR 2 of 3 (base: fix/g01-url-parsing-and-sanitization) Bug: b/584841439, b/584840529, b/584840728, b/584839495 - Replace DataSource.getConnection() createProperties/DriverManager URL round-trip with a defensive typed DataSource snapshot passed directly to BigQueryDriver.connectWithDataSource(). - Preserve all 15 previously dropped security bean fields, explicit false on boxed telemetry/OTel flags, unset enableDiagnosticTelemetry, and raw ImmutableMap queryProperties/labels. - Unify BigQueryDriver.connect() onto two-phase single-pass tokenization with last-wins precedence (Properties/DataSource > URL) for LogLevel, LogPath, enableGcpLogExporter, and EnableDiagnosticTelemetry. - Redact invalid-URL exceptions in DataSource.getConnection() and fix single-read URL TOCTOU.
…o and remove legacy URL round-trip helpers Stack: PR 3 of 3 (base: fix/g01-structured-connect-and-datasource-overrides) Bug: b/584839495 - Sanitize BigQueryConnection.connectionUrl via sanitizeUrlForDisplay() on all entry points so DatabaseMetaData.getURL() omits non-allowlisted URL params and never exposes out-of-band secrets. - Rewire BigQueryDriver.getPropertyInfo() onto structured URL + validated Properties merge, guard null/short/non-BigQuery URLs, and return null for non-allowlisted secret properties. - Replace DataSource.createProperties() in Level.CONFIG logging with DataSource.toMaskedLogMap() covering all configured fields. - Remove unused legacy helpers appendPropertiesToURL(), parseUriPropertyWithoutValidation(), DataSource.createProperties(), and DataSource.serializeMap(). - Document explicit G01 decisions inline on DatabaseMetaData.getURL(), BigQueryDriver.getPropertyInfo(), and BigQueryConnection.getAuthProperties().
There was a problem hiding this comment.
Code Review
This pull request enhances security and credential protection in the BigQuery JDBC driver by ensuring that sensitive connection properties and secrets are not exposed in plaintext. Specifically, BigQueryConnection now sanitizes the connection URL to omit non-allowlisted parameters, and Driver.getPropertyInfo() redacts sensitive properties by returning null per the JDBC contract. Additionally, DataSource replaces its raw createProperties() method with toMaskedLogMap() to provide a sanitized, masked view of properties for diagnostic logging. Unused utility methods have been removed, and comprehensive unit tests have been added to verify these security improvements. There are no review comments, and I have no feedback to provide.
…L/PartnerToken/map parsing
…ctured-connect-and-datasource-overrides
…pt-out always wins
…to fix/g01-credential-redaction-metadata-propertyinfo
…, guard toMaskedLogMap, and update USER_GUIDE
…ty and not an OpenTelemetry instance
…to fix/g01-credential-redaction-metadata-propertyinfo
| */ | ||
| Map<String, String> toMaskedLogMap() { | ||
| Map<String, String> maskedProperties = new LinkedHashMap<>(); | ||
| putMaskedProperty( |
There was a problem hiding this comment.
Similar to the previous PR comment. This is fragile, we need a single source of truth
There was a problem hiding this comment.
Agreed. b/592620248 covers this. Today the reflection guardrail in DataSourceTest only compares the toMaskedLogMap() entry count, so it catches a missing entry but not a misnamed one. With the registry, this map would be generated from the property definitions and could not drift. I am not adding another test in this stack.
…id Properties keys Address review feedback on #15289: DatabaseMetaData display URL now returns only the caller's connection endpoint, validatePropertyKey is renamed to extractValidPropertyKey and rejects non-String keys, and keys that are blank, padded, or contain ';', '=', or control characters are ignored with a warning instead of failing the connection.
…ctured-connect-and-datasource-overrides
…nd empty DataSource strings as unset Address review feedback on #15290: an EndpointOverrides or PrivateServiceConnectUris value from a DataSource setter or Properties now replaces both aliases from the URL, empty-string DataSource setters are treated as unset like empty Properties values, and invalid Properties keys are ignored with a warning via extractValidPropertyKey.
…to fix/g01-credential-redaction-metadata-propertyinfo # Conflicts: # java-bigquery-jdbc/src/main/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcUrlUtility.java # java-bigquery-jdbc/src/test/java/com/google/cloud/bigquery/jdbc/BigQueryJdbcUrlUtilityTest.java
…es with connect Address review feedback on #15291: Driver.getPropertyInfo reports EnableDiagnosticTelemetry=false when any source opts out, matching connect(), applies the EndpointOverrides/PrivateServiceConnectUris alias rule, and a stale process comment on getAuthProperties is removed.
When one EndpointOverrides/PrivateServiceConnectUris alias is configured and the other is an empty string, copy the empty alias as null so it is not surfaced in diagnostic logs.
…to fix/g01-credential-redaction-metadata-propertyinfo
…in getPropertyInfo
…ctured-connect-and-datasource-overrides
…to fix/g01-credential-redaction-metadata-propertyinfo
Stack: PR 3 of 3 (base:
fix/g01-structured-connect-and-datasource-overrides)Bug: b/584839495, b/584839379, b/584840529, b/584841439
Summary
Completes G01 credential redaction across
DatabaseMetaData.getURL(),BigQueryDriver.getPropertyInfo(), andLevel.CONFIGdiagnostics, removes the dead URL round-trip helpers (appendPropertiesToURL,parseUriPropertyWithoutValidation,DataSource.createProperties,DataSource.serializeMap), and documents configuration precedence and credential handling indocs/USER_GUIDE.md.What Changed & Why
DatabaseMetaData.getURL()(b/584839495):BigQueryConnection.connectionUrlis always set viaBigQueryJdbcUrlUtility.sanitizeUrlForDisplay(url)on every entry point (Driver.connect,DataSource.getConnection, and package-privateBigQueryConnection(url)), sogetURL()returns only the connection endpoint and never any connection property or out-of-bandProperties/DataSourcesecret.Level.CONFIGlogging (b/584839495,b/584841439): Replacesds.createProperties()inBigQueryConnection.<init>withDataSource.toMaskedLogMap()(covering all configured fields includingoAuth2TokenUriand security bean properties, applyingmaskPropertyValuefail-closed without serializing maps into URL syntax), guarded by a reflection field-count assertion inDataSourceTest.BigQueryDriver.getPropertyInfo()(b/584839495,b/584839379): RewiresgetPropertyInfo()onto structured URL + validatedPropertiesmerge, reports the sameEnableDiagnosticTelemetryopt-out decisionconnect()makes, guardsnull/non-jdbc:bigquery:URLs, invokesparseOAuthProperties()only whenOAuthTypeis present, wrapsBigQueryJdbcRuntimeException | IllegalArgumentExceptionparse failures intoBigQueryJdbcException(SQLException), and returnsnullfor all non-allowlisted secret properties viaredactPropertyInfoValue().BigQueryJdbcUrlUtility.appendPropertiesToURL(),BigQueryJdbcUrlUtility.parseUriPropertyWithoutValidation(),DataSource.createProperties(), andDataSource.serializeMap(), migrating existing unit tests to the structured APIs.docs/USER_GUIDE.md): Adds aConfiguration precedence and credential handlingsection covering precedence (DataSource>Properties> URL, withEnableDiagnosticTelemetryopt-out always winning), endpoint-onlyDatabaseMetaData.getURL(),Driver.getPropertyInfo()null redaction, duplicate/empty map key rejection, ignored invalidPropertieskeys, and empty values treated as unset.DatabaseMetaData.getURL()returns only the connection endpoint.Driver.getPropertyInfo()returnsnullfor non-allowlisted secret properties.BigQueryConnection.getAuthProperties()keeps itspublicsignature unchanged for G01 API/binary compatibility (ITPSCBigQueryTest,ITUniverseDomainBigQueryTest).How It Was Tested
JAVA_HOME=/usr/lib/jvm/java-21-openjdk-amd64 make lint— 0 reformatted.mvn -B -ntp clean test— Enforcer, Checkstyle (0 violations), Java 8animal-sniffer, and 1,489 unit tests (1 skipped, 0 errors; only the known pre-existing local failureBigQueryJdbcOAuthUtilityTest.testPrivateKeyFromP12Bytes).BigQueryConnectionTest,BigQueryDriverTest,DataSourceTest, andBigQueryJdbcUrlUtilityTestverifying endpoint-onlyDatabaseMetaData.getURL()across all 3 entry points,toMaskedLogMap()security field masking and field-count parity, andDriver.getPropertyInfo()null-redaction, telemetry opt-out parity withconnect(),SQLExceptionwrapping, and invalid-URL safety.