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 7fdf1e3
Show file tree
Hide file tree
Showing 5 changed files with 24 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::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
10 changes: 10 additions & 0 deletions aws/rust-runtime/aws-inlineable/src/presigning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use aws_smithy_runtime_api::box_error::BoxError;
use aws_smithy_runtime_api::client::orchestrator::HttpRequest;
use aws_smithy_types::body::SdkBody;
use aws_smithy_types::config_bag::{Storable, StoreReplace};
use std::fmt;
use std::time::{Duration, SystemTime};

Expand Down Expand Up @@ -265,3 +266,12 @@ impl fmt::Debug for PresignedRequest {
.finish()
}
}

/// 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>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

#![allow(dead_code)]

use crate::presigning::PresigningConfig;
use crate::presigning::{PresigningConfig, PresigningMarker};
use crate::serialization_settings::HeaderSerializationSettings;
use aws_runtime::auth::{HttpSignatureType, SigV4OperationSigningConfig};
use aws_runtime::invocation_id::InvocationIdInterceptor;
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
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 <aws-sdk-rust@amazon.com>", "David Barsky <me@davidbarsky.com>"]
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 <aws-sdk-rust@amazon.com>", "Zelda Hessler <zhessler@amazon.com>"]
description = "The new smithy runtime crate"
edition = "2021"
Expand Down

0 comments on commit 7fdf1e3

Please sign in to comment.