Skip to content

Commit e472445

Browse files
authored
chore: add retrospective integration test for Permissions Boundaries (#34899)
This is an integ test that would have caught the priority reversal problem introduced in #32333. This integration test tests the case of a customer setting a permissions boundary using a custom aspect, then trying to override at a more specific level using the PermissionsBoundary.of() API. ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
1 parent 23ca6fc commit e472445

File tree

9 files changed

+380
-0
lines changed

9 files changed

+380
-0
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-iam/test/integ.custom-permissions-boundary-aspect.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.custom-permissions-boundary-aspect.js.snapshot/integ-permissions-boundary.assets.json

Lines changed: 21 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,85 @@
1+
{
2+
"Resources": {
3+
"NormalRoleE03CFB68": {
4+
"Type": "AWS::IAM::Role",
5+
"Properties": {
6+
"AssumeRolePolicyDocument": {
7+
"Statement": [
8+
{
9+
"Action": "sts:AssumeRole",
10+
"Effect": "Allow",
11+
"Principal": {
12+
"Service": "sqs.amazonaws.com"
13+
}
14+
}
15+
],
16+
"Version": "2012-10-17"
17+
},
18+
"PermissionsBoundary": "arn:aws:iam::aws:policy/ReadOnlyAccess"
19+
}
20+
},
21+
"PowerRoleD07CA715": {
22+
"Type": "AWS::IAM::Role",
23+
"Properties": {
24+
"AssumeRolePolicyDocument": {
25+
"Statement": [
26+
{
27+
"Action": "sts:AssumeRole",
28+
"Effect": "Allow",
29+
"Principal": {
30+
"Service": "sqs.amazonaws.com"
31+
}
32+
}
33+
],
34+
"Version": "2012-10-17"
35+
},
36+
"PermissionsBoundary": {
37+
"Fn::Join": [
38+
"",
39+
[
40+
"arn:",
41+
{
42+
"Ref": "AWS::Partition"
43+
},
44+
":iam::aws:policy/AdministratorAccess"
45+
]
46+
]
47+
}
48+
}
49+
}
50+
},
51+
"Parameters": {
52+
"BootstrapVersion": {
53+
"Type": "AWS::SSM::Parameter::Value<String>",
54+
"Default": "/cdk-bootstrap/hnb659fds/version",
55+
"Description": "Version of the CDK Bootstrap resources in this environment, automatically retrieved from SSM Parameter Store. [cdk:skip]"
56+
}
57+
},
58+
"Rules": {
59+
"CheckBootstrapVersion": {
60+
"Assertions": [
61+
{
62+
"Assert": {
63+
"Fn::Not": [
64+
{
65+
"Fn::Contains": [
66+
[
67+
"1",
68+
"2",
69+
"3",
70+
"4",
71+
"5"
72+
],
73+
{
74+
"Ref": "BootstrapVersion"
75+
}
76+
]
77+
}
78+
]
79+
},
80+
"AssertDescription": "CDK bootstrap stack version 6 required. Please run 'cdk bootstrap' with a recent version of the CDK CLI."
81+
}
82+
]
83+
}
84+
}
85+
}

packages/@aws-cdk-testing/framework-integ/test/aws-iam/test/integ.custom-permissions-boundary-aspect.js.snapshot/integ.json

Lines changed: 13 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.custom-permissions-boundary-aspect.js.snapshot/integtestDefaultTestDeployAssert24D5C536.assets.json

Lines changed: 20 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.custom-permissions-boundary-aspect.js.snapshot/integtestDefaultTestDeployAssert24D5C536.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.custom-permissions-boundary-aspect.js.snapshot/manifest.json

Lines changed: 153 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.custom-permissions-boundary-aspect.js.snapshot/tree.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
* This integration test tests the case of a customer setting a permissions boundary using a custom aspect,
3+
* then trying to override at a more specific level using the PermissionsBoundary.of() API.
4+
*
5+
* Overriding should work.
6+
*/
7+
import { App, Stack, IAspect, Aspects } from 'aws-cdk-lib';
8+
import { IntegTest } from '@aws-cdk/integ-tests-alpha';
9+
import { CfnRole, ManagedPolicy, PermissionsBoundary, Role, ServicePrincipal } from 'aws-cdk-lib/aws-iam';
10+
import { IConstruct } from 'constructs';
11+
12+
class CustomAspect implements IAspect {
13+
public visit(node: IConstruct): void {
14+
if (node instanceof CfnRole) {
15+
node.addPropertyOverride('PermissionsBoundary', 'arn:aws:iam::aws:policy/ReadOnlyAccess');
16+
}
17+
}
18+
}
19+
20+
const app = new App({
21+
postCliContext: {
22+
// Force the intended behavior, from before we found this bug
23+
'@aws-cdk/core:aspectPrioritiesMutating': false,
24+
},
25+
});
26+
27+
const stack = new Stack(app, 'integ-permissions-boundary', {
28+
env: {
29+
account: process.env.CDK_INTEG_ACCOUNT ?? process.env.CDK_DEFAULT_ACCOUNT,
30+
region: process.env.CDK_INTEG_REGION ?? process.env.CDK_DEFAULT_REGION,
31+
},
32+
});
33+
34+
Aspects.of(stack).add(new CustomAspect());
35+
36+
new Role(stack, 'NormalRole', {
37+
assumedBy: new ServicePrincipal('sqs.amazonaws.com'),
38+
});
39+
40+
const powerRole = new Role(stack, 'PowerRole', {
41+
assumedBy: new ServicePrincipal('sqs.amazonaws.com'),
42+
});
43+
44+
PermissionsBoundary.of(powerRole).apply(ManagedPolicy.fromAwsManagedPolicyName('AdministratorAccess'));
45+
46+
new IntegTest(app, 'integ-test', {
47+
testCases: [stack],
48+
});
49+
50+
app.synth();

0 commit comments

Comments
 (0)