Repository navigation
fix(storage): support universe_domain in gRPC clients - #19188
Merged
shradhakatyal merged 2 commits intoNov 23, 2026
Merged
shradhakatyal merged 2 commits into
shradhakatyal merged 2 commits into
Conversation
Ports googleapis#19160 onto the v3.17.1 baseline for the patch release. Updates GrpcClient and AsyncGrpcClient to resolve universe_domain from client_options or GOOGLE_CLOUD_UNIVERSE_DOMAIN and disable DirectPath outside googleapis.com. Validates credential universe domains before creating a gRPC channel, while skipping unconfigured unittest.mock credentials used in unit tests. Co-authored-by: Daniel Sanche <d.sanche14@gmail.com> Co-authored-by: Chandra Sirimala <chandrasiri@google.com> [Generated-by: AI]
Contributor
There was a problem hiding this comment.
Code Review
This pull request introduces universe domain support and validation for both the synchronous and asynchronous gRPC clients in google-cloud-storage. It adds helper functions to resolve universe domains from client options or environment variables, validates credentials against the resolved domain, and disables DirectPath for non-default universes. The review feedback highlights a potential AttributeError when validating certain mock credentials and suggests using local variables instead of redundantly re-assigning self._universe_domain within the client creation helper methods.
[Generated-by: AI]
Contributor
Author
|
/gcbrun (8e26f98) |
ShreyasSinha
approved these changes
Nov 23, 2026
shradhakatyal
pushed a commit
that referenced
this pull request
Nov 23, 2026
🤖 I have created a release *beep* *boop* --- ## [3.17.2](google-cloud-storage-v3.17.1...google-cloud-storage-v3.17.2) (2026-11-23) ### Bug Fixes * **storage:** support universe_domain in gRPC clients ([#19188](#19188)) ([d2d5dee](d2d5dee)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
daniel-sanche
pushed a commit
that referenced
this pull request
Nov 25, 2026
## Summary Ports #19160 onto the `v3.17.1` baseline after #19186 for the patch release. `GrpcClient` and `AsyncGrpcClient` now honor `universe_domain` from `client_options` or `GOOGLE_CLOUD_UNIVERSE_DOMAIN`. ## Changes - Add shared `_resolve_universe_domain`, `_resolve_grpc_config`, and `_validate_universe_domain` helpers in `grpc_client.py`. - Route gRPC channels to `storage.{universe_domain}` unless `client_options.api_endpoint` overrides the host. - Disable DirectPath automatically outside the default `googleapis.com` universe. - Validate credential universe domains before channel creation using `google.api_core.universe.compare_domains`. - Skip universe validation only for unconfigured `unittest.mock` credentials so caller unit tests continue to work. - Expose `universe_domain` on both `GrpcClient` and `AsyncGrpcClient`.
daniel-sanche
pushed a commit
that referenced
this pull request
Nov 25, 2026
🤖 I have created a release *beep* *boop* --- ## [3.17.2](google-cloud-storage-v3.17.1...google-cloud-storage-v3.17.2) (2026-11-23) ### Bug Fixes * **storage:** support universe_domain in gRPC clients ([#19188](#19188)) ([d2d5dee](d2d5dee)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: release-please[bot] <55107282+release-please[bot]@users.noreply.github.com>
This was referenced Nov 27, 2026
shradhakatyal
added a commit
that referenced
this pull request
Dec 3, 2026
…19248) ## Summary `storage.Client` now honors the `GOOGLE_CLOUD_UNIVERSE_DOMAIN` environment variable, and the signing methods validate the universe domain of credentials passed for a single call. Before this change, the REST client read the universe domain only from `client_options.universe_domain`. A workload that set only the environment variable got a `googleapis.com` client. `GrpcClient` and `AsyncGrpcClient` already read the variable since #19188. ## Changes - Add `_resolve_client_universe()` in `_helpers.py`. It is a local mirror of the shared `resolve_client_universe` helper and carries the `# TODO(universe-domain):` header, so it can be replaced by `google.api_core.universe.resolve_client_universe` later. The local copy also strips surrounding whitespace, because `determine_domain` in older `google-api-core` releases returns the value unstripped. - `Client.__init__` resolves the universe domain with that helper. Precedence is `client_options.universe_domain`, then the variable, then `googleapis.com`. - `Client._universe_domain` stays `None` when the resolved value is the default and `client_options` did not name it. The default endpoint and mTLS handling are unchanged for that case. The default universe is matched without regard to case, so `GOOGLE_CLOUD_UNIVERSE_DOMAIN=GoogleApis.com` keeps working. - `Client.__init__` converts a `client_options` mapping that is not a `dict` to a `dict`, so the constructor accepts every type the resolver accepts. - The credential universe check now skips `AnonymousCredentials`, which carry no token. - Add `_validate_signing_credentials_universe_domain()` in `_helpers.py`. `Blob.generate_signed_url`, `Bucket.generate_signed_url` and `Client.generate_signed_post_policy_v4` call it for credentials passed per call. - `Client.generate_signed_post_policy_v4` passes the client's universe domain when it signs with `access_token` and `service_account_email`, as `Blob.generate_signed_url` does. #19243 contains the same change, so either merge order works. - Add an autouse fixture in `tests/unit/conftest.py` that clears the variable, so the runner's environment cannot change test results. ## Behavior Changes The first three apply only when `GOOGLE_CLOUD_UNIVERSE_DOMAIN` is set. - Credentials whose `universe_domain` differs from the variable now raise `ValueError` at construction. API key credentials are one example, because they report `googleapis.com`. - An empty or whitespace-only value raises `EmptyUniverseError` (a `ValueError`), as it does in `GrpcClient` and the generated clients. - A value of `googleapis.com` changes nothing. - An empty or whitespace-only `client_options.universe_domain` raises `EmptyUniverseError`. An empty string was ignored before. - Surrounding whitespace in `client_options.universe_domain` is stripped. A padded value raised a credential mismatch `ValueError` before. - `client_options` that is not a `ClientOptions` instance, a `Mapping`, or `None` raises `TypeError`. - `client_options` can be any `Mapping`, for example a `types.MappingProxyType`. A mapping other than a `dict` raised `AttributeError` before. - `AnonymousCredentials` are accepted with any universe domain. `Client(client_options={"universe_domain": ...}, credentials=AnonymousCredentials())` raised `ValueError` before and now works. The same applies to `STORAGE_EMULATOR_HOST` combined with a non-default universe. - `Blob.generate_signed_url`, `Bucket.generate_signed_url` and `Client.generate_signed_post_policy_v4` raise `ValueError` when all of these hold: 1. The per-call `credentials` sign the result. 2. They report a non-default universe domain that differs from the client's universe domain. 3. The result uses the default Storage endpoint of the client's universe domain. The default endpoint of a universe domain does not accept such a result, so the call now fails early. ## Not Changed - A client configured only with `client_options.api_endpoint` still reports `googleapis.com` as its universe domain. Set `client_options.universe_domain` or the environment variable for a non-default universe. - Per-call credentials are not compared with the client in these cases: - They report `googleapis.com`. Credentials also report that value when no universe domain was set on them. - The caller passes `bucket_bound_hostname`, or an `api_access_endpoint` that is not the default endpoint of the client's universe domain. An `api_access_endpoint` equal to that default endpoint is checked. - The client uses a custom endpoint or the emulator. - Both `access_token` and `service_account_email` are passed, because the `credentials` object does not sign in that case. - They cannot sign. Those calls keep raising `AttributeError`. ## Testing - Unit tests for the resolver cover `ClientOptions` and mapping inputs, an unset variable, the default universe, precedence, surrounding whitespace, empty values, and unsupported `client_options` types. - Unit tests for the per-call credential check cover every branch. - Unit tests for the constructor cover matched and mismatched credentials, `client_options` precedence, empty and padded `client_options.universe_domain`, the default universe named in `client_options` or in mixed case in the variable, non-`dict` mappings, `api_endpoint`, mTLS, the emulator, and anonymous credentials. - Unit tests for the three signing methods cover v2 and v4, virtual-hosted style, explicit endpoints, bucket-bound hostnames, custom client endpoints, a client passed per call, access-token signing, and real service account credentials. - Tests with several cases use `pytest.mark.parametrize`. They are in plain pytest classes, because `parametrize` is not supported in the `unittest.TestCase` classes of these files. - Verified manually with a local script that sends real HTTP requests to a loopback server, for 28 client and signing configurations. - System tests in `tests/system/test__signing.py` pass `universe_domain_credential` to the default client for the three signing methods and expect `ValueError`. They are skipped when `TEST_UNIVERSE_DOMAIN_CREDENTIAL` is not set, and when the client does not use the default storage endpoint. They need no bucket and make no network call. - No system test covers the environment variable itself. That test needs a non-default universe test environment.
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.
Summary
Ports #19160 onto the
v3.17.1baseline after #19186 for the patch release.GrpcClientandAsyncGrpcClientnow honoruniverse_domainfromclient_optionsorGOOGLE_CLOUD_UNIVERSE_DOMAIN.Changes
_resolve_universe_domain,_resolve_grpc_config, and_validate_universe_domainhelpers ingrpc_client.py.storage.{universe_domain}unlessclient_options.api_endpointoverrides the host.googleapis.comuniverse.google.api_core.universe.compare_domains.unittest.mockcredentials so caller unit tests continue to work.universe_domainon bothGrpcClientandAsyncGrpcClient.