Skip to content

chore: Separate AwsCredentials from AwsConfig #716

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

Merged
merged 5 commits into from
Jul 2, 2025
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
13 changes: 8 additions & 5 deletions bottlecap/src/bin/bottlecap/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use bottlecap::{
base_url,
config::{
self,
aws::{build_lambda_function_arn, AwsConfig},
aws::{build_lambda_function_arn, AwsConfig, AwsCredentials},
Config,
},
event_bus::bus::EventBus,
Expand Down Expand Up @@ -302,7 +302,7 @@ async fn register(client: &Client) -> Result<RegisterResponse> {
#[tokio::main]
async fn main() -> Result<()> {
let start_time = Instant::now();
let (mut aws_config, config) = load_configs(start_time);
let (aws_config, mut aws_credentials, config) = load_configs(start_time);

enable_logging_subsystem(&config);
log_fips_status(&aws_config.region);
Expand All @@ -329,7 +329,9 @@ async fn main() -> Result<()> {
.await
.map_err(|e| Error::new(std::io::ErrorKind::InvalidData, e.to_string()))?;

if let Some(resolved_api_key) = resolve_secrets(Arc::clone(&config), &mut aws_config).await {
if let Some(resolved_api_key) =
resolve_secrets(Arc::clone(&config), &aws_config, &mut aws_credentials).await
{
match extension_loop_active(
&aws_config,
&config,
Expand Down Expand Up @@ -357,9 +359,10 @@ async fn main() -> Result<()> {
}
}

fn load_configs(start_time: Instant) -> (AwsConfig, Arc<Config>) {
fn load_configs(start_time: Instant) -> (AwsConfig, AwsCredentials, Arc<Config>) {
// First load the AWS configuration
let aws_config = AwsConfig::from_env(start_time);
let aws_credentials = AwsCredentials::from_env();
let lambda_directory: String =
env::var("LAMBDA_TASK_ROOT").unwrap_or_else(|_| "/var/task".to_string());
let config = match config::get_config(Path::new(&lambda_directory)) {
Expand All @@ -370,7 +373,7 @@ fn load_configs(start_time: Instant) -> (AwsConfig, Arc<Config>) {
}
};

(aws_config, config)
(aws_config, aws_credentials, config)
}

fn enable_logging_subsystem(config: &Arc<Config>) {
Expand Down
33 changes: 23 additions & 10 deletions bottlecap/src/config/aws.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@ const AWS_LAMBDA_EXEC_WRAPPER: &str = "AWS_LAMBDA_EXEC_WRAPPER";
#[derive(Debug, Clone)]
pub struct AwsConfig {
pub region: String,
pub aws_access_key_id: String,
pub aws_secret_access_key: String,
pub aws_session_token: String,
pub aws_container_credentials_full_uri: String,
pub aws_container_authorization_token: String,
pub aws_lwa_proxy_lambda_runtime_api: Option<String>,
pub function_name: String,
pub runtime_api: String,
Expand All @@ -32,18 +27,36 @@ impl AwsConfig {
pub fn from_env(start_time: Instant) -> Self {
Self {
region: env::var(AWS_DEFAULT_REGION).unwrap_or("us-east-1".to_string()),
aws_lwa_proxy_lambda_runtime_api: env::var(AWS_LWA_LAMBDA_RUNTIME_API_PROXY).ok(),
function_name: env::var(AWS_LAMBDA_FUNCTION_NAME).unwrap_or_default(),
runtime_api: env::var(AWS_LAMBDA_RUNTIME_API).unwrap_or_default(),
sandbox_init_time: start_time,
exec_wrapper: env::var(AWS_LAMBDA_EXEC_WRAPPER).ok(),
}
}
}

#[allow(clippy::module_name_repetitions)]
#[derive(Debug, Clone)]
pub struct AwsCredentials {
pub aws_access_key_id: String,
pub aws_secret_access_key: String,
pub aws_session_token: String,
pub aws_container_credentials_full_uri: String,
pub aws_container_authorization_token: String,
}

impl AwsCredentials {
#[must_use]
pub fn from_env() -> Self {
Self {
aws_access_key_id: env::var(AWS_ACCESS_KEY_ID).unwrap_or_default(),
aws_secret_access_key: env::var(AWS_SECRET_ACCESS_KEY).unwrap_or_default(),
aws_session_token: env::var(AWS_SESSION_TOKEN).unwrap_or_default(),
aws_container_credentials_full_uri: env::var(AWS_CONTAINER_CREDENTIALS_FULL_URI)
.unwrap_or_default(),
aws_container_authorization_token: env::var(AWS_CONTAINER_AUTHORIZATION_TOKEN)
.unwrap_or_default(),
aws_lwa_proxy_lambda_runtime_api: env::var(AWS_LWA_LAMBDA_RUNTIME_API_PROXY).ok(),
function_name: env::var(AWS_LAMBDA_FUNCTION_NAME).unwrap_or_default(),
runtime_api: env::var(AWS_LAMBDA_RUNTIME_API).unwrap_or_default(),
sandbox_init_time: start_time,
exec_wrapper: env::var(AWS_LAMBDA_EXEC_WRAPPER).ok(),
}
}
}
Expand Down
5 changes: 0 additions & 5 deletions bottlecap/src/lifecycle/invocation/processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -966,11 +966,6 @@ mod tests {
fn setup() -> Processor {
let aws_config = AwsConfig {
region: "us-east-1".into(),
aws_access_key_id: "***".into(),
aws_secret_access_key: "***".into(),
aws_session_token: "***".into(),
aws_container_credentials_full_uri: "***".into(),
aws_container_authorization_token: "***".into(),
aws_lwa_proxy_lambda_runtime_api: Some("***".into()),
function_name: "test-function".into(),
sandbox_init_time: Instant::now(),
Expand Down
5 changes: 0 additions & 5 deletions bottlecap/src/lifecycle/invocation/span_inferrer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -480,11 +480,6 @@ mod tests {

let aws_config = AwsConfig {
region: "us-east-1".to_string(),
aws_access_key_id: "".to_string(),
aws_secret_access_key: "".to_string(),
aws_session_token: "".to_string(),
aws_container_credentials_full_uri: "".to_string(),
aws_container_authorization_token: "".to_string(),
aws_lwa_proxy_lambda_runtime_api: Some("".to_string()),
runtime_api: "".to_string(),
function_name: "".to_string(),
Expand Down
5 changes: 0 additions & 5 deletions bottlecap/src/proxy/interceptor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,13 +400,8 @@ mod tests {

Copy link
Preview

Copilot AI Jun 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since credential fields are now removed from AwsConfig, ensure that any test or sample initialization that previously provided dummy credential values is updated to either create an AwsCredentials instance or clearly document that these values are not required.

Suggested change
// Note: Credentials are not required for this test case as it does not involve AWS authentication.

Copilot uses AI. Check for mistakes.

let aws_config = AwsConfig {
region: "us-east-1".to_string(),
aws_access_key_id: "AKIDEXAMPLE".to_string(),
aws_secret_access_key: "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY".to_string(),
aws_session_token: "AQoDYXdzEJr...<remainder of session token>".to_string(),
function_name: "arn:some-function".to_string(),
sandbox_init_time: Instant::now(),
aws_container_credentials_full_uri: String::new(),
aws_container_authorization_token: String::new(),
runtime_api: aws_lambda_runtime_api.to_string(),
aws_lwa_proxy_lambda_runtime_api: Some(aws_lwa_lambda_runtime_api.to_string()),
exec_wrapper: None,
Expand Down
25 changes: 0 additions & 25 deletions bottlecap/src/proxy/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ mod tests {
});
let aws_config = AwsConfig {
region: "us-east-1".to_string(),
aws_access_key_id: "".to_string(),
aws_secret_access_key: "".to_string(),
aws_session_token: "".to_string(),
aws_container_credentials_full_uri: "".to_string(),
aws_container_authorization_token: "".to_string(),
aws_lwa_proxy_lambda_runtime_api: Some("127.0.0.1:12345".to_string()),
function_name: "".to_string(),
runtime_api: "".to_string(),
Expand All @@ -55,11 +50,6 @@ mod tests {
let config = Arc::new(Config::default());
let aws_config = AwsConfig {
region: "us-east-1".to_string(),
aws_access_key_id: "".to_string(),
aws_secret_access_key: "".to_string(),
aws_session_token: "".to_string(),
aws_container_credentials_full_uri: "".to_string(),
aws_container_authorization_token: "".to_string(),
// LWA proxy is set, so we should start the proxy
aws_lwa_proxy_lambda_runtime_api: Some("127.0.0.1:12345".to_string()),
function_name: "".to_string(),
Expand All @@ -79,11 +69,6 @@ mod tests {
});
let aws_config = AwsConfig {
region: "us-east-1".to_string(),
aws_access_key_id: "".to_string(),
aws_secret_access_key: "".to_string(),
aws_session_token: "".to_string(),
aws_container_credentials_full_uri: "".to_string(),
aws_container_authorization_token: "".to_string(),
aws_lwa_proxy_lambda_runtime_api: None,
function_name: "".to_string(),
runtime_api: "".to_string(),
Expand All @@ -102,11 +87,6 @@ mod tests {
});
let aws_config = AwsConfig {
region: "us-east-1".to_string(),
aws_access_key_id: "".to_string(),
aws_secret_access_key: "".to_string(),
aws_session_token: "".to_string(),
aws_container_credentials_full_uri: "".to_string(),
aws_container_authorization_token: "".to_string(),
aws_lwa_proxy_lambda_runtime_api: None,
function_name: "".to_string(),
runtime_api: "".to_string(),
Expand All @@ -125,11 +105,6 @@ mod tests {
});
let aws_config = AwsConfig {
region: "us-east-1".to_string(),
aws_access_key_id: "".to_string(),
aws_secret_access_key: "".to_string(),
aws_session_token: "".to_string(),
aws_container_credentials_full_uri: "".to_string(),
aws_container_authorization_token: "".to_string(),
aws_lwa_proxy_lambda_runtime_api: None,
function_name: "".to_string(),
runtime_api: "".to_string(),
Expand Down
Loading
Loading