From 9d4d89c55161c65288bd36b5db65ae816bc0306c Mon Sep 17 00:00:00 2001 From: Landon James Date: Tue, 10 Dec 2024 20:16:54 -0800 Subject: [PATCH] Exempt presigned requests from default checksum Update HttpChecksumTest to have presigning types --- .../aws-inlineable/src/http_request_checksum.rs | 9 +++++++++ aws/rust-runtime/aws-inlineable/src/presigning.rs | 10 ++++++++++ .../aws-inlineable/src/presigning_interceptors.rs | 4 +++- aws/rust-runtime/aws-sigv4/Cargo.toml | 2 +- .../software/amazon/smithy/rustsdk/HttpChecksumTest.kt | 2 ++ rust-runtime/aws-smithy-runtime/Cargo.toml | 2 +- 6 files changed, 26 insertions(+), 3 deletions(-) diff --git a/aws/rust-runtime/aws-inlineable/src/http_request_checksum.rs b/aws/rust-runtime/aws-inlineable/src/http_request_checksum.rs index e0390dbb10..26be0b380b 100644 --- a/aws/rust-runtime/aws-inlineable/src/http_request_checksum.rs +++ b/aws/rust-runtime/aws-inlineable/src/http_request_checksum.rs @@ -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 { @@ -202,6 +204,13 @@ where // Calculate the checksum if necessary if calculate_checksum { + let is_presigned_req = cfg.load::().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) diff --git a/aws/rust-runtime/aws-inlineable/src/presigning.rs b/aws/rust-runtime/aws-inlineable/src/presigning.rs index c19d160e18..c308307685 100644 --- a/aws/rust-runtime/aws-inlineable/src/presigning.rs +++ b/aws/rust-runtime/aws-inlineable/src/presigning.rs @@ -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}; @@ -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; +} diff --git a/aws/rust-runtime/aws-inlineable/src/presigning_interceptors.rs b/aws/rust-runtime/aws-inlineable/src/presigning_interceptors.rs index 481a8d9cab..25c674feb2 100644 --- a/aws/rust-runtime/aws-inlineable/src/presigning_interceptors.rs +++ b/aws/rust-runtime/aws-inlineable/src/presigning_interceptors.rs @@ -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; @@ -63,6 +63,8 @@ impl Intercept for SigV4PresigningInterceptor { .omit_default_content_length() .omit_default_content_type(), ); + + cfg.interceptor_state().store_put(PresigningMarker); Ok(()) } diff --git a/aws/rust-runtime/aws-sigv4/Cargo.toml b/aws/rust-runtime/aws-sigv4/Cargo.toml index cc80e15908..82874377cc 100644 --- a/aws/rust-runtime/aws-sigv4/Cargo.toml +++ b/aws/rust-runtime/aws-sigv4/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aws-sigv4" -version = "1.2.6" +version = "1.2.7" authors = ["AWS Rust SDK Team ", "David Barsky "] description = "SigV4 signer for HTTP requests and Event Stream messages." edition = "2021" diff --git a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/HttpChecksumTest.kt b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/HttpChecksumTest.kt index 928612055c..2634618c14 100644 --- a/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/HttpChecksumTest.kt +++ b/aws/sdk-codegen/src/test/kotlin/software/amazon/smithy/rustsdk/HttpChecksumTest.kt @@ -180,6 +180,7 @@ internal class HttpChecksumTest { use #{HttpRequest}; use #{UaAssert}; use #{UaExtract}; + //#{PresigningMarker}; """, *preludeScope, "Blob" to RuntimeType.smithyTypes(rc).resolve("Blob"), @@ -193,6 +194,7 @@ internal class HttpChecksumTest { "UaExtract" to AwsRuntimeType.awsRuntime(rc) .resolve("user_agent::test_util::extract_ua_values"), + "PresigningMarker" to AwsRuntimeType.presigning().resolve("PresigningMarker"), ) } diff --git a/rust-runtime/aws-smithy-runtime/Cargo.toml b/rust-runtime/aws-smithy-runtime/Cargo.toml index d25e3c3929..29a6d2fa2c 100644 --- a/rust-runtime/aws-smithy-runtime/Cargo.toml +++ b/rust-runtime/aws-smithy-runtime/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "aws-smithy-runtime" -version = "1.7.4" +version = "1.7.5" authors = ["AWS Rust SDK Team ", "Zelda Hessler "] description = "The new smithy runtime crate" edition = "2021"