Repository navigation
fix(bigtable): validate universe domain on client initialization - #15399
Conversation
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.
There was a problem hiding this comment.
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.
| static void validateUniverseDomain( | ||
| String configuredUniverseDomain, @Nullable Credentials credentials) { |
There was a problem hiding this comment.
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.
| 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; | |
| } |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
I think there is a much cleaner approach that doesnt require all of this duplication. Lets chat offline
No description provided.