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

Fix presigning bug with content-length and content-type in S3 #1216

Merged
merged 8 commits into from Feb 24, 2022

Conversation

jdisanti
Copy link
Collaborator

@jdisanti jdisanti commented Feb 23, 2022

Motivation and Context

Description

Rather than remove content-length and content-type when signing and creating a presigned request, this PR refactors MakeOperationGenerator to not produce default values for those headers when making an operation for presigning.

Testing

  • Updated S3 presign tests
  • Ran Polly presign tests
  • Manually tested S3 presigning:
    • Set content-length to a value in the input, and then verified there is a signing error when uploading a file that is not that length, and that it succeeds with the matching file size.
    • Set content-type to a value in the input, and then verified there is a signing error with a different content-type, and that it succeeds when it matches.

Checklist

  • I have updated CHANGELOG.next.toml if I made changes to the AWS SDK, generated SDK code, or SDK runtime crates

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@jdisanti jdisanti requested a review from a team as a code owner February 23, 2022 00:57
@github-actions
Copy link

A new doc preview is ready to view.

@github-actions
Copy link

A new generated diff is ready to view.

@github-actions
Copy link

A new generated diff is ready to view.

@github-actions
Copy link

A new doc preview is ready to view.

Copy link
Collaborator

@rcoh rcoh left a comment

Choose a reason for hiding this comment

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

LGTM! I like the design we landed on for this, thanks for the iteration!

author = "jdisanti"

[[aws-sdk-rust]]
message = "Fixed a bug in S3 that prevented the `content-length` and `content-type` inputs from being included in a presigned request signature"
Copy link
Collaborator

Choose a reason for hiding this comment

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

a sentence about the impact may be helpful, "With this fix, customers can generate presigned URLs that enforce content-length and content type" or something

Comment on lines 266 to 267
req.headers_mut().remove(USER_AGENT);
req.headers_mut().remove("X-Amz-User-Agent");
Copy link
Collaborator

Choose a reason for hiding this comment

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

maybe this is hard...this is probably hard...ideally we just wouldn't hit the UA middleware

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We could potentially add something to the property bag that tells the UA middleware to no-op, but I don't think it would be easy to customize the middleware in the presigning function as it currently is.

use s3::presigning::config::PresigningConfig;
use std::error::Error;
use std::time::{Duration, SystemTime};

macro_rules! presign_input {
Copy link
Collaborator

Choose a reason for hiding this comment

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

comment on test macros is often helpful

private val public: Boolean = true
private val public: Boolean = true,
/** Whether or not to include default values for content-length and content-type */
private val includeDefaultPayloadHeaders: Boolean = true,
Copy link
Collaborator

Choose a reason for hiding this comment

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

consider removing the default values here—since this function is only invoked in 2 (?) places, explicit is probably clearer on both sides

@@ -76,16 +79,19 @@ open class MakeOperationGenerator(
val fnType = if (public) "pub async fn" else "async fn"

implBlockWriter.docs("Consumes the builder and constructs an Operation<#D>", outputSymbol)
Attribute.Custom("allow(unused_mut)").render(implBlockWriter) // For codegen simplicity
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Attribute.Custom("allow(unused_mut)").render(implBlockWriter) // For codegen simplicity
Attribute.AllowUnusedMut.render(implBlockWriter) // For codegen simplicity

*codegenScope
)
}
for (header in protocol.additionalRequestHeaders(operationShape)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

are these ones we want to always set? I guess so right? this is stuff like operation for JSON RPC?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, it looks like it's only used by AWS JSON to add the x-amz-target header, which is needed to identify the operation to the service. We wouldn't want to remove these for this current use-case.

@jdisanti
Copy link
Collaborator Author

Going to add S3 to the codegen diff so that we can see these changes in the PR.

@jdisanti
Copy link
Collaborator Author

It looks like it's not so simple to just include S3. It should already be in the diff output, but it seems like diff2html is dropping files when the diff is exceedingly large. Going to punt on this for now.

@jdisanti jdisanti requested a review from a team as a code owner February 24, 2022 01:46
@github-actions
Copy link

A new doc preview is ready to view.

@github-actions
Copy link

A new generated diff is ready to view.

@github-actions
Copy link

A new doc preview is ready to view.

Copy link
Contributor

@crisidev crisidev left a comment

Choose a reason for hiding this comment

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

LGTM from a server perspective.

@github-actions
Copy link

A new doc preview is ready to view.

@github-actions
Copy link

A new generated diff is ready to view.

@Velfi Velfi merged commit b989a8d into main Feb 24, 2022
@Velfi Velfi deleted the jdisanti-fix-presign-default-headers branch February 24, 2022 17:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants