Skip to content

fix(storage): require a universe domain for IAM signBlob signing - #19383

Draft
shradhakatyal wants to merge 1 commit into
googleapis:mainfrom
shradhakatyal:fix/storage-signing-universe-default
Draft

shradhakatyal wants to merge 1 commit into
googleapis:mainfrom
shradhakatyal:fix/storage-signing-universe-default

Conversation

@shradhakatyal

Copy link
Copy Markdown
Contributor

Summary

Signing through the IAM signBlob API now needs an explicit universe domain. _signing._sign_message no longer falls back to googleapis.com, and it rejects a missing or empty value before it sends a request.

Changes

  • _signing._sign_message takes universe_domain as a required argument. It raises ValueError when the value is not a non-empty string, and strips surrounding whitespace.
  • _signing.generate_signed_url_v2 and _signing.generate_signed_url_v4 document universe_domain. They still accept None for credentials that sign locally.

Behavior Changes

These apply only to direct callers of the private _signing module.

  • The two helpers raise ValueError when access_token and service_account_email are passed without universe_domain. Before this change they built a request URL with the host iamcredentials.None.
  • A call to _sign_message without universe_domain raises TypeError. Before this change it used googleapis.com.

Not Changed

  • Blob.generate_signed_url and Client.generate_signed_post_policy_v4 pass the universe domain of the client, as before.
  • Bucket.generate_signed_url signs locally and does not use signBlob.
  • Signing with credentials that hold a private key does not need a universe domain.

Testing

  • Unit tests for _sign_message cover the request URL for two universe domains, a padded value, and missing, empty, whitespace-only and non-string values.
  • Unit tests for both helpers cover the value passed to _sign_message, the signBlob request URL, access-token signing without a universe domain, and local signing without a universe domain.
  • The tests with several cases use pytest.mark.parametrize.

BEGIN_COMMIT_OVERRIDE
fix(storage): require a universe domain for IAM signBlob signing
END_COMMIT_OVERRIDE

`_signing._sign_message` had a default universe domain of
`googleapis.com`, and the `generate_signed_url_v2` and
`generate_signed_url_v4` helpers passed `None` to it when the caller
did not set one. The request URL was then built from a value that the
caller never chose.

`_sign_message` now takes `universe_domain` as a required argument and
raises `ValueError` when it is not a non-empty string. No request is
sent in that case. The helpers still accept `universe_domain=None` for
credentials that sign locally.

`Blob.generate_signed_url` and `Client.generate_signed_post_policy_v4`
already pass the universe domain of the client, so their behavior does
not change.

[Generated-by: AI]

@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 updates the URL signing mechanism in google-cloud-storage to require a universe_domain parameter when using an access token and service account email. The _sign_message function has been updated to make universe_domain a required argument and now validates that it is a non-empty string. Corresponding unit tests have been added to verify correct behavior, URL construction, and error handling for invalid or missing universe domains. There are no review comments, and I have no additional feedback to provide.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant