Skip to content

fix(bigtable): validate universe domain on client initialization - #15399

Merged
mutianf merged 5 commits into
googleapis:mainfrom
mutianf:fix-universe-domain-validation
Dec 3, 2026
Merged

mutianf merged 5 commits into
googleapis:mainfrom
mutianf:fix-universe-domain-validation

Conversation

@mutianf

@mutianf mutianf commented Dec 2, 2026

Copy link
Copy Markdown
Contributor

No description provided.

BigtableChannelPrimer and ShimImpl issue raw gRPC calls during client initialization outside GAX's GrpcClientCalls pipeline, bypassing EndpointContext.validateUniverseDomain(). Validate the configured universe domain against the credentials once in BigtableClientContext.create() before creating metrics, channels, primer, or ShimImpl so mismatched clients fail fast with UNAUTHENTICATED without sending any network traffic or credentials.
@mutianf
mutianf requested review from a team as code owners December 2, 2026 18:51

@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 introduces universe domain validation in BigtableClientContext to ensure that startup RPCs do not send credentials to a mismatched universe. It adds the validateUniverseDomain helper method and corresponding unit tests to verify correct behavior under various credential types and error scenarios. A review comment highlights a potential NullPointerException if configuredUniverseDomain is null, suggesting to default it to Credentials.GOOGLE_DEFAULT_UNIVERSE.

Comment on lines +387 to +388
static void validateUniverseDomain(
String configuredUniverseDomain, @Nullable Credentials credentials) {

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

If configuredUniverseDomain is null (which can happen if settings.getUniverseDomain() is not configured or returns null), calling configuredUniverseDomain.equals(...) will throw a NullPointerException. To prevent this, we should default configuredUniverseDomain to Credentials.GOOGLE_DEFAULT_UNIVERSE if it is null.

Suggested change
static void validateUniverseDomain(
String configuredUniverseDomain, @Nullable Credentials credentials) {
static void validateUniverseDomain(
@Nullable String configuredUniverseDomain, @Nullable Credentials credentials) {
if (configuredUniverseDomain == null) {
configuredUniverseDomain = Credentials.GOOGLE_DEFAULT_UNIVERSE;
}

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.

StubSettings.getUniverseDomain() is final and returns EndpointContext.resolvedUniverseDomain(), which already defaults unconfigured values to Credentials.GOOGLE_DEFAULT_UNIVERSE (googleapis.com) and is non-null in AutoValue. So settings.getUniverseDomain() cannot return null here.

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

Overall placement looks good: validating before getBackgroundExecutorProvider().getExecutor(), builtinOtelFactory.create(), BigtableChannelPrimer, ClassicDirectAccessChecker, and ShimImpl prevents startup RPCs, metadata fetches, and executor/metrics setup on a universe mismatch, and JwtCredentialsWithAudience delegates getUniverseDomain() properly.

One GAX parity gap: EndpointContext.validateUniverseDomain() skips ApiKeyCredentials (if (credentials instanceof ApiKeyCredentials) return;) because API keys carry no universe domain metadata and Credentials.getUniverseDomain() defaults to googleapis.com. Consider adding the same ApiKeyCredentials check (and a unit test) in BigtableClientContext.validateUniverseDomain() so ApiKeyCredentials with a non-GDU universeDomain is not rejected at init.

Reviewed with potto

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

I think there is a much cleaner approach that doesnt require all of this duplication. Lets chat offline

@mutianf
mutianf merged commit 97b8c78 into googleapis:main Dec 3, 2026
196 checks passed
@mutianf
mutianf deleted the fix-universe-domain-validation branch December 3, 2026 14:43
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.

4 participants