Skip to content

fix(resources_aws): improve the aws credentials sourcing logic by offloading the selection logic to boto3#707

Merged
Thilak-KN merged 1 commit intovirt-s1:masterfrom
Thilak-KN:master
Apr 24, 2026
Merged

fix(resources_aws): improve the aws credentials sourcing logic by offloading the selection logic to boto3#707
Thilak-KN merged 1 commit intovirt-s1:masterfrom
Thilak-KN:master

Conversation

@Thilak-KN
Copy link
Copy Markdown
Collaborator

@Thilak-KN Thilak-KN commented Apr 24, 2026

Summary by Sourcery

Bug Fixes:

  • Ensure EC2-related resources correctly use environment-provided AWS credentials by deferring credential selection to boto3 when AWS_ACCESS_KEY_ID is set.

sourcery-ai[bot]

This comment was marked as outdated.

gemini-code-assist[bot]

This comment was marked as outdated.

@virt-s1 virt-s1 deleted a comment from sourcery-ai Bot Apr 24, 2026
@virt-s1 virt-s1 deleted a comment from gemini-code-assist Bot Apr 24, 2026
@virt-s1 virt-s1 deleted a comment from gemini-code-assist Bot Apr 24, 2026
@virt-s1 virt-s1 deleted a comment from gemini-code-assist Bot Apr 24, 2026
@Thilak-KN
Copy link
Copy Markdown
Collaborator Author

@sourcery-ai review

sourcery-ai[bot]

This comment was marked as outdated.

@Thilak-KN
Copy link
Copy Markdown
Collaborator Author

@sourcery-ai review

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Apr 24, 2026

Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts AWS credential sourcing for EC2-related resources so that boto3’s default credential resolution is used whenever no profile is given or explicit AWS access key environment variables are present, preventing unintended profile usage.

File-Level Changes

Change Details Files
Delegate AWS credential selection to boto3 for EC2-related resources when either no profile is provided or explicit AWS access key environment variables are set, instead of always forcing a configured profile when present.
  • Update session initialization conditions to treat the presence of AWS_ACCESS_KEY_ID in the environment as a signal to use a profile-less boto3 session, even if a profile_name parameter is provided.
  • Unify and clarify log messages to reflect that boto3 is now responsible for detecting authentication methods and sourcing credentials in these cases.
  • Apply this credential sourcing logic consistently across EC2VM, EC2Volume, and EC2NIC resource initializers.
os_tests/libs/resources_aws.py

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The if self.profile_name is None or os.environ.get('AWS_ACCESS_KEY_ID') is not None condition is duplicated across multiple resources; consider extracting the credential/session selection into a shared helper to keep the logic consistent and easier to change in one place.
  • Relying only on AWS_ACCESS_KEY_ID to decide to ignore the configured profile may be too narrow; consider checking for the full set of explicit credential env vars (AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, and optionally AWS_SESSION_TOKEN) to better reflect boto3’s intent and avoid ambiguous states.
  • It might be useful to log when the code is intentionally ignoring a provided profile_name due to environment credentials being set so that operators understand which auth source actually took precedence.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `if self.profile_name is None or os.environ.get('AWS_ACCESS_KEY_ID') is not None` condition is duplicated across multiple resources; consider extracting the credential/session selection into a shared helper to keep the logic consistent and easier to change in one place.
- Relying only on `AWS_ACCESS_KEY_ID` to decide to ignore the configured profile may be too narrow; consider checking for the full set of explicit credential env vars (`AWS_ACCESS_KEY_ID`, `AWS_SECRET_ACCESS_KEY`, and optionally `AWS_SESSION_TOKEN`) to better reflect boto3’s intent and avoid ambiguous states.
- It might be useful to log when the code is intentionally ignoring a provided `profile_name` due to environment credentials being set so that operators understand which auth source actually took precedence.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Thilak-KN Thilak-KN merged commit 96b5dce into virt-s1:master Apr 24, 2026
2 checks passed
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.

1 participant