Skip to content

Commit

Permalink
Exempt presigned requests from default checksum
Browse files Browse the repository at this point in the history
  • Loading branch information
landonxjames committed Dec 11, 2024
1 parent 363b344 commit 3d61e10
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
9 changes: 9 additions & 0 deletions aws/rust-runtime/aws-inlineable/src/http_request_checksum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ use http_body::Body;
use std::str::FromStr;
use std::{fmt, mem};

use crate::presigning_interceptors::PresigningMarker;

/// Errors related to constructing checksum-validated HTTP requests
#[derive(Debug)]
pub(crate) enum Error {
Expand Down Expand Up @@ -202,6 +204,13 @@ where

// Calculate the checksum if necessary
if calculate_checksum {
let is_presigned_req = cfg.load::<PresigningMarker>().is_some();

// If this is a presigned request and the user has not set a checksum we short circuit
if is_presigned_req && checksum_algorithm.is_none() {
return Ok(());
}

// If a checksum override is set in the ConfigBag we use that instead (currently only used by S3Express)
// If we have made it this far without a checksum being set we set the default as Crc32
let checksum_algorithm = incorporate_custom_default(checksum_algorithm, cfg)
Expand Down
13 changes: 12 additions & 1 deletion aws/rust-runtime/aws-inlineable/src/presigning_interceptors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use aws_smithy_runtime_api::client::runtime_components::{
RuntimeComponents, RuntimeComponentsBuilder,
};
use aws_smithy_runtime_api::client::runtime_plugin::RuntimePlugin;
use aws_smithy_types::config_bag::{ConfigBag, FrozenLayer, Layer};
use aws_smithy_types::config_bag::{ConfigBag, FrozenLayer, Layer, Storable, StoreReplace};
use std::borrow::Cow;

/// Interceptor that tells the SigV4 signer to add the signature to query params,
Expand Down Expand Up @@ -63,6 +63,8 @@ impl Intercept for SigV4PresigningInterceptor {
.omit_default_content_length()
.omit_default_content_type(),
);

cfg.interceptor_state().store_put(PresigningMarker);
Ok(())
}

Expand Down Expand Up @@ -125,3 +127,12 @@ impl RuntimePlugin for SigV4PresigningRuntimePlugin {
Cow::Borrowed(&self.runtime_components)
}
}

/// A marker struct to be stored in the ConfigBag allowing other interceptors to know that
/// the current request is Presigned
#[derive(Debug)]
pub(crate) struct PresigningMarker;

impl Storable for PresigningMarker {
type Storer = StoreReplace<Self>;
}
2 changes: 1 addition & 1 deletion aws/rust-runtime/aws-sigv4/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aws-sigv4"
version = "1.2.6"
version = "1.2.7"
authors = ["AWS Rust SDK Team <[email protected]>", "David Barsky <[email protected]>"]
description = "SigV4 signer for HTTP requests and Event Stream messages."
edition = "2021"
Expand Down
2 changes: 1 addition & 1 deletion rust-runtime/aws-smithy-runtime/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aws-smithy-runtime"
version = "1.7.4"
version = "1.7.5"
authors = ["AWS Rust SDK Team <[email protected]>", "Zelda Hessler <[email protected]>"]
description = "The new smithy runtime crate"
edition = "2021"
Expand Down

0 comments on commit 3d61e10

Please sign in to comment.