aws-sdk-rust: `SdkBody::from_dyn()` produces a Request with an invalid signature
Describe the bug
We recently updated our AWS dependencies and had to replace our usage of with_body_callback(). I followed the suggestion to wrap the SdkBody, as proposed here.
However this change causes the body to be an UNSIGNED-PAYLOAD, which is - as far as we can find - not valid for all services. Looking at other SDK’s and implementations, it only seems to be used with S3.
Expected Behavior
A request containing a wrapped SdkBody to be correctly signed.
Current Behavior
InvalidSignatureException
The request signature we calculated does not match the signature you provided.
Our requests to S3 do seem to correctly signed when using this same code.
Reproduction Steps
I can look to create a sample, but thought raising this now given the differences with other SDKs worthwhile
Possible Solution
No response
Additional Information/Context
https://docs.rs/aws-sig-auth/latest/src/aws_sig_auth/signer.rs.html#196-197
// A body that is already in memory can be signed directly. A body that is not in memory // (any sort of streaming body or presigned request) will be signed via UNSIGNED-PAYLOAD.
Checking the JS SDK it seems to be specific to services, rather than generally applied.
Version
├── aws-config v0.54.1
│ ├── aws-credential-types v0.54.1
│ │ ├── aws-smithy-async v0.54.4
│ │ ├── aws-smithy-types v0.54.4
│ ├── aws-http v0.54.1
│ │ ├── aws-credential-types v0.54.1 (*)
│ │ ├── aws-smithy-http v0.54.4
│ │ │ ├── aws-smithy-eventstream v0.54.4
│ │ │ │ ├── aws-smithy-types v0.54.4 (*)
│ │ │ ├── aws-smithy-types v0.54.4 (*)
│ │ ├── aws-smithy-types v0.54.4 (*)
│ │ ├── aws-types v0.54.1
│ │ │ ├── aws-credential-types v0.54.1 (*)
│ │ │ ├── aws-smithy-async v0.54.4 (*)
│ │ │ ├── aws-smithy-client v0.54.4
│ │ │ │ ├── aws-smithy-async v0.54.4 (*)
│ │ │ │ ├── aws-smithy-http v0.54.4 (*)
│ │ │ │ ├── aws-smithy-http-tower v0.54.4
│ │ │ │ │ ├── aws-smithy-http v0.54.4 (*)
│ │ │ │ │ ├── aws-smithy-types v0.54.4 (*)
│ │ │ │ ├── aws-smithy-protocol-test v0.54.4
│ │ │ │ ├── aws-smithy-types v0.54.4 (*)
│ │ │ ├── aws-smithy-http v0.54.4 (*)
│ │ │ ├── aws-smithy-types v0.54.4 (*)
│ ├── aws-sdk-sso v0.24.0
│ │ ├── aws-credential-types v0.54.1 (*)
│ │ ├── aws-endpoint v0.54.1
│ │ │ ├── aws-smithy-http v0.54.4 (*)
│ │ │ ├── aws-smithy-types v0.54.4 (*)
│ │ │ ├── aws-types v0.54.1 (*)
│ │ ├── aws-http v0.54.1 (*)
│ │ ├── aws-sig-auth v0.54.1
│ │ │ ├── aws-credential-types v0.54.1 (*)
│ │ │ ├── aws-sigv4 v0.54.1
│ │ │ │ ├── aws-smithy-eventstream v0.54.4 (*)
│ │ │ │ ├── aws-smithy-http v0.54.4 (*)
│ │ │ ├── aws-smithy-eventstream v0.54.4 (*)
│ │ │ ├── aws-smithy-http v0.54.4 (*)
│ │ │ ├── aws-types v0.54.1 (*)
│ │ ├── aws-smithy-async v0.54.4 (*)
│ │ ├── aws-smithy-client v0.54.4 (*)
│ │ ├── aws-smithy-http v0.54.4 (*)
│ │ ├── aws-smithy-http-tower v0.54.4 (*)
│ │ ├── aws-smithy-json v0.54.2
│ │ │ └── aws-smithy-types v0.54.4 (*)
│ │ ├── aws-smithy-types v0.54.4 (*)
│ │ ├── aws-types v0.54.1 (*)
│ ├── aws-sdk-sts v0.24.0
│ │ ├── aws-credential-types v0.54.1 (*)
│ │ ├── aws-endpoint v0.54.1 (*)
│ │ ├── aws-http v0.54.1 (*)
│ │ ├── aws-sig-auth v0.54.1 (*)
│ │ ├── aws-smithy-async v0.54.4 (*)
│ │ ├── aws-smithy-client v0.54.4 (*)
│ │ ├── aws-smithy-http v0.54.4 (*)
│ │ ├── aws-smithy-http-tower v0.54.4 (*)
│ │ ├── aws-smithy-json v0.54.2 (*)
│ │ ├── aws-smithy-query v0.54.2
│ │ │ ├── aws-smithy-types v0.54.4 (*)
│ │ ├── aws-smithy-types v0.54.4 (*)
│ │ ├── aws-smithy-xml v0.54.2
│ │ ├── aws-types v0.54.1 (*)
│ ├── aws-smithy-async v0.54.4 (*)
│ ├── aws-smithy-client v0.54.4 (*)
│ ├── aws-smithy-http v0.54.4 (*)
│ ├── aws-smithy-http-tower v0.54.4 (*)
│ ├── aws-smithy-json v0.54.2 (*)
│ ├── aws-smithy-types v0.54.4 (*)
│ ├── aws-types v0.54.1 (*)
├── aws-credential-types v0.54.1 (*)
├── aws-sdk-cloudwatch v0.24.0
│ ├── aws-credential-types v0.54.1 (*)
│ ├── aws-endpoint v0.54.1 (*)
│ ├── aws-http v0.54.1 (*)
│ ├── aws-sig-auth v0.54.1 (*)
│ ├── aws-smithy-async v0.54.4 (*)
│ ├── aws-smithy-client v0.54.4 (*)
│ ├── aws-smithy-http v0.54.4 (*)
│ ├── aws-smithy-http-tower v0.54.4 (*)
│ ├── aws-smithy-json v0.54.2 (*)
│ ├── aws-smithy-query v0.54.2 (*)
│ ├── aws-smithy-types v0.54.4 (*)
│ ├── aws-smithy-xml v0.54.2 (*)
│ ├── aws-types v0.54.1 (*)
├── aws-sdk-cloudwatchlogs v0.24.0
│ ├── aws-credential-types v0.54.1 (*)
│ ├── aws-endpoint v0.54.1 (*)
│ ├── aws-http v0.54.1 (*)
│ ├── aws-sig-auth v0.54.1 (*)
│ ├── aws-smithy-async v0.54.4 (*)
│ ├── aws-smithy-client v0.54.4 (*)
│ ├── aws-smithy-http v0.54.4 (*)
│ ├── aws-smithy-http-tower v0.54.4 (*)
│ ├── aws-smithy-json v0.54.2 (*)
│ ├── aws-smithy-types v0.54.4 (*)
│ ├── aws-types v0.54.1 (*)
├── aws-sdk-firehose v0.24.0
│ ├── aws-credential-types v0.54.1 (*)
│ ├── aws-endpoint v0.54.1 (*)
│ ├── aws-http v0.54.1 (*)
│ ├── aws-sig-auth v0.54.1 (*)
│ ├── aws-smithy-async v0.54.4 (*)
│ ├── aws-smithy-client v0.54.4 (*)
│ ├── aws-smithy-http v0.54.4 (*)
│ ├── aws-smithy-http-tower v0.54.4 (*)
│ ├── aws-smithy-json v0.54.2 (*)
│ ├── aws-smithy-types v0.54.4 (*)
│ ├── aws-types v0.54.1 (*)
├── aws-sdk-kinesis v0.24.0
│ ├── aws-credential-types v0.54.1 (*)
│ ├── aws-endpoint v0.54.1 (*)
│ ├── aws-http v0.54.1 (*)
│ ├── aws-sig-auth v0.54.1 (*)
│ ├── aws-smithy-async v0.54.4 (*)
│ ├── aws-smithy-client v0.54.4 (*)
│ ├── aws-smithy-http v0.54.4 (*)
│ ├── aws-smithy-http-tower v0.54.4 (*)
│ ├── aws-smithy-json v0.54.2 (*)
│ ├── aws-smithy-types v0.54.4 (*)
│ ├── aws-types v0.54.1 (*)
├── aws-sdk-s3 v0.24.0
│ ├── aws-credential-types v0.54.1 (*)
│ ├── aws-endpoint v0.54.1 (*)
│ ├── aws-http v0.54.1 (*)
│ ├── aws-sig-auth v0.54.1 (*)
│ ├── aws-sigv4 v0.54.1 (*)
│ ├── aws-smithy-async v0.54.4 (*)
│ ├── aws-smithy-checksums v0.54.2
│ │ ├── aws-smithy-http v0.54.4 (*)
│ │ ├── aws-smithy-types v0.54.4 (*)
│ ├── aws-smithy-client v0.54.4 (*)
│ ├── aws-smithy-eventstream v0.54.4 (*)
│ ├── aws-smithy-http v0.54.4 (*)
│ ├── aws-smithy-http-tower v0.54.4 (*)
│ ├── aws-smithy-json v0.54.2 (*)
│ ├── aws-smithy-types v0.54.4 (*)
│ ├── aws-smithy-xml v0.54.2 (*)
│ ├── aws-types v0.54.1 (*)
├── aws-sdk-sqs v0.24.0
│ ├── aws-credential-types v0.54.1 (*)
│ ├── aws-endpoint v0.54.1 (*)
│ ├── aws-http v0.54.1 (*)
│ ├── aws-sig-auth v0.54.1 (*)
│ ├── aws-smithy-async v0.54.4 (*)
│ ├── aws-smithy-client v0.54.4 (*)
│ ├── aws-smithy-http v0.54.4 (*)
│ ├── aws-smithy-http-tower v0.54.4 (*)
│ ├── aws-smithy-json v0.54.2 (*)
│ ├── aws-smithy-query v0.54.2 (*)
│ ├── aws-smithy-types v0.54.4 (*)
│ ├── aws-smithy-xml v0.54.2 (*)
│ ├── aws-types v0.54.1 (*)
├── aws-sigv4 v0.54.1 (*)
├── aws-smithy-async v0.54.4 (*)
├── aws-smithy-client v0.54.4 (*)
├── aws-smithy-http v0.54.4 (*)
├── aws-smithy-http-tower v0.54.4 (*)
├── aws-smithy-types v0.54.4 (*)
├── aws-types v0.54.1 (*)
Environment details (OS name and version, etc.)
Darwin COMP-J44M27KKWV 22.3.0 Darwin Kernel Version 22.3.0: Mon Jan 30 20:38:37 PST 2023; root:xnu-8792.81.3~2/RELEASE_ARM64_T6000 arm64 arm Darwin
Logs
2023-03-01T16:10:49.377040Z TRACE map_request{name="sigv4_sign_request"}: aws_sigv4::http_request::sign: signing request request=SignableRequest { method: POST, uri: https://logs.us-east-1.amazonaws.com/, headers: {"content-type": "application/x-amz-json-1.1", "x-amz-target": "Logs_20140328.DescribeLogGroups", "content-length": "61", "user-agent": "aws-sdk-rust/0.54.1 os/macos lang/rust/1.66.1", "x-amz-user-agent": "aws-sdk-rust/0.54.1 api/cloudwatchlogs/0.24.0 os/macos lang/rust/1.66.1"}, body: UnsignedPayload } params=SigningParams { access_key: "********", secret_key: "*******", security_token: None, region: "us-east-1", service_name: "logs", time: SystemTime { tv_sec: 1677687049, tv_nsec: 376983000 }, settings: SigningSettings { percent_encoding_mode: Double, payload_checksum_kind: NoHeader, signature_location: Headers, expires_in: None, excluded_headers: Some(["user-agent"]), uri_path_normalization_mode: Enabled } }
2023-03-01T16:10:49.377806Z TRACE map_request{name="sigv4_sign_request"}: aws_sigv4::http_request::sign: canonical_request=POST
/
content-length:61
content-type:application/x-amz-json-1.1
host:logs.us-east-1.amazonaws.com
x-amz-date:20230301T161049Z
x-amz-target:Logs_20140328.DescribeLogGroups
x-amz-user-agent:aws-sdk-rust/0.54.1 api/cloudwatchlogs/0.24.0 os/macos lang/rust/1.66.1
content-length;content-type;host;x-amz-date;x-amz-target;x-amz-user-agent
UNSIGNED-PAYLOAD
2023-03-01T16:10:49.378195Z TRACE dispatch: aws_smithy_http_tower::dispatch: dispatching request request=Request { method: POST, uri: https://logs.us-east-1.amazonaws.com/, version: HTTP/1.1, headers: {"content-type": "application/x-amz-json-1.1", "x-amz-target": "Logs_20140328.DescribeLogGroups", "content-length": "61", "user-agent": "aws-sdk-rust/0.54.1 os/macos lang/rust/1.66.1", "x-amz-user-agent": "aws-sdk-rust/0.54.1 api/cloudwatchlogs/0.24.0 os/macos lang/rust/1.66.1", "x-amz-date": "20230301T161049Z", "authorization": Sensitive}, body: SdkBody { inner: BoxBody, retryable: true } }
2023-03-01T16:10:49.440272Z TRACE load_response: aws_smithy_http::middleware: read HTTP response body http_response=Response { status: 400, version: HTTP/1.1, headers: {"x-amzn-requestid": "3dfbd4d5-ab57-4c08-9184-cee365f7466d", "content-type": "application/x-amz-json-1.1", "content-length": "229", "date": "Wed, 01 Mar 2023 16:10:48 GMT", "connection": "close"}, body: b"{\"__type\":\"InvalidSignatureException\",\"message\":\"The request signature we calculated does not match the signature you provided. Check your AWS Secret Access Key and signing method. Consult the service documentation for details.\"}" }
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Comments: 20 (11 by maintainers)
Commits related to this issue
- Bug fix for https://github.com/awslabs/aws-sdk-rust/issues/749 Pulled from https://github.com/awslabs/smithy-rs/pull/2567 — committed to vectordotdev/aws-sdk-rust by spencergilbert 3 years ago
- Merge remote-tracking branch 'upstream/main' into 0.56.x-#749-fix — committed to vectordotdev/aws-sdk-rust by fuchsnj 3 years ago
Fix verified:
clarification here given the
pending-releaselabel—we didn’t release runtime-library changes in the last release, just codegen. I’ll update this when it’s publishedoh great—we’ll merge that PR. cc @Velfi can you resurrect and merge? Looks like it needs a rebase but should otherwise apply cleanly.
I’m embarrassed to say I don’t even remember why I closed the PR. It might have just been housecleaning.
We’ve been working on a new implementation of the client that changes a lot of things and we may make breaking changes to the body. We’ve also got work on our calendar to change the way that chunked encoding happens so that we can support more use-cases and I expect that work to be a little related to the closed PR.
What was your original reason for defining a body callback? Progress reporting? I think we should start by figuring out what we want to be able to do and then considering if we should extend the old
SdkBodydesign or break it.Hey @spencergilbert, we’re PRing a change that should solve your issue.
The PR adds a new method to
SdkBodycalledmap_immutablewhich will preserve the inner body’s bytes, if it has some.Would you mind checking out the PR and letting me know what you think? I think you could even test it if you set your project to target this version of
aws-smithy-httpby a file path dependency (and maybe even with a Git dependency? I’m not sure about that though.)No, I fully understand what’s going on at this point
Just need to figure out the best solution for progress tracking which I think is a pretty common desire.
On Wed, Apr 5, 2023, 12:42 PM Spencer Gilbert @.***> wrote:
We’ll need to do something on the SDK side unfortunately
ah, I see. Yeah that’s tricky. If it’s any consolation, when
.bytes().is_some()more or less guarantees that it’s a small directly serialized request body (instead of a potentially large streaming request).Another thing we should consider is handling this on the signing side by attempting to clone() then read the body to the end during signing instead of just giving up.
A final option might be doing something like this to enable your dyn body to still provide a hint about bytes: https://github.com/awslabs/smithy-rs/compare/proto-bytes-hint?expand=1
And as an immediate workaround, I would check to see if
.bytes()returnsSomeon the body before you wrap it. If you only wrap bodies where.bytes()isNone, then you will only wrap streaming bodies (sidestepping this issue).