Skip to content

Commit

Permalink
Use mapping to conditionally select services for iam:PassRole
Browse files Browse the repository at this point in the history
  • Loading branch information
artem-nefedov committed Aug 30, 2024
1 parent 910a4a4 commit 441e058
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ Parameters:
ClusterName:
Type: String
Description: "EKS cluster name"
Mappings:
Partition:
aws:
PassRoleToServices: ["ec2.amazonaws.com"]
aws-cn:
PassRoleToServices: ["ec2.amazonaws.com", "ec2.amazonaws.com.cn"]
Resources:
KarpenterNodeRole:
Type: "AWS::IAM::Role"
Expand Down Expand Up @@ -212,7 +218,15 @@ Resources:
"Action": "iam:PassRole",
"Condition": {
"StringEquals": {
"iam:PassedToService": "ec2.${AWS::URLSuffix}"
"iam:PassedToService": {
"Fn::FindInMap": [
"Partition",
{
"Ref": "AWS::Partition"
},
"PassRoleToServices"
]
}
}
}
},
Expand Down
10 changes: 9 additions & 1 deletion website/content/en/preview/reference/cloudformation.md
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,15 @@ This gives EC2 permission explicit permission to use the `KarpenterNodeRole-${Cl
"Action": "iam:PassRole",
"Condition": {
"StringEquals": {
"iam:PassedToService": "ec2.${AWS::URLSuffix}"
"iam:PassedToService": {
"Fn::FindInMap": [
"Partition",
{
"Ref": "AWS::Partition"
},
"PassRoleToServices"
]
}
}
}
}
Expand Down

0 comments on commit 441e058

Please sign in to comment.