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

feat: Add support for AWS_EC2_METADATA_DISABLED env var #380

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 9 additions & 1 deletion src/aws/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,11 @@ pub struct Config {
/// - env value: [`AWS_WEB_IDENTITY_TOKEN_FILE`]
/// - profile config: `web_identity_token_file`
pub web_identity_token_file: Option<String>,
/// `ec2_metadata_disabled` value will be loaded from:
///
/// - this field
/// - env value: [`AWS_EC2_METADATA_DISABLED`]
pub ec2_metadata_disabled: bool,
}

impl Default for Config {
Expand All @@ -101,6 +106,7 @@ impl Default for Config {
role_session_name: "reqsign".to_string(),
external_id: None,
web_identity_token_file: None,
ec2_metadata_disabled: false,
}
}
}
Expand Down Expand Up @@ -143,7 +149,9 @@ impl Config {
if let Some(v) = envs.get(AWS_WEB_IDENTITY_TOKEN_FILE) {
self.web_identity_token_file = Some(v.to_string());
}

if let Some(v) = envs.get(AWS_EC2_METADATA_DISABLED) {
self.ec2_metadata_disabled = v == "true";
}
self
}

Expand Down
1 change: 1 addition & 0 deletions src/aws/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pub const AWS_WEB_IDENTITY_TOKEN_FILE: &str = "AWS_WEB_IDENTITY_TOKEN_FILE";
pub const AWS_ROLE_ARN: &str = "AWS_ROLE_ARN";
pub const AWS_ROLE_SESSION_NAME: &str = "AWS_ROLE_SESSION_NAME";
pub const AWS_STS_REGIONAL_ENDPOINTS: &str = "AWS_STS_REGIONAL_ENDPOINTS";
pub const AWS_EC2_METADATA_DISABLED: &str = "AWS_EC2_METADATA_DISABLED";

/// AsciiSet for [AWS UriEncode](https://docs.aws.amazon.com/AmazonS3/latest/API/sig-v4-header-based-auth.html)
///
Expand Down
11 changes: 5 additions & 6 deletions src/aws/credential.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,22 +73,21 @@ pub trait CredentialLoad: 'static + Send + Sync {
pub struct DefaultLoader {
client: Client,
config: Config,

credential: Arc<Mutex<Option<Credential>>>,

imds_v2_loader: Option<IMDSv2Loader>,
}

impl DefaultLoader {
/// Create a new CredentialLoader
pub fn new(client: Client, config: Config) -> Self {
let imds_v2_loader = config
.ec2_metadata_disabled
.then(|| IMDSv2Loader::new(client.clone()));
Self {
client: client.clone(),
client,
config,

credential: Arc::default(),

imds_v2_loader: Some(IMDSv2Loader::new(client)),
imds_v2_loader,
}
}

Expand Down
Loading