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(aws service): use http client when building assume role for AccessKey #20285

Merged
merged 4 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Vector would panic when attempting to use a combination af `access_key_id` and
`assume_role` authentication with the AWS components. This error has now been
fixed.

authors: StephenWakely
61 changes: 41 additions & 20 deletions src/aws/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,33 @@ impl AwsAuthentication {
}
}

/// Create the AssumeRoleProviderBuilder, ensuring we create the HTTP client with
/// the correct proxy and TLS options.
fn assume_role_provider_builder(
proxy: &ProxyConfig,
tls_options: &Option<TlsConfig>,
region: &Region,
assume_role: &str,
external_id: Option<&str>,
) -> crate::Result<AssumeRoleProviderBuilder> {
let connector = super::connector(proxy, tls_options)?;
let config = SdkConfig::builder()
.http_client(connector)
.region(region.clone())
.time_source(SystemTimeSource::new())
.build();

let mut builder = AssumeRoleProviderBuilder::new(assume_role)
.region(region.clone())
.configure(&config);

if let Some(external_id) = external_id {
builder = builder.external_id(external_id)
}

Ok(builder)
}

/// Returns the provider for the credentials based on the authentication mechanism chosen.
pub async fn credentials_provider(
&self,
Expand All @@ -228,12 +255,13 @@ impl AwsAuthentication {
));
if let Some(assume_role) = assume_role {
let auth_region = region.clone().map(Region::new).unwrap_or(service_region);
let mut builder =
AssumeRoleProviderBuilder::new(assume_role).region(auth_region);

if let Some(external_id) = external_id {
builder = builder.external_id(external_id)
}
let builder = Self::assume_role_provider_builder(
proxy,
tls_options,
&auth_region,
assume_role,
external_id.as_deref(),
)?;

let provider = builder.build_from_provider(provider).await;

Expand Down Expand Up @@ -264,20 +292,13 @@ impl AwsAuthentication {
..
} => {
let auth_region = region.clone().map(Region::new).unwrap_or(service_region);
let connector = super::connector(proxy, tls_options)?;
let config = SdkConfig::builder()
.http_client(connector)
.region(auth_region.clone())
.time_source(SystemTimeSource::new())
.build();

let mut builder = AssumeRoleProviderBuilder::new(assume_role)
.region(auth_region.clone())
.configure(&config);

if let Some(external_id) = external_id {
builder = builder.external_id(external_id)
}
let builder = Self::assume_role_provider_builder(
proxy,
tls_options,
&auth_region,
assume_role,
external_id.as_deref(),
)?;

let provider = builder
.build_from_provider(
Expand Down
Loading