Skip to content

Commit f9f3681

Browse files
authored
fix(iam): fromUserArn returns incorrect principalAccount (#30023)
### Issue # (if applicable) Closes #29999 ### Reason for this change As described in the issue [comment](#29999 (comment)). ### Description of changes ### Description of how you validated changes 1. added more unit tests. 2. added a new integ test 3. I have deployed this in my AWS account ```ts import { App, Stack, CfnParameter, aws_iam as iam, CfnOutput, } from 'aws-cdk-lib'; const app = new App(); const stack = new Stack(app, 'dummy-stack'); const userArn = 'arn:aws:iam::123456789012:user/OthersExternalIamUser'; const userparam = new CfnParameter(stack, 'UserParameter', { default: userArn, }); const imported = iam.User.fromUserArn(stack, 'imported-user', userArn); const imported2 = iam.User.fromUserArn(stack, 'imported-user2', userparam.valueAsString ); new CfnOutput(stack, 'User', { value: imported.principalAccount! }); new CfnOutput(stack, 'User2', { value: imported2.principalAccount! }); ``` And the output is correct: ``` Outputs: dummy-stack.User = 123456789012 dummy-stack.User2 = 123456789012 ``` ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 7bd76bf commit f9f3681

File tree

11 files changed

+555
-2
lines changed

11 files changed

+555
-2
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-iam/test/integ.user-import.js.snapshot/cdk.out

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-iam/test/integ.user-import.js.snapshot/dummy-stack.assets.json

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
{
2+
"Parameters": {
3+
"UserParameter": {
4+
"Type": "String",
5+
"Default": "arn:aws:iam::123456789012:user/OthersExternalIamUser"
6+
},
7+
"BootstrapVersion": {
8+
"Type": "AWS::SSM::Parameter::Value<String>",
9+
"Default": "/cdk-bootstrap/hnb659fds/version",
10+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
11+
}
12+
},
13+
"Resources": {
14+
"User00B015A1": {
15+
"Type": "AWS::IAM::User"
16+
}
17+
},
18+
"Outputs": {
19+
"UserOutput": {
20+
"Value": "123456789012"
21+
},
22+
"User2Output": {
23+
"Value": {
24+
"Fn::Select": [
25+
4,
26+
{
27+
"Fn::Split": [
28+
":",
29+
{
30+
"Ref": "UserParameter"
31+
}
32+
]
33+
}
34+
]
35+
}
36+
},
37+
"User3Output": {
38+
"Value": {
39+
"Fn::Select": [
40+
4,
41+
{
42+
"Fn::Split": [
43+
":",
44+
{
45+
"Fn::GetAtt": [
46+
"User00B015A1",
47+
"Arn"
48+
]
49+
}
50+
]
51+
}
52+
]
53+
}
54+
}
55+
},
56+
"Rules": {
57+
"CheckBootstrapVersion": {
58+
"Assertions": [
59+
{
60+
"Assert": {
61+
"Fn::Not": [
62+
{
63+
"Fn::Contains": [
64+
[
65+
"1",
66+
"2",
67+
"3",
68+
"4",
69+
"5"
70+
],
71+
{
72+
"Ref": "BootstrapVersion"
73+
}
74+
]
75+
}
76+
]
77+
},
78+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
79+
}
80+
]
81+
}
82+
}
83+
}

packages/@aws-cdk-testing/framework-integ/test/aws-iam/test/integ.user-import.js.snapshot/dummystackintegtestDefaultTestDeployAssertF190D0AF.assets.json

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-iam/test/integ.user-import.js.snapshot/dummystackintegtestDefaultTestDeployAssertF190D0AF.template.json

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-iam/test/integ.user-import.js.snapshot/integ.json

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-iam/test/integ.user-import.js.snapshot/manifest.json

Lines changed: 137 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)