Repository navigation
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces credentials scoping for BigQuery Read and Write clients in BigQueryConnection to support Trusted Partner Cloud (TPC) environments, and updates several integration tests by removing the @Tag("disable_tpc") annotation and asserting specific result set types. The review feedback suggests improving test robustness by adding null and presence checks for the Authorization header in the test helper extractBearerJwtPayload to avoid potential NullPointerException or IndexOutOfBoundsException, and using try-with-resources for jsonResultSet in ITBigQueryJDBCTest to prevent resource leaks if assertions fail.
…c/it/ITBigQueryJDBCTest.java Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Queries routed through the BigQuery Storage Read API (HTAPI / Arrow) or Storage Write API fail with
UNAUTHENTICATEDwhen connecting to non-default universe domains (TPC / customuniverseDomain) using service account or Application Default Credentials.Root Cause
BigQueryJdbcOAuthUtility.getCredentials(...)returns unscopedGoogleCredentials(createScopedRequired() == true) unlessRequestGoogleDriveScope=1or service account impersonation is configured.BigQueryclient,BigQueryOptions(ServiceOptions.getScopedCredentials()) automatically scopes credentials, causingServiceAccountCredentialsin non-default universes to mint a scope-based self-signed JWT (scopeclaim, noaudclaim).BigQueryReadClientandBigQueryWriteClient,BigQueryConnectionbypassedBigQueryReadSettings.defaultCredentialsProviderBuilder()/BigQueryWriteSettings.defaultCredentialsProviderBuilder()and wrapped the unscoped credential directly inFixedCredentialsProvider.create(...). BecausecreateScopedRequired()remainedtrue,ServiceAccountCredentialsfell back to minting an audience-based self-signed JWT (audset to the custom universe Storage endpoint, noscopeclaim), which is rejected withUNAUTHENTICATED.Fix
BigQueryConnection.scopeStorageCredentials(Credentials, List<String>)mirroringGoogleCredentialsProviderinBigQueryReadSettingsandBigQueryWriteSettings:BigQueryReadSettings.getDefaultServiceScopes()/BigQueryWriteSettings.getDefaultServiceScopes()) whencreateScopedRequired()istrue, while preserving explicit scopes when already configured (such asRequestGoogleDriveScope=1).createWithUseJwtAccessWithScope(true)onServiceAccountCredentialsso self-signed JWTs include thescopeclaim without requiring extra OAuth token endpoint round-trips in GDU.@Tag("disable_tpc")) that were previously disabled due to this authentication failure.Tests
BigQueryConnectionTest: verifiesBigQueryReadClientandBigQueryWriteClientpreserve customuniverseDomainsettings and mint scope-based self-signed JWTs (scopeclaim present,audabsent), including when explicit scopes are pre-applied.ITBigQueryJDBCTest: re-enabledtestReadAPIPathLarge,testReadAPIPathLargeWithThresholdParameters, andtestReadAPIPathLargeWithThresholdNotMetfor TPC using self-containedUNNEST(GENERATE_ARRAY(...))queries and explicit result set type assertions.ITNightlyBigQueryTest: re-enabledtestHTAPIWithValidDestinationTableSavesQueriesWithStandardSQL,testReadAPIPathLarge, andtestReadAPIPathLargeWithThresholdParametersfor TPC.