Repository navigation
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request adds universe domain support and validation to the Google Cloud NDB client, resolving the universe domain from client options or environment variables and templating the API endpoint. A critical issue was identified in the _validate_credentials_universe helper function, where universe.compare_domains is incorrectly called with a Credentials object instead of a domain string, and its return value is not checked to raise a UniverseMismatchError on mismatch.
Resolve universe_domain via google.api_core.universe.determine_domain, template the default Datastore host as datastore.<universe_domain>, and validate credential universe parity before opening a secure gRPC channel (AIP-4113). Fixes: b/589768754
ohmayr
force-pushed
the
smallpr/b589768754-ndb-universe-domain
branch
from
November 27, 2026 18:24
7d3f485 to
6f851f4
Compare
chalmerlowe
reviewed
Nov 30, 2026
Remove the fail-open non-string universe_domain bypass in _validate_credentials_universe so it delegates directly to universe.compare_domains and matches google-api-core, accept any Mapping in Client.__init__ via client_options.from_dict, and fall back to api_endpoint when DATASTORE_EMULATOR_HOST is an empty string. Fix tests/conftest.py unit-module prefix matching so ambient GOOGLE_CLOUD_UNIVERSE_DOMAIN is cleared under pytest, set universe_domain on patch_credentials, and expand test_client.py assertions and edge-case coverage.
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.
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
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
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