Skip to content

Commit 2284425

Browse files
Merge branch 'main' into RFC30/tests
2 parents b0c4133 + 6532a2b commit 2284425

File tree

173 files changed

+10492
-3239
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+10492
-3239
lines changed

CHANGELOG.next.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111
# meta = { "breaking" = false, "tada" = false, "bug" = false, "target" = "client | server | all"}
1212
# author = "rcoh"
1313

14+
[[aws-sdk-rust]]
15+
message = "Automatically exclude X-Ray trace ID headers and authorization headers from SigV4 canonical request calculations."
16+
references = ["smithy-rs#2815"]
17+
meta = { "breaking" = false, "tada" = false, "bug" = true }
18+
author = "relevantsam"
19+
1420
[[aws-sdk-rust]]
1521
message = "Add accessors to Builders"
1622
references = ["smithy-rs#2791"]

aws/rust-runtime/aws-config/src/default_provider/credentials.rs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -250,11 +250,14 @@ mod test {
250250
.await
251251
.unwrap()
252252
.with_provider_config($provider_config_builder)
253-
.$func(|conf| async {
254-
crate::default_provider::credentials::Builder::default()
255-
.configure(conf)
256-
.build()
257-
.await
253+
.$func(|conf| {
254+
let conf = conf.clone();
255+
async move {
256+
crate::default_provider::credentials::Builder::default()
257+
.configure(conf)
258+
.build()
259+
.await
260+
}
258261
})
259262
.await
260263
}

aws/rust-runtime/aws-config/src/lib.rs

Lines changed: 71 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,17 @@ mod loader {
171171
use crate::profile::profile_file::ProfileFiles;
172172
use crate::provider_config::ProviderConfig;
173173

174+
#[derive(Default, Debug)]
175+
enum CredentialsProviderOption {
176+
/// No provider was set by the user. We can set up the default credentials provider chain.
177+
#[default]
178+
NotSet,
179+
/// The credentials provider was explicitly unset. Do not set up a default chain.
180+
ExplicitlyUnset,
181+
/// Use the given credentials provider.
182+
Set(SharedCredentialsProvider),
183+
}
184+
174185
/// Load a cross-service [`SdkConfig`](aws_types::SdkConfig) from the environment
175186
///
176187
/// This builder supports overriding individual components of the generated config. Overriding a component
@@ -181,7 +192,7 @@ mod loader {
181192
pub struct ConfigLoader {
182193
app_name: Option<AppName>,
183194
credentials_cache: Option<CredentialsCache>,
184-
credentials_provider: Option<SharedCredentialsProvider>,
195+
credentials_provider: CredentialsProviderOption,
185196
endpoint_url: Option<String>,
186197
region: Option<Box<dyn ProvideRegion>>,
187198
retry_config: Option<RetryConfig>,
@@ -348,7 +359,33 @@ mod loader {
348359
mut self,
349360
credentials_provider: impl ProvideCredentials + 'static,
350361
) -> Self {
351-
self.credentials_provider = Some(SharedCredentialsProvider::new(credentials_provider));
362+
self.credentials_provider = CredentialsProviderOption::Set(
363+
SharedCredentialsProvider::new(credentials_provider),
364+
);
365+
self
366+
}
367+
368+
// TODO(enableNewSmithyRuntimeLaunch): Remove the doc hidden from this function
369+
#[doc(hidden)]
370+
/// Don't use credentials to sign requests.
371+
///
372+
/// Turning off signing with credentials is necessary in some cases, such as using
373+
/// anonymous auth for S3, calling operations in STS that don't require a signature,
374+
/// or using token-based auth.
375+
///
376+
/// # Examples
377+
///
378+
/// Turn off credentials in order to call a service without signing:
379+
/// ```no_run
380+
/// # async fn create_config() {
381+
/// let config = aws_config::from_env()
382+
/// .no_credentials()
383+
/// .load()
384+
/// .await;
385+
/// # }
386+
/// ```
387+
pub fn no_credentials(mut self) -> Self {
388+
self.credentials_provider = CredentialsProviderOption::ExplicitlyUnset;
352389
self
353390
}
354391

@@ -570,13 +607,28 @@ mod loader {
570607
.http_connector
571608
.unwrap_or_else(|| HttpConnector::ConnectorFn(Arc::new(default_connector)));
572609

573-
let credentials_cache = self.credentials_cache.unwrap_or_else(|| {
574-
let mut builder = CredentialsCache::lazy_builder().time_source(
575-
aws_credential_types::time_source::TimeSource::shared(conf.time_source()),
576-
);
577-
builder.set_sleep(conf.sleep());
578-
builder.into_credentials_cache()
579-
});
610+
let credentials_provider = match self.credentials_provider {
611+
CredentialsProviderOption::Set(provider) => Some(provider),
612+
CredentialsProviderOption::NotSet => {
613+
let mut builder =
614+
credentials::DefaultCredentialsChain::builder().configure(conf.clone());
615+
builder.set_region(region.clone());
616+
Some(SharedCredentialsProvider::new(builder.build().await))
617+
}
618+
CredentialsProviderOption::ExplicitlyUnset => None,
619+
};
620+
621+
let credentials_cache = if credentials_provider.is_some() {
622+
Some(self.credentials_cache.unwrap_or_else(|| {
623+
let mut builder = CredentialsCache::lazy_builder().time_source(
624+
aws_credential_types::time_source::TimeSource::shared(conf.time_source()),
625+
);
626+
builder.set_sleep(conf.sleep());
627+
builder.into_credentials_cache()
628+
}))
629+
} else {
630+
None
631+
};
580632

581633
let use_fips = if let Some(use_fips) = self.use_fips {
582634
Some(use_fips)
@@ -590,26 +642,18 @@ mod loader {
590642
use_dual_stack_provider(&conf).await
591643
};
592644

593-
let credentials_provider = if let Some(provider) = self.credentials_provider {
594-
provider
595-
} else {
596-
let mut builder = credentials::DefaultCredentialsChain::builder().configure(conf);
597-
builder.set_region(region.clone());
598-
SharedCredentialsProvider::new(builder.build().await)
599-
};
600-
601645
let ts = self.time_source.unwrap_or_default();
602646

603647
let mut builder = SdkConfig::builder()
604648
.region(region)
605649
.retry_config(retry_config)
606650
.timeout_config(timeout_config)
607-
.credentials_cache(credentials_cache)
608-
.credentials_provider(credentials_provider)
609651
.time_source(ts)
610652
.http_connector(http_connector);
611653

612654
builder.set_app_name(app_name);
655+
builder.set_credentials_cache(credentials_cache);
656+
builder.set_credentials_provider(credentials_provider);
613657
builder.set_sleep_impl(sleep_impl);
614658
builder.set_endpoint_url(self.endpoint_url);
615659
builder.set_use_fips(use_fips);
@@ -719,5 +763,13 @@ mod loader {
719763
let conf = base_conf().app_name(app_name.clone()).load().await;
720764
assert_eq!(Some(&app_name), conf.app_name());
721765
}
766+
767+
#[cfg(aws_sdk_orchestrator_mode)]
768+
#[tokio::test]
769+
async fn disable_default_credentials() {
770+
let config = from_env().no_credentials().load().await;
771+
assert!(config.credentials_cache().is_none());
772+
assert!(config.credentials_provider().is_none());
773+
}
722774
}
723775
}

aws/rust-runtime/aws-config/src/sts.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ pub use assume_role::{AssumeRoleProvider, AssumeRoleProviderBuilder};
1212
mod assume_role;
1313

1414
use crate::connector::expect_connector;
15-
use aws_credential_types::cache::CredentialsCache;
1615
use aws_sdk_sts::config::Builder as StsConfigBuilder;
1716
use aws_smithy_types::retry::RetryConfig;
1817

@@ -22,8 +21,7 @@ impl crate::provider_config::ProviderConfig {
2221
.http_connector(expect_connector(self.connector(&Default::default())))
2322
.retry_config(RetryConfig::standard())
2423
.region(self.region())
25-
.time_source(self.time_source())
26-
.credentials_cache(CredentialsCache::no_caching());
24+
.time_source(self.time_source());
2725
builder.set_sleep_impl(self.sleep());
2826
builder
2927
}

aws/rust-runtime/aws-http/src/user_agent.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
use aws_smithy_http::middleware::MapRequest;
77
use aws_smithy_http::operation::Request;
8+
use aws_smithy_types::config_bag::{Storable, StoreReplace};
89
use aws_types::app_name::AppName;
910
use aws_types::build_metadata::{OsFamily, BUILD_METADATA};
1011
use aws_types::os_shim_internal::Env;
@@ -211,6 +212,10 @@ impl AwsUserAgent {
211212
}
212213
}
213214

215+
impl Storable for AwsUserAgent {
216+
type Storer = StoreReplace<Self>;
217+
}
218+
214219
#[derive(Clone, Copy, Debug)]
215220
struct SdkMetadata {
216221
name: &'static str,
@@ -246,6 +251,10 @@ impl fmt::Display for ApiMetadata {
246251
}
247252
}
248253

254+
impl Storable for ApiMetadata {
255+
type Storer = StoreReplace<Self>;
256+
}
257+
249258
/// Error for when an user agent metadata doesn't meet character requirements.
250259
///
251260
/// Metadata may only have alphanumeric characters and any of these characters:

aws/rust-runtime/aws-inlineable/src/apigateway_interceptors.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55

66
#![allow(dead_code)]
77

8-
use aws_smithy_runtime_api::client::interceptors::{
9-
BeforeTransmitInterceptorContextMut, BoxError, Interceptor,
10-
};
8+
use aws_smithy_runtime_api::box_error::BoxError;
9+
use aws_smithy_runtime_api::client::interceptors::context::BeforeTransmitInterceptorContextMut;
10+
use aws_smithy_runtime_api::client::interceptors::Interceptor;
1111
use aws_smithy_types::config_bag::ConfigBag;
1212
use http::header::ACCEPT;
1313
use http::HeaderValue;

aws/rust-runtime/aws-inlineable/src/glacier_interceptors.rs

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ use aws_runtime::auth::sigv4::SigV4OperationSigningConfig;
1010
use aws_sigv4::http_request::SignableBody;
1111
use aws_smithy_http::body::SdkBody;
1212
use aws_smithy_http::byte_stream;
13-
use aws_smithy_runtime_api::client::interceptors::{
14-
BeforeSerializationInterceptorContextMut, BeforeTransmitInterceptorContextMut, BoxError,
15-
Interceptor,
13+
use aws_smithy_runtime_api::box_error::BoxError;
14+
use aws_smithy_runtime_api::client::config_bag_accessors::ConfigBagAccessors;
15+
use aws_smithy_runtime_api::client::interceptors::context::{
16+
BeforeSerializationInterceptorContextMut, BeforeTransmitInterceptorContextMut,
1617
};
17-
use aws_smithy_runtime_api::client::orchestrator::{ConfigBagAccessors, LoadedRequestBody};
18+
use aws_smithy_runtime_api::client::interceptors::Interceptor;
19+
use aws_smithy_runtime_api::client::orchestrator::LoadedRequestBody;
1820
use aws_smithy_types::config_bag::ConfigBag;
1921
use bytes::Bytes;
2022
use http::header::{HeaderName, HeaderValue};
@@ -129,18 +131,18 @@ impl Interceptor for GlacierTreeHashHeaderInterceptor {
129131
context: &mut BeforeTransmitInterceptorContextMut<'_>,
130132
cfg: &mut ConfigBag,
131133
) -> Result<(), BoxError> {
132-
let maybe_loaded_body = cfg.get::<LoadedRequestBody>();
134+
let maybe_loaded_body = cfg.load::<LoadedRequestBody>();
133135
if let Some(LoadedRequestBody::Loaded(body)) = maybe_loaded_body {
134136
let content_sha256 = add_checksum_treehash(context.request_mut(), body)?;
135137

136138
// Override the signing payload with this precomputed hash
137139
let mut signing_config = cfg
138-
.get::<SigV4OperationSigningConfig>()
140+
.load::<SigV4OperationSigningConfig>()
139141
.ok_or("SigV4OperationSigningConfig not found")?
140142
.clone();
141143
signing_config.signing_options.payload_override =
142144
Some(SignableBody::Precomputed(content_sha256));
143-
cfg.interceptor_state().put(signing_config);
145+
cfg.interceptor_state().store_put(signing_config);
144146
} else {
145147
return Err(
146148
"the request body wasn't loaded into memory before the retry loop, \
@@ -234,7 +236,7 @@ fn compute_hash_tree(mut hashes: Vec<Digest>) -> Digest {
234236
#[cfg(test)]
235237
mod account_id_autofill_tests {
236238
use super::*;
237-
use aws_smithy_runtime_api::client::interceptors::InterceptorContext;
239+
use aws_smithy_runtime_api::client::interceptors::context::InterceptorContext;
238240
use aws_smithy_types::type_erasure::TypedBox;
239241

240242
#[test]
@@ -273,7 +275,7 @@ mod account_id_autofill_tests {
273275
#[cfg(test)]
274276
mod api_version_tests {
275277
use super::*;
276-
use aws_smithy_runtime_api::client::interceptors::InterceptorContext;
278+
use aws_smithy_runtime_api::client::interceptors::context::InterceptorContext;
277279
use aws_smithy_types::type_erasure::TypedBox;
278280

279281
#[test]

aws/rust-runtime/aws-inlineable/src/http_request_checksum.rs

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ use aws_smithy_checksums::ChecksumAlgorithm;
1414
use aws_smithy_checksums::{body::calculate, http::HttpChecksum};
1515
use aws_smithy_http::body::{BoxBody, SdkBody};
1616
use aws_smithy_http::operation::error::BuildError;
17-
use aws_smithy_runtime_api::client::interceptors::context::Input;
18-
use aws_smithy_runtime_api::client::interceptors::{
19-
BeforeSerializationInterceptorContextRef, BeforeTransmitInterceptorContextMut, BoxError,
20-
Interceptor,
17+
use aws_smithy_runtime_api::box_error::BoxError;
18+
use aws_smithy_runtime_api::client::interceptors::context::{
19+
BeforeSerializationInterceptorContextRef, BeforeTransmitInterceptorContextMut, Input,
2120
};
21+
use aws_smithy_runtime_api::client::interceptors::Interceptor;
2222
use aws_smithy_types::config_bag::{ConfigBag, Layer, Storable, StoreReplace};
2323
use http::HeaderValue;
2424
use http_body::Body;
@@ -132,13 +132,10 @@ fn add_checksum_for_request_body(
132132
// Body is streaming: wrap the body so it will emit a checksum as a trailer.
133133
None => {
134134
tracing::debug!("applying {checksum_algorithm:?} of the request body as a trailer");
135-
if let Some(mut signing_config) = cfg.get::<SigV4OperationSigningConfig>().cloned() {
135+
if let Some(mut signing_config) = cfg.load::<SigV4OperationSigningConfig>().cloned() {
136136
signing_config.signing_options.payload_override =
137137
Some(SignableBody::StreamingUnsignedPayloadTrailer);
138-
139-
let mut layer = Layer::new("http_body_checksum_sigv4_payload_override");
140-
layer.put(signing_config);
141-
cfg.push_layer(layer);
138+
cfg.interceptor_state().store_put(signing_config);
142139
}
143140
wrap_streaming_request_body_in_checksum_calculating_body(request, checksum_algorithm)?;
144141
}

aws/rust-runtime/aws-inlineable/src/http_response_checksum.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
1010
use aws_smithy_checksums::ChecksumAlgorithm;
1111
use aws_smithy_http::body::{BoxBody, SdkBody};
12-
use aws_smithy_runtime_api::client::interceptors::context::Input;
13-
use aws_smithy_runtime_api::client::interceptors::{
14-
BeforeDeserializationInterceptorContextMut, BeforeSerializationInterceptorContextRef, BoxError,
15-
Interceptor,
12+
use aws_smithy_runtime_api::box_error::BoxError;
13+
use aws_smithy_runtime_api::client::interceptors::context::{
14+
BeforeDeserializationInterceptorContextMut, BeforeSerializationInterceptorContextRef, Input,
1615
};
16+
use aws_smithy_runtime_api::client::interceptors::Interceptor;
1717
use aws_smithy_types::config_bag::{ConfigBag, Layer, Storable, StoreReplace};
1818
use http::HeaderValue;
1919
use std::{fmt, mem};

0 commit comments

Comments
 (0)