Skip to content

Conversation

@omus
Copy link
Member

@omus omus commented Jul 2, 2025

While working on #726 it was noticed that one of our AWSConfig tests was falling back to getting the region from IMDS when it should have been getting that information from the AWS configuration file via source_profile. This PR updates the internal function _aws_profile_config to combine the various configuration sections with all of the options inherited via source_profile.

In #726 I noticed that some tests which appeared to be unit tests were failing as they would attempt to fallback on IMDS to determine the region. This made me investigate the internals of the _aws_profile_config and address some minor issues.

Comment on lines 39 to 44
if profile != "default" || !haskey(sections(ini), "default")
profile = "profile $profile"
# Prefer using "profile default" over "default"
section_name = if profile != "default" || haskey(sections(ini), "profile default")
"profile $profile"
else
"default"
end
Copy link
Member Author

@omus omus Jul 2, 2025

Choose a reason for hiding this comment

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

Note the previous logic was to prefer default over profile default which deviates from the AWS CLI preference.

@omus omus marked this pull request as ready for review July 2, 2025 15:59
@omus
Copy link
Member Author

omus commented Jul 2, 2025

Made this feature opt-in as other logic in this code base expects only the one profile to be loaded. I discovered this in #726 and I thought it best to keep things simple for now and maybe we can use the recursive approach across the board in an future update.

@omus omus changed the title Improve AWS config support for source_profile Add recursive AWS config support via source_profile Jul 2, 2025
@omus omus changed the title Add recursive AWS config support via source_profile Improve recursive AWS config support via source_profile Jul 2, 2025
source_profile = test
role_arn = arn:aws:iam::123456789000:role/Dev
[profile test:sub-dev]
Copy link
Collaborator

Choose a reason for hiding this comment

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

If this now supports chained roles, the max time for the session is one hour. Would this time limit cause any other issues?

Copy link
Member Author

Choose a reason for hiding this comment

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

We supported role chaining before this change so nothing really changed here. Any issues that existed before would still be present

@omus omus changed the title Improve recursive AWS config support via source_profile Fix default profile handling when parsing AWS configuration files Jul 2, 2025
@omus
Copy link
Member Author

omus commented Jul 2, 2025

PR has been revised to no longer support inheritance as AWS configurations don't usually support that (annoyingly).

@omus omus requested a review from maganaluis July 2, 2025 21:02
@omus omus enabled auto-merge July 3, 2025 13:14
@omus omus added this pull request to the merge queue Jul 3, 2025
Merged via the queue into master with commit a883442 Jul 3, 2025
7 checks passed
@omus omus deleted the cv/aws-profile-config branch July 3, 2025 13:21
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.

3 participants