Skip to content

fix(storage): make URL signing universe domain handling consistent with EndpointContext - #15239

Open
nidhiii-27 wants to merge 4 commits into
fix/storage-universe-domain-envfrom
fix/storage-signing-universe-domain
Open

nidhiii-27 wants to merge 4 commits into
fix/storage-universe-domain-envfrom
fix/storage-signing-universe-domain

Conversation

@nidhiii-27

@nidhiii-27 nidhiii-27 commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

StorageImpl checks that the signer's universe domain matches the configured universe domain when signing URLs and POST policies, consistent with EndpointContext. Signature formats for credentials in the configured universe domain are unchanged. StorageSigningUniverseDomainTest covers signUrl and generateSignedPostPolicyV4.

@nidhiii-27 nidhiii-27 added ai-generated Pull Request generated by AI storage-bug-immunity labels Nov 25, 2026

@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 universe domain validation for signing credentials in Google Cloud Storage, ensuring that the credentials' universe domain matches the configured universe domain during URL signing and PostPolicyV4 generation. It also updates header handling in buildSignatureInfo to support case-insensitive overrides. Feedback on these changes includes a recommendation to pass null instead of a redundant Throwable as the cause in UnauthenticatedException, and a suggestion to avoid spawning a subprocess in unit tests to prevent potential flakiness and performance issues.

…th EndpointContext

StorageImpl derives default signing hosts from the configured universe domain and checks the signer's universe domain as EndpointContext does. Hostname options and signature formats in the default universe are unchanged. StorageSigningUniverseDomainTest covers signUrl and generateSignedPostPolicyV4.
@nidhiii-27
nidhiii-27 force-pushed the fix/storage-universe-domain-env branch from 6c01bec to fa26520 Compare November 27, 2026 06:51
@nidhiii-27
nidhiii-27 force-pushed the fix/storage-signing-universe-domain branch from a046f92 to 5b67dd5 Compare November 27, 2026 06:51
@nidhiii-27
nidhiii-27 marked this pull request as ready for review November 27, 2026 06:52
@nidhiii-27
nidhiii-27 requested review from a team as code owners November 27, 2026 06:52
Comment on lines +1134 to +1136
} catch (IOException e) {
throw unauthenticated(EndpointContext.UNABLE_TO_RETRIEVE_CREDENTIALS_ERROR_MESSAGE, e);
}

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.

Could we also add unit tests covering the IOException path when getUniverseDomain() fails and the ComputeEngineCredentials bypass so those branches in validateSigningCredentialsUniverseDomain are exercised?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a test in StorageSigningUniverseDomainTest for the IOException path when the signer's universe domain cannot be retrieved.

Co-authored by AI Agent

…eDomainTest

StorageSigningUniverseDomainTest now installs a clean test environment resolver in @before, before default StorageOptions instances are built. Existing test cases and @after cleanup remain unchanged.

[Generated-by: AI]
StorageImpl validates the signer's universe domain for every signed URL and POST policy host, consistent with EndpointContext. Signature formats for credentials in the configured universe domain are unchanged. StorageSigningUniverseDomainTest covers hostname options and universe domain lookup failures.

[Generated-by: AI]
private void validateSigningCredentialsUniverseDomain(ServiceAccountSigner signer) {
if (!(signer instanceof Credentials)
|| signer instanceof GdchCredentials
|| signer instanceof ComputeEngineCredentials) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion. I will follow up with you on this one directly.

Co-authored by AI Agent

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

LGTM overall! Before merging, could you double-check two quick edge cases here and in the base branch?

  • In EndpointContext and HttpTransportOptions, empty strings are only checked before reading the GOOGLE_CLOUD_UNIVERSE_DOMAIN env var—so if GOOGLE_CLOUD_UNIVERSE_DOMAIN="" is set, it slips through as "". If the base branch does the same thing, signing here would fail with a confusing 401 mismatch ("" vs googleapis.com) instead of ignoring the empty value or failing clearly at setup time.

  • Can getOptions().getResolvedUniverseDomain() ever return null? If so, configuredUniverseDomain.equals(...) will throw a NullPointerException—defaulting to googleapis.com (or using Objects.equals) would avoid that.

StorageSigningUniverseDomainTest verifies that StorageOptions configured with a custom host and an explicit googleapis.com universe domain produce a V4 signed URL that uses that host in both the URL and the signed payload. Existing test cases remain unchanged.

[Generated-by: AI]

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

ai-generated Pull Request generated by AI storage-bug-immunity

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants