Add --sso-role to override the IAM Identity Center role - #9
Merged
Conversation
Lets an agent reach AWS through a narrower role, such as ReadOnlyAccess, without editing the shared config. Each profile keeps its own sso_account_id and SSO session; only the role name changes, so one flag covers every profile even across accounts. The SSO access token is per session rather than per role, so the swap needs no new login. This is SSO-only because GetRoleCredentials takes an account and a role name, while AssumeRole needs the role's full ARN, which differs per account. A profile that does not use IAM Identity Center never reaches the SSO branch of the credential chain, so it is left alone. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
winebarrel
enabled auto-merge
August 9, 2026 04:30
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9 +/- ##
==========================================
+ Coverage 98.38% 98.40% +0.02%
==========================================
Files 5 5
Lines 372 377 +5
==========================================
+ Hits 366 371 +5
Misses 3 3
Partials 3 3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Replaces
sso_role_namefor every profile, keeping each profile's ownsso_account_idand SSO session. One flag covers every profile even across accounts, because only the role name changes.This is how you stop an agent writing to AWS. Hiding write-capable tools would not be a boundary; a role that lacks the permissions is one.
Implementation
One option, no hand-rolled credential wiring:
ssocreds.Newtakes the role name as a constructor argument and then applies the option functions, so this wins oversso_role_name. The rest of the SDK's credential resolution is untouched.The SSO access token is per session rather than per role, so the swap needs no new login -- the cached token from
aws sso loginis reused and only theGetRoleCredentialsrole name differs.Why SSO only
GetRoleCredentialstakes an account ID and a role name.AssumeRoletakes the role's full ARN, which embeds the account ID, so a single flag could not cover profiles in different accounts without first resolving each account and building the ARN.A profile that does not use IAM Identity Center never reaches the SSO branch of the credential chain, so the option is never consulted and the profile keeps its own credentials. No detection code, and nothing to go stale.
A role that is not assigned to you in that account fails when the credentials are first used, not at startup -- there is no way to know earlier without calling the portal.
Tests
A fake IAM Identity Center portal answers
GetRoleCredentials, so the tests assert what was actually asked for:--sso-role,role_name=ReadOnlyAccesswhileaccount_idstays the profile'srole_nameis the profile'sAdministratorAccessCoverage stays at 99.0%.