Repository navigation
fix(storage): make URL signing universe domain handling consistent with EndpointContext - #15239
nidhiii-27 wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
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.
6c01bec to
fa26520
Compare
a046f92 to
5b67dd5
Compare
| } catch (IOException e) { | ||
| throw unauthenticated(EndpointContext.UNABLE_TO_RETRIEVE_CREDENTIALS_ERROR_MESSAGE, e); | ||
| } |
There was a problem hiding this comment.
Could we also add unit tests covering the IOException path when getUniverseDomain() fails and the ComputeEngineCredentials bypass so those branches in validateSigningCredentialsUniverseDomain are exercised?
There was a problem hiding this comment.
Added a test in StorageSigningUniverseDomainTest for the IOException path when the signer's universe domain cannot be retrieved.
Co-authored by AI Agent
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) { |
There was a problem hiding this comment.
Thanks for the suggestion. I will follow up with you on this one directly.
Co-authored by AI Agent
Dhriti07
left a comment
There was a problem hiding this comment.
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]
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.