Skip to content

Commit d6865d2

Browse files
feat: Add additional permissions to Karpenter EKS IRSA role for native node termination handling support (#304)
Co-authored-by: Bryant Biggs <[email protected]>
1 parent 3ec0f0f commit d6865d2

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

modules/iam-role-for-service-accounts-eks/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ No modules.
206206
| <a name="input_karpenter_controller_cluster_id"></a> [karpenter\_controller\_cluster\_id](#input\_karpenter\_controller\_cluster\_id) | Cluster ID where the Karpenter controller is provisioned/managing | `string` | `"*"` | no |
207207
| <a name="input_karpenter_controller_node_iam_role_arns"></a> [karpenter\_controller\_node\_iam\_role\_arns](#input\_karpenter\_controller\_node\_iam\_role\_arns) | List of node IAM role ARNs Karpenter can use to launch nodes | `list(string)` | <pre>[<br> "*"<br>]</pre> | no |
208208
| <a name="input_karpenter_controller_ssm_parameter_arns"></a> [karpenter\_controller\_ssm\_parameter\_arns](#input\_karpenter\_controller\_ssm\_parameter\_arns) | List of SSM Parameter ARNs that contain AMI IDs launched by Karpenter | `list(string)` | <pre>[<br> "arn:aws:ssm:*:*:parameter/aws/service/*"<br>]</pre> | no |
209+
| <a name="input_karpenter_sqs_queue_arn"></a> [karpenter\_sqs\_queue\_arn](#input\_karpenter\_sqs\_queue\_arn) | (Optional) ARN of SQS used by Karpenter when native node termination handling is enabled | `string` | `null` | no |
209210
| <a name="input_karpenter_subnet_account_id"></a> [karpenter\_subnet\_account\_id](#input\_karpenter\_subnet\_account\_id) | Account ID of where the subnets Karpenter will utilize resides. Used when subnets are shared from another account | `string` | `""` | no |
210211
| <a name="input_karpenter_tag_key"></a> [karpenter\_tag\_key](#input\_karpenter\_tag\_key) | Tag key (`{key = value}`) applied to resources launched by Karpenter through the Karpenter provisioner | `string` | `"karpenter.sh/discovery"` | no |
211212
| <a name="input_max_session_duration"></a> [max\_session\_duration](#input\_max\_session\_duration) | Maximum CLI/API session duration in seconds between 3600 and 43200 | `number` | `null` | no |

modules/iam-role-for-service-accounts-eks/policies.tf

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -509,24 +509,25 @@ resource "aws_iam_role_policy_attachment" "fsx_lustre_csi" {
509509
# Karpenter Controller Policy
510510
################################################################################
511511

512-
# curl -fsSL https://karpenter.sh/v0.6.1/getting-started/cloudformation.yaml
512+
# https://github.com/aws/karpenter/blob/502d275cc330fb0f2435b124935c49632146d945/website/content/en/v0.19.0/getting-started/getting-started-with-eksctl/cloudformation.yaml#L34
513513
data "aws_iam_policy_document" "karpenter_controller" {
514514
count = var.create_role && var.attach_karpenter_controller_policy ? 1 : 0
515515

516516
statement {
517517
actions = [
518-
"ec2:CreateLaunchTemplate",
519518
"ec2:CreateFleet",
519+
"ec2:CreateLaunchTemplate",
520520
"ec2:CreateTags",
521-
"ec2:DescribeLaunchTemplates",
521+
"ec2:DescribeAvailabilityZones",
522+
"ec2:DescribeImages",
522523
"ec2:DescribeImages",
523524
"ec2:DescribeInstances",
524-
"ec2:DescribeSecurityGroups",
525-
"ec2:DescribeSubnets",
526-
"ec2:DescribeInstanceTypes",
527525
"ec2:DescribeInstanceTypeOfferings",
528-
"ec2:DescribeAvailabilityZones",
526+
"ec2:DescribeInstanceTypes",
527+
"ec2:DescribeLaunchTemplates",
528+
"ec2:DescribeSecurityGroups",
529529
"ec2:DescribeSpotPriceHistory",
530+
"ec2:DescribeSubnets",
530531
"pricing:GetProducts",
531532
]
532533

@@ -583,6 +584,20 @@ data "aws_iam_policy_document" "karpenter_controller" {
583584
actions = ["iam:PassRole"]
584585
resources = var.karpenter_controller_node_iam_role_arns
585586
}
587+
588+
dynamic "statement" {
589+
for_each = var.karpenter_sqs_queue_arn != null ? [1] : []
590+
591+
content {
592+
actions = [
593+
"sqs:DeleteMessage",
594+
"sqs:GetQueueAttributes",
595+
"sqs:GetQueueUrl",
596+
"sqs:ReceiveMessage",
597+
]
598+
resources = [var.karpenter_sqs_queue_arn]
599+
}
600+
}
586601
}
587602

588603
resource "aws_iam_policy" "karpenter_controller" {

modules/iam-role-for-service-accounts-eks/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,12 @@ variable "karpenter_subnet_account_id" {
215215
default = ""
216216
}
217217

218+
variable "karpenter_sqs_queue_arn" {
219+
description = "(Optional) ARN of SQS used by Karpenter when native node termination handling is enabled"
220+
type = string
221+
default = null
222+
}
223+
218224
# AWS Load Balancer Controller
219225
variable "attach_load_balancer_controller_policy" {
220226
description = "Determines whether to attach the Load Balancer Controller policy to the role"

0 commit comments

Comments
 (0)