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): post policy can be signed with a fn that takes raw bytes #5079

Merged
merged 16 commits into from Nov 9, 2021

Conversation

BrennaEpp
Copy link
Contributor

@BrennaEpp BrennaEpp commented Nov 4, 2021

  • Adds a SignRawBytes field to PostPolicyV4Options. This field works like the SignedURLOptions SignBytes field. This function expects raw bytes as opposed to the SignBytes field which expects the bytes to be hashed before called.
  • Deprecates the SignBytes field of PostPolicyV4Options
  • Adds a test to ensure that both bucket.SignedURL and GenerateSignedPostPolicyV4 work with the same signing function for SignBytes and SignRawBytes respectively.
  • Refactors some test code to reuse checks for signed urls and post policies; adds a check to TestIntegration_SignedURL to error on an expected failure not failing.

Fixes #4752

@BrennaEpp BrennaEpp requested review from a team as code owners November 4, 2021 00:19
@product-auto-label product-auto-label bot added the api: storage Issues related to the Cloud Storage API. label Nov 4, 2021
@google-cla
Copy link

google-cla bot commented Nov 4, 2021

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added the cla: no This human has *not* signed the Contributor License Agreement. label Nov 4, 2021
@google-cla
Copy link

google-cla bot commented Nov 4, 2021

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@google-cla
Copy link

google-cla bot commented Nov 4, 2021

All (the pull request submitter and all commit authors) CLAs are signed, but one or more commits were authored or co-authored by someone other than the pull request submitter.

We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that by leaving a comment that contains only @googlebot I consent. in this pull request.

Note to project maintainer: There may be cases where the author cannot leave a comment, or the comment is not properly detected as consent. In those cases, you can manually confirm consent of the commit author(s), and set the cla label to yes (if enabled on your project).

ℹ️ Googlers: Go here for more info.

@codyoss
Copy link
Member

codyoss commented Nov 4, 2021

@googlebot I consent.

@google-cla google-cla bot added cla: yes This human has signed the Contributor License Agreement. and removed cla: no This human has *not* signed the Contributor License Agreement. labels Nov 4, 2021
Copy link
Member

@codyoss codyoss left a comment

Choose a reason for hiding this comment

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

LGTM, in general. I'll let Chris look more closely. One minor comment.

storage/post_policy_v4.go Outdated Show resolved Hide resolved
@BrennaEpp BrennaEpp added the automerge Merge the pull request once unit tests and other checks pass. label Nov 5, 2021
@gcf-merge-on-green
Copy link
Contributor

Merge-on-green attempted to merge your PR for 6 hours, but it was not mergeable because either one of your required status checks failed, one of your required reviews was not approved, or there is a do not merge label. Learn more about your required status checks here: https://help.github.com/en/github/administering-a-repository/enabling-required-status-checks. You can remove and reapply the label to re-run the bot.

@gcf-merge-on-green gcf-merge-on-green bot removed the automerge Merge the pull request once unit tests and other checks pass. label Nov 6, 2021
Copy link
Contributor

@tritone tritone left a comment

Choose a reason for hiding this comment

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

Generally looks good, a few comments mostly on docs.


// verifyPostPolicy uploads a file to the obj using the provided post policy and
// verifies that it was uploaded correctly
func verifyPostPolicy(pv4 *PostPolicyV4, obj *ObjectHandle, bytesToWrite []byte, statusCodeOnSuccess int) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Don't think passing StatusCodeOnSuccess is necessary; it should always be 200 right?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It can be different depending on what you specify in PostPolicyV4Options.PolicyV4Fields.StatusCodeOnSuccess

Copy link
Contributor

@tritone tritone Nov 9, 2021

Choose a reason for hiding this comment

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

I think currently it is 200 in all these tests, so we shouldn't pass more params unnecessarily if possible.

storage/integration_test.go Outdated Show resolved Hide resolved
storage/integration_test.go Outdated Show resolved Hide resolved
storage/integration_test.go Outdated Show resolved Hide resolved
@@ -52,22 +52,31 @@ type PostPolicyV4Options struct {
// Exactly one of PrivateKey or SignBytes must be non-nil.
PrivateKey []byte

// SignBytes is a function for implementing custom signing. For example, if
// SignBytes is a function for implementing custom signing.
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe include a sentence about how it differs from SignRawBytes even though we are deprecating it.

// bytes = shaSum[:]
SignBytes func(hashBytes []byte) (signature []byte, err error)

// SignRawBytes is a function for implementing custom signing. For example, if
Copy link
Contributor

Choose a reason for hiding this comment

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

I would note explicitly that the same function that works for SignBytes for signed URLs will work for SignRawBytes for post policy. Obviously it's confusing but still better to state explicitly.

var signature []byte
var signErr error
// SignBytes is used only if SignRawBytes is not defined
if opts.SignRawBytes == nil && opts.SignBytes != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

I worry about the fact that we are checking this condition multiple times. Maybe we just add an unexported field to the options about whether the signed bytes should be hashed or not, set that once when parsing the options, then make subsequent decisions accordingly?

Copy link
Contributor

@tritone tritone left a comment

Choose a reason for hiding this comment

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

Nice improvements, looks really good!

@BrennaEpp BrennaEpp merged commit 25d1278 into googleapis:main Nov 9, 2021
@BrennaEpp BrennaEpp deleted the storage-sign-post-policy branch March 23, 2022 19:07
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. cla: yes This human has signed the Contributor License Agreement.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

storage: PostPolicyV4Options.SignBytes is not compatible with Credentials API
3 participants