Skip to content

fix(bigquery-jdbc): limit DatabaseMetaData.getURL to the endpoint, redact getPropertyInfo, and remove legacy URL round-trip helpers - #15291

Open
Neenu1995 wants to merge 23 commits into
fix/g01-structured-connect-and-datasource-overridesfrom
fix/g01-credential-redaction-metadata-propertyinfo
Open

Neenu1995 wants to merge 23 commits into
fix/g01-structured-connect-and-datasource-overridesfrom
fix/g01-credential-redaction-metadata-propertyinfo

Conversation

@Neenu1995

@Neenu1995 Neenu1995 commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

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(), and Level.CONFIG diagnostics, removes the dead URL round-trip helpers (appendPropertiesToURL, parseUriPropertyWithoutValidation, DataSource.createProperties, DataSource.serializeMap), and documents configuration precedence and credential handling in docs/USER_GUIDE.md.

What Changed & Why

  • Endpoint-only DatabaseMetaData.getURL() (b/584839495): BigQueryConnection.connectionUrl is always set via BigQueryJdbcUrlUtility.sanitizeUrlForDisplay(url) on every entry point (Driver.connect, DataSource.getConnection, and package-private BigQueryConnection(url)), so getURL() returns only the connection endpoint and never any connection property or out-of-band Properties/DataSource secret.
  • Fail-closed Level.CONFIG logging (b/584839495, b/584841439): Replaces ds.createProperties() in BigQueryConnection.<init> with DataSource.toMaskedLogMap() (covering all configured fields including oAuth2TokenUri and security bean properties, applying maskPropertyValue fail-closed without serializing maps into URL syntax), guarded by a reflection field-count assertion in DataSourceTest.
  • Redacted BigQueryDriver.getPropertyInfo() (b/584839495, b/584839379): Rewires getPropertyInfo() onto structured URL + validated Properties merge, reports the same EnableDiagnosticTelemetry opt-out decision connect() makes, guards null/non-jdbc:bigquery: URLs, invokes parseOAuthProperties() only when OAuthType is present, wraps BigQueryJdbcRuntimeException | IllegalArgumentException parse failures into BigQueryJdbcException (SQLException), and returns null for all non-allowlisted secret properties via redactPropertyInfoValue().
  • Dead-code removal: Deletes BigQueryJdbcUrlUtility.appendPropertiesToURL(), BigQueryJdbcUrlUtility.parseUriPropertyWithoutValidation(), DataSource.createProperties(), and DataSource.serializeMap(), migrating existing unit tests to the structured APIs.
  • Documentation (docs/USER_GUIDE.md): Adds a Configuration precedence and credential handling section covering precedence (DataSource > Properties > URL, with EnableDiagnosticTelemetry opt-out always winning), endpoint-only DatabaseMetaData.getURL(), Driver.getPropertyInfo() null redaction, duplicate/empty map key rejection, ignored invalid Properties keys, and empty values treated as unset.
  • Explicit inline G01 decisions documented:
    • DatabaseMetaData.getURL() returns only the connection endpoint.
    • Driver.getPropertyInfo() returns null for non-allowlisted secret properties.
    • BigQueryConnection.getAuthProperties() keeps its public signature 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 8 animal-sniffer, and 1,489 unit tests (1 skipped, 0 errors; only the known pre-existing local failure BigQueryJdbcOAuthUtilityTest.testPrivateKeyFromP12Bytes).
  • Added unit tests in BigQueryConnectionTest, BigQueryDriverTest, DataSourceTest, and BigQueryJdbcUrlUtilityTest verifying endpoint-only DatabaseMetaData.getURL() across all 3 entry points, toMaskedLogMap() security field masking and field-count parity, and Driver.getPropertyInfo() null-redaction, telemetry opt-out parity with connect(), SQLException wrapping, and invalid-URL safety.

…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().
@Neenu1995
Neenu1995 requested review from a team as code owners November 30, 2026 20:11

@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 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.

@Neenu1995
Neenu1995 added this pull request to stack #15292 November 30, 2026 20:14
@Neenu1995 Neenu1995 changed the title [WIP] fix(bigquery-jdbc): redact DatabaseMetaData.getURL and getPropertyInfo and remove legacy URL round-trip helpers fix(bigquery-jdbc): redact DatabaseMetaData.getURL and getPropertyInfo and remove legacy URL round-trip helpers Dec 1, 2026
*/
Map<String, String> toMaskedLogMap() {
Map<String, String> maskedProperties = new LinkedHashMap<>();
putMaskedProperty(

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.

Similar to the previous PR comment. This is fragile, we need a single source of truth

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.
…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
@Neenu1995
Neenu1995 requested a review from logachev December 2, 2026 19:48
@Neenu1995 Neenu1995 changed the title fix(bigquery-jdbc): redact DatabaseMetaData.getURL and getPropertyInfo and remove legacy URL round-trip helpers fix(bigquery-jdbc): limit DatabaseMetaData.getURL to the endpoint, redact getPropertyInfo, and remove legacy URL round-trip helpers Dec 3, 2026

This branch has not been deployed

No deployments
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