Skip to content

Commit 1f9c608

Browse files
authored
Fix EcsCredentialsProvider to respect query params (#3977)
## Motivation and Context awslabs/aws-sdk-rust#1248, and implemented the fix as prescribed. ## Testing Added a request matching unit test to the `ecs` module to ensure that query params are included in credential's HTTP request. ## Checklist - [x] For changes to the AWS SDK, generated SDK code, or SDK runtime crates, I have created a changelog entry Markdown file in the `.changelog` directory, specifying "aws-sdk-rust" in the `applies_to` key. ---- _By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice._
1 parent e41f7d7 commit 1f9c608

File tree

3 files changed

+54
-3
lines changed

3 files changed

+54
-3
lines changed

.changelog/1737491439.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
---
2+
applies_to:
3+
- aws-sdk-rust
4+
authors:
5+
- ysaito1001
6+
references:
7+
- aws-sdk-rust#1248
8+
breaking: false
9+
new_feature: false
10+
bug_fix: true
11+
---
12+
Fix `EcsCredentialsProvider` to include query params passed via `AWS_CONTAINER_CREDENTIALS_RELATIVE_URI`.

aws/rust-runtime/aws-config/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "aws-config"
3-
version = "1.5.14"
3+
version = "1.5.15"
44
authors = [
55
"AWS Rust SDK Team <aws-sdk-rust@amazon.com>",
66
"Russell Cohen <rcoh@amazon.com>",

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

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,10 @@ impl Provider {
191191
Err(EcsConfigurationError::NotConfigured) => return Provider::NotConfigured,
192192
Err(err) => return Provider::InvalidConfiguration(err),
193193
};
194-
let path = uri.path().to_string();
194+
let path_and_query = match uri.path_and_query() {
195+
Some(path_and_query) => path_and_query.to_string(),
196+
None => uri.path().to_string(),
197+
};
195198
let endpoint = {
196199
let mut parts = uri.into_parts();
197200
parts.path_and_query = Some(PathAndQuery::from_static("/"));
@@ -208,7 +211,7 @@ impl Provider {
208211
.read_timeout(DEFAULT_READ_TIMEOUT)
209212
.build(),
210213
)
211-
.build("EcsContainer", &endpoint, path);
214+
.build("EcsContainer", &endpoint, path_and_query);
212215
Provider::Configured(http_provider)
213216
}
214217

@@ -828,6 +831,42 @@ mod test {
828831
http_client.assert_requests_match(&[]);
829832
}
830833

834+
#[tokio::test]
835+
async fn query_params_should_be_included_in_credentials_http_request() {
836+
let env = Env::from_slice(&[
837+
(
838+
"AWS_CONTAINER_CREDENTIALS_RELATIVE_URI",
839+
"/my-credentials/?applicationName=test2024",
840+
),
841+
(
842+
"AWS_CONTAINER_AUTHORIZATION_TOKEN_FILE",
843+
"/var/run/secrets/pods.eks.amazonaws.com/serviceaccount/eks-pod-identity-token",
844+
),
845+
("AWS_CONTAINER_AUTHORIZATION_TOKEN", "unused"),
846+
]);
847+
let fs = Fs::from_raw_map(HashMap::from([(
848+
OsString::from(
849+
"/var/run/secrets/pods.eks.amazonaws.com/serviceaccount/eks-pod-identity-token",
850+
),
851+
"Basic password".into(),
852+
)]));
853+
854+
let http_client = StaticReplayClient::new(vec![ReplayEvent::new(
855+
creds_request(
856+
"http://169.254.170.2/my-credentials/?applicationName=test2024",
857+
Some("Basic password"),
858+
),
859+
ok_creds_response(),
860+
)]);
861+
let provider = provider(env, fs, http_client.clone());
862+
let creds = provider
863+
.provide_credentials()
864+
.await
865+
.expect("valid credentials");
866+
assert_correct(creds);
867+
http_client.assert_requests_match(&[]);
868+
}
869+
831870
#[tokio::test]
832871
async fn fs_missing_file() {
833872
let env = Env::from_slice(&[

0 commit comments

Comments
 (0)