Skip to content

Commit 2cfd928

Browse files
hanwen-clusterhanwen-pcluste
authored andcommitted
Use CloudFormation constant to retrieve Stack ARN for Instance Roles
1. Use CloudFormation constant to retrieve Stack ARN for Instance Roles. Assuming `self._format_arn(service="cloudformation", resource=f"stack/{Stack.of(self).stack_name}-*/*")` represents the names of the substack is wrong because the name could be truncated by CloudFormation. For example, the main stack is: arn:aws:cloudformation:eu-west-1:000:stack/integ-tests-u7brkajrdgec5ys8-performance-test/123-d743-11ee-a184-123 The nested stack is arn:aws:cloudformation:eu-west-1:000:stack/integ-tests-u7brkajrdgec5ys8-performance-te-ComputeFleetQueuesNestedStackQueuesNestedS-7R1JJ4IR4CM6/123-d743-11ee-a184-123 2. Remove nested stack DescribeStackResources permission on head nodes. This is a side improvement to keep the commit simple. According to node package and cookbook package, head node does not need DescribeStackResources permission of nested stacks. Signed-off-by: Hanwen <hanwenli@amazon.com>
1 parent ecbe14e commit 2cfd928

File tree

3 files changed

+6
-34
lines changed

3 files changed

+6
-34
lines changed

cli/src/pcluster/templates/cdk_builder_utils.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from aws_cdk import aws_iam as iam
2020
from aws_cdk import aws_lambda as awslambda
2121
from aws_cdk import aws_logs as logs
22+
from aws_cdk import core
2223
from aws_cdk.aws_iam import ManagedPolicy, PermissionsBoundary
2324
from aws_cdk.core import Arn, ArnFormat, CfnDeletionPolicy, CfnTag, Construct, Fn, Stack
2425

@@ -656,10 +657,7 @@ def _build_policy(self) -> List[iam.PolicyStatement]:
656657
"cloudformation:SignalResource",
657658
],
658659
effect=iam.Effect.ALLOW,
659-
resources=[
660-
self._format_arn(service="cloudformation", resource=f"stack/{Stack.of(self).stack_name}/*"),
661-
self._format_arn(service="cloudformation", resource=f"stack/{Stack.of(self).stack_name}-*/*"),
662-
],
660+
resources=[core.Aws.STACK_ID],
663661
),
664662
iam.PolicyStatement(
665663
sid="DcvLicense",
@@ -938,9 +936,7 @@ def _build_policy(self) -> List[iam.PolicyStatement]:
938936
"cloudformation:DescribeStackResource",
939937
],
940938
effect=iam.Effect.ALLOW,
941-
resources=[
942-
self._format_arn(service="cloudformation", resource=f"stack/{Stack.of(self).stack_name}-*/*"),
943-
],
939+
resources=[core.Aws.STACK_ID],
944940
),
945941
iam.PolicyStatement(
946942
sid="DynamoDBTable",
@@ -999,9 +995,7 @@ def _build_policy(self) -> List[iam.PolicyStatement]:
999995
"cloudformation:DescribeStackResource",
1000996
],
1001997
effect=iam.Effect.ALLOW,
1002-
resources=[
1003-
self._format_arn(service="cloudformation", resource=f"stack/{Stack.of(self).stack_name}-*/*"),
1004-
],
998+
resources=[core.Aws.STACK_ID],
1005999
),
10061000
iam.PolicyStatement(
10071001
sid="DynamoDBTable",

cli/tests/pcluster/templates/test_cluster_stack.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -759,18 +759,7 @@ def assert_iam_policy_properties(self, template, resource_name: str):
759759
"Action": "cloudformation:DescribeStackResource",
760760
"Effect": "Allow",
761761
"Resource": {
762-
"Fn::Join": [
763-
"",
764-
[
765-
"arn:",
766-
{"Ref": "AWS::Partition"},
767-
":cloudformation:",
768-
{"Ref": "AWS::Region"},
769-
":",
770-
{"Ref": "AWS::AccountId"},
771-
":stack/clustername-*/*",
772-
],
773-
]
762+
"Ref": "AWS::StackId",
774763
},
775764
"Sid": "CloudFormation",
776765
},

cli/tests/pcluster/templates/test_queues_stack.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -48,18 +48,7 @@
4848
"Action": "cloudformation:DescribeStackResource",
4949
"Effect": "Allow",
5050
"Resource": {
51-
"Fn::Join": [
52-
"",
53-
[
54-
"arn:",
55-
{"Ref": "AWS::Partition"},
56-
":cloudformation:",
57-
{"Ref": "AWS::Region"},
58-
":",
59-
{"Ref": "AWS::AccountId"},
60-
":stack/clustername-*/*",
61-
],
62-
]
51+
"Ref": "AWS::StackId",
6352
},
6453
"Sid": "CloudFormation",
6554
},

0 commit comments

Comments
 (0)