Repository navigation
feat(google-cloud-core): add universe_domain resolution, HTTP validation, and mTLS guards - #19231
daniel-sanche wants to merge 13 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces support for custom universe domains across the Google Cloud Core library. It updates connection and client initialization to resolve the universe domain, validate credentials against the resolved universe, and dynamically format API endpoints. Additionally, it propagates the default service host to AuthorizedSession and secure_authorized_channel when supported. Feedback on these changes highlights two important compatibility issues: first, mock credentials in downstream tests may trigger false-positive UniverseMismatchErrors if their universe_domain attribute returns a mock object; second, older versions of google-auth (prior to 2.23.0) do not support the default_host parameter in AuthorizedSession, which could lead to a TypeError unless handled gracefully.
|
SYNC WARNING: I noticed a few sync gaps between the In #19231 (
In #19232 (
I know that you have better context on this than I do, so if any of these suggestions are wrong, please leave a comment here. Gemini will pick them up and learn from them during the next sync sweep. |
481a7ca to
2f612ca
Compare
|
@chalmerlowe This stack is focused on http clients, so some of the grpc logic wasn't necessary. I originally held it back, to keep the diff smaller. But I changed it to keep the helpers consistent, because consistency is probably better than being concise here |
a58251f to
9cd9b41
Compare
…19251) ## Context & Problem google.cloud.ndb.Client ignored client_options.universe_domain and GOOGLE_CLOUD_UNIVERSE_DOMAIN, hardcoding datastore.googleapis.com and opening a gRPC channel without validating credential universe parity (AIP-4113). ## Summary of Changes - Resolve universe_domain in ndb.Client.__init__ via google.api_core.universe.determine_domain and expose client.universe_domain. - Template the default Datastore endpoint as datastore.<universe_domain> when client_options.api_endpoint and DATASTORE_EMULATOR_HOST are unset. - Validate credential universe parity via _validate_credentials_universe before opening a secure gRPC channel (exempting emulator mode, AnonymousCredentials, uncached compute_engine.Credentials, and non-string credential mocks). - Add unit tests covering client_options, GOOGLE_CLOUD_UNIVERSE_DOMAIN, endpoint precedence, empty universe errors, mismatch errors before channel creation, and exemptions, and clear GOOGLE_CLOUD_UNIVERSE_DOMAIN in unit test conftest. ## Why This Approach Resolving universe_domain and validating credentials directly inside ndb.Client.__init__ before make_secure_channel prevents cross-universe token leakage while preserving google-cloud-ndb's google-api-core >= 2.28.0 lower bound. We considered waiting for google.api_core.universe.validate_credentials_universe (> 2.44.0) or relying on google-cloud-core, but mirroring _validate_credentials_universe locally with a TODO(universe-domain) marker matches sibling PRs (#19192, #19231) and works immediately without bumping dependency floors. ## Intentionally Out of Scope - Bumping google-api-core minimum version in setup.py or testing/constraints-3.10.txt. - Changing DatastoreGrpcTransport or google-cloud-datastore client behavior (tracked separately in b/588887217). - Refactoring unrelated ndb.Client attributes or removing DATASTORE_API_HOST. ## Verification pytest packages/google-cloud-ndb/tests/unit/ on Python 3.14 with google-api-core==2.28.0 (1851 passed, including 16 new universe_domain tests in test_client.py) Fixes: b/589768754
Adds
universe_domainsupport and mTLS endpoint guards togoogle-cloud-coreso handwritten clients work consistently outsidegoogleapis.com:Client: Resolvesuniverse_domainfromclient_optionsorGOOGLE_CLOUD_UNIVERSE_DOMAIN, validates credentials against the resolved universe when initializing the HTTP session, and passesdefault_hosttoAuthorizedSessionfor self-signed JWTs.JSONConnection: ExpandsDEFAULT_API_ENDPOINT_TEMPLATEusing the client'suniverse_domainwhen no customapi_endpointis set, and restricts mTLS endpoint switching togoogleapis.com.make_secure_channel: Forwardsdefault_hosttosecure_authorized_channelwhen supported bygoogle-auth.Note: this design means upstream libraries will have to bump their google-cloud-core floor to make use of the new functionality. I think this is a good trade-off, to avoid duplicating logic in the higher layers. Unlike other dependencies (google-auth, grpc, etc), updating google-cloud-core should have a lower diamond-dependency risk