Skip to content

feat(google-cloud-core): add universe_domain resolution, HTTP validation, and mTLS guards - #19231

Open
daniel-sanche wants to merge 7 commits into
mainfrom
python_bug_burndown_track_five_google-cloud-core_01_universe-domain
Open

daniel-sanche wants to merge 7 commits into
mainfrom
python_bug_burndown_track_five_google-cloud-core_01_universe-domain

Conversation

@daniel-sanche

@daniel-sanche daniel-sanche commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Adds universe_domain support and mTLS endpoint guards to google-cloud-core so handwritten clients work consistently outside googleapis.com:

  • Client: Resolves universe_domain from client_options or GOOGLE_CLOUD_UNIVERSE_DOMAIN, validates credentials against the resolved universe when initializing the HTTP session, and passes default_host to AuthorizedSession for self-signed JWTs.
  • JSONConnection: Expands DEFAULT_API_ENDPOINT_TEMPLATE using the client's universe_domain when no custom api_endpoint is set, and restricts mTLS endpoint switching to googleapis.com.
  • make_secure_channel: Forwards default_host to secure_authorized_channel when supported by google-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

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

@chalmerlowe

Copy link
Copy Markdown
Contributor

SYNC WARNING:

I noticed a few sync gaps between the google-api-core==2.28.0 fallback helpers in #19231 (google-cloud-core) and the proposed shared helpers in #19211, plus private cross-package imports in downstream PRs #19232, #19233, and #19235. I recommend the following actions:

In #19231 (google-cloud-core):

  • Mirror _validate_credentials_universe in google/cloud/client/__init__.py on #19211 validate_credentials_universe (universe.py L277–309), which goes one step further and ALSO exempts google.auth.aio.credentials.AnonymousCredentials alongside sync AnonymousCredentials and uncached compute_engine.Credentials and has a more robust docstring.
  • Mirror _is_googleapis_url in google/cloud/_http/__init__.py on #19211 is_googleapis_host (universe.py L371–395), which is more robust and uses an internal function call to _parse_target() to ALSO handle @ userinfo, # fragments, malformed ports, and scheme-less/gRPC targets.
  • Add a protected _validate_universe_domain(self) method on google.cloud.client.Client in google/cloud/client/__init__.py (matching the GAPIC client convention in client.py.j2) so subclasses can validate without importing a private module helper (while keeping it off google-cloud-core's public standalone API).
  • Keep the # TODO(universe-domain): fallback markers in google-cloud-core until testing/constraints-3.10.txt exceeds google-api-core 2.44.0.

In #19232 (dns), #19233 (runtimeconfig), and #19235 (translate):

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.

@daniel-sanche
daniel-sanche force-pushed the python_bug_burndown_track_five_google-cloud-core_01_universe-domain branch from 481a7ca to 2f612ca Compare November 30, 2026 19:15
@daniel-sanche daniel-sanche changed the title [DRAFT] feat(google-cloud-core): add universe_domain resolution, HTTP validation, and mTLS guards feat(google-cloud-core): add universe_domain resolution, HTTP validation, and mTLS guards Nov 30, 2026
@daniel-sanche
daniel-sanche marked this pull request as ready for review November 30, 2026 20:03
@daniel-sanche
daniel-sanche requested a review from a team as a code owner November 30, 2026 20:03
@daniel-sanche

Copy link
Copy Markdown
Contributor Author

@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

This branch has not been deployed

No deployments
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.

2 participants