Skip to content

Commit

Permalink
enhancement(aws provider): Let region be configured for default aut…
Browse files Browse the repository at this point in the history
…hentication (vectordotdev#17414)

* enhancement(aws provider): Let `region` be configured for default authentication

Fixes: vectordotdev#17406

Signed-off-by: Jesse Szwedko <jesse.szwedko@datadoghq.com>

* Add some more defaults

Signed-off-by: Jesse Szwedko <jesse.szwedko@datadoghq.com>

* clippy

Signed-off-by: Jesse Szwedko <jesse.szwedko@datadoghq.com>

---------

Signed-off-by: Jesse Szwedko <jesse.szwedko@datadoghq.com>
  • Loading branch information
jszwedko authored May 17, 2023
1 parent 58603b9 commit c81ad30
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/aws/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,15 @@ pub enum AwsAuthentication {
/// Configuration for authenticating with AWS through IMDS.
#[serde(default)]
imds: ImdsAuthentication,

/// The [AWS region][aws_region] to send STS requests to.
///
/// If not set, this defaults to the configured region
/// for the service itself.
///
/// [aws_region]: https://docs.aws.amazon.com/general/latest/gr/rande.html#regional-endpoints
#[configurable(metadata(docs::examples = "us-west-2"))]
region: Option<String>,
},
}

Expand Down Expand Up @@ -213,8 +222,14 @@ impl AwsAuthentication {
AwsAuthentication::Default {
load_timeout_secs,
imds,
region,
} => Ok(SharedCredentialsProvider::new(
default_credentials_provider(service_region, *load_timeout_secs, *imds).await?,
default_credentials_provider(
region.clone().map(Region::new).unwrap_or(service_region),
*load_timeout_secs,
*imds,
)
.await?,
)),
}
}
Expand Down Expand Up @@ -294,10 +309,28 @@ mod tests {
AwsAuthentication::Default {
load_timeout_secs: Some(10),
imds: ImdsAuthentication { .. },
region: None,
}
));
}

#[test]
fn parsing_default_with_region() {
let config = toml::from_str::<ComponentConfig>(
r#"
auth.region = "us-east-2"
"#,
)
.unwrap();

match config.auth {
AwsAuthentication::Default { region, .. } => {
assert_eq!(region.unwrap(), "us-east-2");
}
_ => panic!(),
}
}

#[test]
fn parsing_default_with_imds_client() {
let config = toml::from_str::<ComponentConfig>(
Expand All @@ -313,6 +346,7 @@ mod tests {
config.auth,
AwsAuthentication::Default {
load_timeout_secs: None,
region: None,
imds: ImdsAuthentication {
max_attempts: 5,
connect_timeout: CONNECT_TIMEOUT,
Expand Down
1 change: 1 addition & 0 deletions src/sinks/aws_kinesis/firehose/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ async fn firehose_put_records() {
auth: Some(ElasticsearchAuth::Aws(AwsAuthentication::Default {
load_timeout_secs: Some(5),
imds: ImdsAuthentication::default(),
region: None,
})),
endpoints: vec![elasticsearch_address()],
bulk: BulkConfig {
Expand Down
3 changes: 3 additions & 0 deletions src/sinks/elasticsearch/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ async fn auto_version_aws() {
auth: Some(ElasticsearchAuth::Aws(AwsAuthentication::Default {
load_timeout_secs: Some(5),
imds: ImdsAuthentication::default(),
region: None,
})),
endpoints: vec![aws_server()],
aws: Some(RegionOrEndpoint::with_region(String::from("localstack"))),
Expand Down Expand Up @@ -346,6 +347,7 @@ async fn insert_events_on_aws() {
auth: Some(ElasticsearchAuth::Aws(AwsAuthentication::Default {
load_timeout_secs: Some(5),
imds: ImdsAuthentication::default(),
region: None,
})),
endpoints: vec![aws_server()],
aws: Some(RegionOrEndpoint::with_region(String::from("localstack"))),
Expand All @@ -368,6 +370,7 @@ async fn insert_events_on_aws_with_compression() {
auth: Some(ElasticsearchAuth::Aws(AwsAuthentication::Default {
load_timeout_secs: Some(5),
imds: ImdsAuthentication::default(),
region: None,
})),
endpoints: vec![aws_server()],
aws: Some(RegionOrEndpoint::with_region(String::from("localstack"))),
Expand Down

0 comments on commit c81ad30

Please sign in to comment.