Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(storage): better error messages in signed URLs #11741

Merged

Conversation

coryan
Copy link
Contributor

@coryan coryan commented May 27, 2023

The error messages for signed URL functions (CreateV2SignedUrl(), CreateV4SignedUrl() and CreatedSignedPolicyDocument()) were not helpful when the signing account is missing.

Fixes #11740


This change is Reviewable

The error messages for signed URL functions (`CreateV2SignedUrl()`,
`CreateV4SignedUrl()` and `CreatedSignedPolicyDocument()`) were not
helpful when the signing account is missing.
@product-auto-label product-auto-label bot added the api: storage Issues related to the Cloud Storage API. label May 27, 2023
@codecov
Copy link

codecov bot commented May 27, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (21e4a27) 93.76% compared to head (b350dcd) 93.76%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #11741   +/-   ##
=======================================
  Coverage   93.76%   93.76%           
=======================================
  Files        1831     1831           
  Lines      165012   165033   +21     
=======================================
+ Hits       154729   154749   +20     
- Misses      10283    10284    +1     
Impacted Files Coverage Δ
google/cloud/storage/client.cc 85.93% <100.00%> (+0.13%) ⬆️
.../cloud/storage/client_sign_policy_document_test.cc 98.51% <100.00%> (+0.05%) ⬆️
google/cloud/storage/client_sign_url_test.cc 100.00% <100.00%> (ø)

... and 5 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@coryan coryan marked this pull request as ready for review May 27, 2023 20:36
@coryan coryan requested a review from a team as a code owner May 27, 2023 20:36
Copy link
Member

@dbolduc dbolduc left a comment

Choose a reason for hiding this comment

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

Reviewed 3 of 3 files at r1, all commit messages.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on @coryan)


google/cloud/storage/client.cc line 361 at r1 (raw file):

  std::string signing_account_email = SigningEmail(signing_account);

Looks like we should move this after the "sign locally" attempt.

  // First try to sign locally.
  auto signed_blob = credentials->SignBlob(signing_account, string_to_sign);
  if (signed_blob) {
    return SignBlobResponseRaw{credentials->KeyId(), *std::move(signed_blob)};
  }

  // If signing locally fails that may be because the credentials do not
  // support signing, or because the signing account is different than the
  // credentials account. In either case, try to sign using the API.
  std::string signing_account_email = SigningEmail(signing_account);
  if (signing_account_email.empty()) {
    return google::cloud::internal::InvalidArgumentError(
        "signing account cannot be empty."
        " The client library was unable to fetch a valid signing email from"
        " the configured credentials, and the application did not provide"
        " a value in the `google::cloud::storage::SigningAccount` option.",
        GCP_ERROR_INFO());
  }

  internal::SignBlobRequest sign_request(
      signing_account_email, internal::Base64Encode(string_to_sign), {});

Copy link
Contributor Author

@coryan coryan left a comment

Choose a reason for hiding this comment

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

Reviewable status: 2 of 3 files reviewed, 1 unresolved discussion (waiting on @dbolduc)


google/cloud/storage/client.cc line 361 at r1 (raw file):

Previously, dbolduc (Darren Bolduc) wrote…

Looks like we should move this after the "sign locally" attempt.

  // First try to sign locally.
  auto signed_blob = credentials->SignBlob(signing_account, string_to_sign);
  if (signed_blob) {
    return SignBlobResponseRaw{credentials->KeyId(), *std::move(signed_blob)};
  }

  // If signing locally fails that may be because the credentials do not
  // support signing, or because the signing account is different than the
  // credentials account. In either case, try to sign using the API.
  std::string signing_account_email = SigningEmail(signing_account);
  if (signing_account_email.empty()) {
    return google::cloud::internal::InvalidArgumentError(
        "signing account cannot be empty."
        " The client library was unable to fetch a valid signing email from"
        " the configured credentials, and the application did not provide"
        " a value in the `google::cloud::storage::SigningAccount` option.",
        GCP_ERROR_INFO());
  }

  internal::SignBlobRequest sign_request(
      signing_account_email, internal::Base64Encode(string_to_sign), {});

Done.

@coryan coryan enabled auto-merge (squash) May 27, 2023 22:17
@coryan coryan merged commit 3578ed4 into googleapis:main May 27, 2023
@coryan coryan deleted the feat-storage-better-sign-url-error-messages branch May 29, 2023 15:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the Cloud Storage API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bad error message when Signing URLs without a service account email
2 participants