Commit 0bfc338
authored
fix(auth): Fix for SSO Profile Role Chaining Regression (aws#7764)
## Github Issue aws#6902
## Problem
AWS Toolkit version 3.47.0 introduced a regression where profiles using
`source_profile` for role chaining fail to authenticate when the source
profile uses SSO credentials. Users get an "InvalidClientTokenId: The
security token included in the request is invalid" error.
## Root Cause
The issue was introduced in commit 6f6a8c2 (Feb 13, 2025) which
refactored the authentication code to remove deprecated AWS SDK
dependencies. The new implementation in
`makeSharedIniFileCredentialsProvider` method incorrectly assumed that
the source profile would have static credentials (aws_access_key_id and
aws_secret_access_key) directly in the profile data.
When the source profile uses SSO, these static credentials don't exist
in the profile data - they need to be obtained by calling the SSO
service first.
## Solution
The fix modifies the `makeSharedIniFileCredentialsProvider` method in
`packages/core/src/auth/providers/sharedCredentialsProvider.ts` to:
1. Check if the source profile already has resolved credentials (from
`patchSourceCredentials`)
2. If not, create a new `SharedCredentialsProvider` instance for the
source profile and resolve its credentials dynamically
3. Use those resolved credentials to assume the role via STS
This ensures that SSO profiles can be used as source profiles for role
assumption.
## Changed Files
- `packages/core/src/auth/providers/sharedCredentialsProvider.ts` -
Fixed the credential resolution logic
-
`packages/core/src/test/auth/providers/sharedCredentialsProvider.roleChaining.test.ts`
- Added tests to verify the fix
## Testing
The fix includes unit tests that verify:
1. Role chaining from SSO profiles works correctly
2. Role chaining from SSO profiles with MFA works correctly
## Configuration Example
This fix enables configurations like:
```ini
[sso-session aws1_session]
sso_start_url = https://example.awsapps.com/start
sso_region = us-east-1
sso_registration_scopes = sso:account:access
[profile Landing]
sso_session = aws1_session
sso_account_id = 111111111111
sso_role_name = Landing
region = us-east-1
[profile dev]
region = us-east-1
role_arn = arn:aws:iam::123456789012:role/dev
source_profile = Landing
```
Where `dev` profile assumes a role using credentials from the SSO-based
`Landing` profile.
---
- Treat all work as PUBLIC. Private `feature/x` branches will not be
squash-merged at release time.
- Your code changes must meet the guidelines in
[CONTRIBUTING.md](https://github.com/aws/aws-toolkit-vscode/blob/master/CONTRIBUTING.md#guidelines).
- License: I confirm that my contribution is made under the terms of the
Apache 2.0 license.1 parent 64fae72 commit 0bfc338
File tree
2 files changed
+100
-5
lines changed- packages/core/src
- auth/providers
- test/auth/providers
2 files changed
+100
-5
lines changedLines changed: 21 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
406 | 406 | | |
407 | 407 | | |
408 | 408 | | |
409 | | - | |
| 409 | + | |
| 410 | + | |
410 | 411 | | |
411 | | - | |
412 | | - | |
413 | | - | |
414 | | - | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
415 | 431 | | |
416 | 432 | | |
417 | 433 | | |
| |||
Lines changed: 79 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
0 commit comments