Skip to content

chore: Separate AwsCredentials from AwsConfig#716

Merged
lym953 merged 5 commits intomainfrom
yiming.luo/separate-aws-creds
Jul 2, 2025
Merged

chore: Separate AwsCredentials from AwsConfig#716
lym953 merged 5 commits intomainfrom
yiming.luo/separate-aws-creds

Conversation

@lym953
Copy link
Copy Markdown
Contributor

@lym953 lym953 commented Jun 24, 2025

Problem

Right now AwsConfig has a lot of fields, including the ones related to credential:

    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,

The next PR #717 wants to lazily load API key and the credentials. To do that, for the resolver function resolve_secrets(), I need to change the param aws_config from &AwsConfig to Arc<RwLock<AwsConfig>>. Because aws_config is passed to many places, this change involves updating lots of functions, which is formidable.

This PR

Separates these credential-related fields out from AwsConfig and creates a new struct AwsCredentials

Thus, the next PR will only need to change the param aws_credentials from &AwsCredentials to Arc<RwLock<AwsCredentials>>. Because aws_credentials is not used in lots of places, the next PR becomes easier.

https://datadoghq.atlassian.net/issues/SVLS-6996
https://datadoghq.atlassian.net/issues/SVLS-6998

fn build_get_secret_signed_headers(
aws_config: &AwsConfig,
aws_credentials: &AwsCredentials,
region: String,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't see a region to pass region separately in the old code. It should be the same as the region in aws_config.
In the new code, removing aws_config since region is the only field needed from aws_config.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

secrets can be cross region, see: #594

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Got it. Let me add back aws_config param.

@lym953 lym953 force-pushed the yiming.luo/separate-aws-creds branch from f749307 to 11c1c77 Compare June 27, 2025 17:35
@lym953 lym953 requested a review from Copilot June 27, 2025 18:36
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR separates AWS credential fields from AwsConfig and introduces a new struct, AwsCredentials, to simplify upcoming changes involving lazy loading of credentials. Key changes include updating function signatures in decrypt.rs to accept an AwsCredentials parameter, updating helper functions to use AwsCredentials, and modifying tests to use the new structure.

Reviewed Changes

Copilot reviewed 6 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
bottlecap/src/secrets/decrypt.rs Updated resolve_secrets and helper functions to use AwsCredentials
bottlecap/src/proxy/mod.rs Removed credential fields from test AwsConfig instances
bottlecap/src/proxy/interceptor.rs Adjusted test AwsConfig instantiation to account for extracted fields
bottlecap/src/lifecycle/invocation/span_inferrer.rs Removed credential fields in test AwsConfig instantiation
bottlecap/src/lifecycle/invocation/processor.rs Removed credential fields in test AwsConfig instantiation
bottlecap/src/config/aws.rs Removed credential fields from AwsConfig and added the AwsCredentials struct
Comments suppressed due to low confidence (3)

bottlecap/src/secrets/decrypt.rs:45

  • Ensure that the logic comparing empty credential fields in aws_credentials aligns with how credentials are initialized elsewhere, to avoid false negatives when credentials are intentionally empty.
            if aws_credentials.aws_secret_access_key.is_empty()

bottlecap/src/secrets/decrypt.rs:20

  • [nitpick] Consider whether the use of a mutable reference for AwsCredentials in resolve_secrets is necessary, or if the function could accept an immutable reference to improve safety and concurrency.
pub async fn resolve_secrets(

bottlecap/src/config/aws.rs:41

  • [nitpick] Adding brief documentation comments for the fields in AwsCredentials would improve clarity for future maintainers.
pub struct AwsCredentials {

@@ -400,13 +400,8 @@ mod tests {

Copy link

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.
@lym953 lym953 marked this pull request as ready for review June 27, 2025 18:37
@lym953 lym953 requested a review from a team as a code owner June 27, 2025 18:37
@lym953 lym953 merged commit f9705b5 into main Jul 2, 2025
46 checks passed
@lym953 lym953 deleted the yiming.luo/separate-aws-creds branch July 2, 2025 21:11
duncanpharvey pushed a commit that referenced this pull request Mar 10, 2026
# Problem
Right now `AwsConfig` has a lot of fields, including the ones related to
credential:
```
    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,
```

The next PR #717
wants to lazily load API key and the credentials. To do that, for the
resolver function `resolve_secrets()`, I need to change the param
`aws_config` from `&AwsConfig` to `Arc<RwLock<AwsConfig>>`. Because
`aws_config` is passed to many places, this change involves updating
lots of functions, which is formidable.

# This PR
Separates these credential-related fields out from `AwsConfig` and
creates a new struct `AwsCredentials`

Thus, the next PR will only need to change the param `aws_credentials`
from `&AwsCredentials` to `Arc<RwLock<AwsCredentials>>`. Because
`aws_credentials` is not used in lots of places, the next PR becomes
easier.

https://datadoghq.atlassian.net/issues/SVLS-6996
https://datadoghq.atlassian.net/issues/SVLS-6998
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants