Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix default credential chain not respecting endpoint URL overrides #3873

Merged
merged 8 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .changelog/1728582276.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
applies_to:
- aws-sdk-rust
authors:
- aajtodd
references:
- aws-sdk-rust#1193
breaking: false
new_feature: false
bug_fix: true
---
Fix default credential provider chain not respecting endpoint URL overrides from environment
47 changes: 17 additions & 30 deletions aws/rust-runtime/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions aws/rust-runtime/aws-config/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion aws/rust-runtime/aws-config/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "aws-config"
version = "1.5.8"
version = "1.5.9"
authors = [
"AWS Rust SDK Team <aws-sdk-rust@amazon.com>",
"Russell Cohen <rcoh@amazon.com>",
Expand Down
16 changes: 12 additions & 4 deletions aws/rust-runtime/aws-config/src/profile/credentials.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ use aws_credential_types::{
Credentials,
};
use aws_smithy_types::error::display::DisplayErrorContext;
use aws_types::SdkConfig;
use std::borrow::Cow;
use std::collections::HashMap;
use std::error::Error;
Expand Down Expand Up @@ -142,7 +141,6 @@ pub struct ProfileFileCredentialsProvider {
#[derive(Debug)]
struct Config {
factory: exec::named::NamedProviderFactory,
sdk_config: SdkConfig,
provider_config: ProviderConfig,
}

Expand Down Expand Up @@ -493,7 +491,6 @@ impl Builder {
ProfileFileCredentialsProvider {
config: Arc::new(Config {
factory,
sdk_config: conf.client_config(),
provider_config: conf,
}),
inner_provider: ErrorTakingOnceCell::new(),
Expand Down Expand Up @@ -542,9 +539,13 @@ impl ChainProvider {
return Err(CredentialsError::provider_error(e));
}
};

// we want to create `SdkConfig` _after_ we have resolved the profile or else
// we won't get things like `service_config()` set appropriately.
let sdk_config = config.provider_config.client_config();
for provider in chain.chain().iter() {
let next_creds = provider
.credentials(creds, &config.sdk_config)
.credentials(creds, &sdk_config)
.instrument(tracing::debug_span!("load_assume_role", provider = ?provider))
.await;
match next_creds {
Expand Down Expand Up @@ -609,7 +610,14 @@ mod test {
#[cfg(feature = "sso")]
make_test!(sso_credentials);
#[cfg(feature = "sso")]
make_test!(sso_override_global_env_url);
#[cfg(feature = "sso")]
make_test!(sso_token);

make_test!(assume_role_override_global_env_url);
make_test!(assume_role_override_service_env_url);
make_test!(assume_role_override_global_profile_url);
make_test!(assume_role_override_service_profile_url);
}

#[cfg(all(test, feature = "sso"))]
Expand Down
14 changes: 14 additions & 0 deletions aws/rust-runtime/aws-config/src/provider_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

//! Configuration Options for Credential Providers

use crate::env_service_config::EnvServiceConfig;
use crate::profile;
#[allow(deprecated)]
use crate::profile::profile_file::ProfileFiles;
Expand Down Expand Up @@ -196,13 +197,26 @@ impl ProviderConfig {
Self::without_region().load_default_region().await
}

/// Attempt to get a representation of `SdkConfig` from this `ProviderConfig`.
///
///
/// **WARN**: Some options (e.g. `service_config`) can only be set if the profile has been
/// parsed already (e.g. by calling [`ProviderConfig::profile()`]). This is an
/// imperfect mapping and should be used sparingly.
pub(crate) fn client_config(&self) -> SdkConfig {
let profiles = self.parsed_profile.get().map(|v| v.as_ref().ok()).flatten();
let service_config = EnvServiceConfig {
env: self.env(),
env_config_sections: profiles.cloned().unwrap_or_default(),
};

let mut builder = SdkConfig::builder()
.retry_config(RetryConfig::standard())
.region(self.region())
.time_source(self.time_source())
.use_fips(self.use_fips().unwrap_or_default())
.use_dual_stack(self.use_dual_stack().unwrap_or_default())
.service_config(service_config)
.behavior_version(crate::BehaviorVersion::latest());
builder.set_http_client(self.http_client.clone());
builder.set_sleep_impl(self.sleep_impl.clone());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"HOME": "/home",
"AWS_ENDPOINT_URL": "http://aws.global-env-override"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[default]
region = us-east-1
role_arn = arn:aws:iam::123456789:role/integration-test
source_profile = base

[profile base]
region = us-east-1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[base]
aws_access_key_id = AKIAFAKE
aws_secret_access_key = FAKE
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{
"events": [
{
"connection_id": 0,
"action": {
"Request": {
"request": {
"uri": "http://aws.global-env-override",
"headers": {
"content-type": [
"application/x-www-form-urlencoded"
],
"authorization": [
"AWS4-HMAC-SHA256 Credential=AKIAFAKE/20210810/us-east-1/sts/aws4_request, SignedHeaders=content-length;content-type;host;x-amz-date;x-amz-user-agent, Signature=cd5cb2aa1d20717ca17692bcbda711797ae9eb8bb1130690b021b3952b7ae56e"
],
"user-agent": [
"aws-sdk-rust/0.1.0 os/macos lang/rust/1.55.0-nightly"
],
"content-length": [
"146"
],
"x-amz-date": [
"20210810T003833Z"
],
"host": [
"aws.global-env-override"
],
"x-amz-user-agent": [
"aws-sdk-rust/0.1.0 api/sts/0.0.14-alpha os/macos lang/rust/1.55.0-nightly"
]
},
"method": "POST"
}
}
}
},
{
"connection_id": 0,
"action": {
"Data": {
"data": {
"Utf8": "Action=AssumeRole&Version=2011-06-15&RoleArn=arn%3Aaws%3Aiam%3A%3A123456789%3Arole%2Fintegration-test&RoleSessionName=assume-role-provider-session"
},
"direction": "Request"
}
}
},
{
"connection_id": 0,
"action": {
"Eof": {
"ok": true,
"direction": "Request"
}
}
},
{
"connection_id": 0,
"action": {
"Response": {
"response": {
"Ok": {
"status": 200,
"version": "HTTP/1.1",
"headers": {
"date": [
"Thu, 05 Aug 2021 18:58:02 GMT"
],
"content-length": [
"1491"
],
"content-type": [
"text/xml"
],
"x-amzn-requestid": [
"c2e971c2-702d-4124-9b1f-1670febbea18"
]
}
}
}
}
}
},
{
"connection_id": 0,
"action": {
"Data": {
"data": {
"Utf8": "<AssumeRoleResponse xmlns=\"https://sts.amazonaws.com/doc/2011-06-15/\">\n <AssumeRoleResult>\n <AssumedRoleUser>\n <AssumedRoleId>AROARABCDEFGHIJKLMNOP:assume-role-provider-session</AssumedRoleId>\n <Arn>arn:aws:sts::123456789012:assumed-role/integration-test/assume-role-provider-session</Arn>\n </AssumedRoleUser>\n <Credentials>\n <AccessKeyId>ASIARTESTID</AccessKeyId>\n <SecretAccessKey>TESTSECRETKEY</SecretAccessKey>\n <SessionToken>TESTSESSIONTOKEN</SessionToken>\n <Expiration>2021-08-05T19:58:02Z</Expiration>\n </Credentials>\n </AssumeRoleResult>\n <ResponseMetadata>\n <RequestId>c2e971c2-702d-4124-9b1f-1670febbea18</RequestId>\n </ResponseMetadata>\n</AssumeRoleResponse>\n"
},
"direction": "Response"
}
}
},
{
"connection_id": 0,
"action": {
"Eof": {
"ok": true,
"direction": "Response"
}
}
}
],
"docs": "standard request / response with STS",
"version": "V0"
}
Loading
Loading