-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CDK CLI: assuming a doubly-chained role fails since 2.167.0 #32195
Comments
I presume role0 for Account A and both role1,2 for Account B right? |
Apologies, you are correct. I'll update the initial comment as well. |
This is my test
CLI TestI can run the following commands using AWS CLI correctly
CDK Testconst app = new App();
const env = { region: process.env.CDK_DEFAULT_REGION, account: process.env.CDK_DEFAULT_ACCOUNT };
const stack = new Stack(app, 'issue-triage-stack', { env } )
new CfnOutput(stack, 'cdk_default_account', { value: process.env.CDK_DEFAULT_ACCOUNT || 'not found' });
new CfnOutput(stack, 'cdk_default_region', { value: process.env.CDK_DEFAULT_REGION || 'not found' }); I can run this correctly % npx cdk --profile role1 diff And see the Outputs
But it won't resolve using role2 profile in 1.166.0
I don't think CDK 2.166.0 supports this. But if I change the config of role2 using role0 as the source
cdk diff works pretty great! Can you provide a minimal sample as above that works in 166 but not in 167? |
by the way, we don't specify these in ~/.aws/config are you sure they are configured in ~/.aws/config ?
|
Those are specified in ~/.aws/credentials. All 3 roles are in ~/.aws/credentials. Although I believe it is possible to move role1 and role2 to ~/.aws/config. |
Here's some more detailed reproduction steps, similar to what you have.
cdk.json
app.py
Hopefully that helps. Let me know if there's any other info I can provide. |
OK so you are actually using CDK in Python but you mentioned |
Sorry about that, I must've misclicked. Fixed! |
No worries. Unfortunately, I still can't reproduce that in 2.166.0 % aws sts get-caller-identity --profile role1
{
"UserId": "<***>",
"Account": "<***>",
"Arn": "arn:aws:sts::<***>:assumed-role/<***>"
}
% aws sts get-caller-identity --profile role2
{
"UserId": "<***>",
"Account": "<***>",
"Arn": "arn:aws:sts::<***>:assumed-role/<***>"
}
app.py #!/usr/bin/env python3
import os
from aws_cdk import App
print(f"CDK_DEFAULT_ACCOUNT = {os.environ.get('CDK_DEFAULT_ACCOUNT')}")
print(f"CDK_DEFAULT_REGION = {os.environ.get('CDK_DEFAULT_REGION')}")
app = App()
app.synth() Are you running on |
The issue is with the cdk cli version 1.167.0. Not with aws-cdk-lib 2.166.0. |
Yes I know but from my testing even 2.166.0(both CLI and aws-cdk-lib) does not support that. I wil reach out to someone else on my team to have a second look. |
Yeah, I'm running on Windows 10. I had someone try this on a Mac, and they're having the same issue. I tried it with javascript, and I'm seeing the same issue as well.
|
Related: #25870. I am also unable to reproduce. That is, i'm seeing the same behavior on 2.166.0. This is my [role0]
aws_access_key_id = XXXX
aws_secret_access_key = XXXX
aws_session_token = XXXX
[role1]
source_profile = role0
role_arn = arn:aws:iam::ACCOUNT_B:role/TestIssue32195
[role2]
source_profile = role1
role_arn = arn:aws:iam::ACCOUNT_B:role/TestIssue32195-2
Both This is what i'm seeing in 2.166.0: cdk synth --profile role2
CDK_DEFAULT_ACCOUNT: undefined. <-- Getting undefined in 2.166.0 as well
CDK_DEFAULT_REGION: us-east-1
This app contains no stacks
cdk synth --profile role1
CDK_DEFAULT_ACCOUNT: ACCOUNT_B
CDK_DEFAULT_REGION: us-east-1
This app contains no stacks
dk synth --profile role0
CDK_DEFAULT_ACCOUNT: ACCOUNT_A
CDK_DEFAULT_REGION: us-east-1
This app contains no stacks |
Debug logs show |
Hmm. Im getting: aws sts get-caller-identity --profile role2
An error occurred (AccessDenied) when calling the AssumeRole operation: User: arn:aws:sts::ACCOUNT_B:assumed-role/TestIssue32195/botocore-session-1732089642 is not authorized to perform: sts:AssumeRole on resource: arn:aws:iam::ACCOUNT_B:role/TestIssue32195-2 @Joe-Zer0 Can you confirm you aren't seeing this error from sts? Can you share how |
Ok I managed to reproduce. I was just missing the right policies for ❯ npx aws-cdk@2.167.2 synth --profile role2 [10:12:08]
CDK_DEFAULT_ACCOUNT: undefined
CDK_DEFAULT_REGION: us-east-1
❯ npx aws-cdk@2.166.0 synth --profile role2 [10:12:26]
CDK_DEFAULT_ACCOUNT: ACCOUNT_B
CDK_DEFAULT_REGION: us-east-1
This app contains no stacks |
We have tracked the issue to the JavaScript AWS SDKv3. Doubly-chained role assumption does not seem to work there. |
For JS SDK issue - it could be resolved by updating the package version to v3.651.1 or higher |
Comments on closed issues and PRs are hard for our team to see. |
1 similar comment
Comments on closed issues and PRs are hard for our team to see. |
Describe the bug
This may be related to #32120, but it's different enough I decided to create a separate issue.
2.166.0 works. 2.167.0 and 2.167.2 do not work.
Credentials File
Not sure if it's relevant, but role0 is for Account A and role1 and role2 are for Account B.
Using version 2.167.0,
cdk synth --profile role1
works correctly, the CDK_DEFAULT_ACCOUNT environment variable is populated. The issue happens when runningcdk synth --profile role2
, CDK_DEFAULT_ACCOUNT is not populated. But CDK_DEFAULT_REGION is still populated correctly.Please let me know if there is any additional information I can provide.
Regression Issue
Last Known Working CDK Version
2.166.0
Expected Behavior
I would expect
cdk synth --profile role2
to populate CDK_DEFAULT_ACCOUNT with the account number.Current Behavior
cdk synth --profile role2
does not populate CDK_DEFAULT_ACCOUNT with the account number.Reproduction Steps
Run
cdk synth
on any stack with a profile that is "double assumed".Possible Solution
No response
Additional Information/Context
No response
CDK CLI Version
2.167.2
Framework Version
No response
Node.js Version
v20.17.0
OS
Windows 10
Language
Python
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: