Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add additional permissions to Karpenter EKS IRSA role for native node termination handling support #304

Merged
merged 8 commits into from
Nov 21, 2022
1 change: 1 addition & 0 deletions modules/iam-role-for-service-accounts-eks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ No modules.
| [aws_iam_policy_document.velero](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
| [aws_iam_policy_document.vpc_cni](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
| [aws_partition.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/partition) | data source |
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |

## Inputs

Expand Down
2 changes: 2 additions & 0 deletions modules/iam-role-for-service-accounts-eks/main.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
data "aws_partition" "current" {}
data "aws_caller_identity" "current" {}

data "aws_region" "current" {}

locals {
account_id = data.aws_caller_identity.current.account_id
partition = data.aws_partition.current.partition
Expand Down
28 changes: 21 additions & 7 deletions modules/iam-role-for-service-accounts-eks/policies.tf
Original file line number Diff line number Diff line change
Expand Up @@ -509,24 +509,25 @@ resource "aws_iam_role_policy_attachment" "fsx_lustre_csi" {
# Karpenter Controller Policy
################################################################################

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

statement {
actions = [
"ec2:CreateLaunchTemplate",
"ec2:CreateFleet",
"ec2:CreateLaunchTemplate",
"ec2:CreateTags",
"ec2:DescribeLaunchTemplates",
"ec2:DescribeAvailabilityZones",
"ec2:DescribeImages",
"ec2:DescribeImages",
"ec2:DescribeInstances",
"ec2:DescribeSecurityGroups",
"ec2:DescribeSubnets",
"ec2:DescribeInstanceTypes",
"ec2:DescribeInstanceTypeOfferings",
"ec2:DescribeAvailabilityZones",
"ec2:DescribeInstanceTypes",
"ec2:DescribeLaunchTemplates",
"ec2:DescribeSecurityGroups",
"ec2:DescribeSpotPriceHistory",
"ec2:DescribeSubnets",
"pricing:GetProducts",
]

Expand Down Expand Up @@ -583,6 +584,19 @@ data "aws_iam_policy_document" "karpenter_controller" {
actions = ["iam:PassRole"]
resources = var.karpenter_controller_node_iam_role_arns
}

statement {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets make this dynamic if an SQS queue arn is provided

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bryantbiggs what do you mean with dynamic?
i've already created a var for karpenter_sqs_queue_arn and a local

sid = "KarpenterEventPolicySQS"
effect = "Allow"
resources = ["arn:aws:sqs:${data.aws_region.current.name}:${local.account_id}:${var.karpenter_controller_cluster_id}"]
Copy link
Member

@bryantbiggs bryantbiggs Nov 17, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets add a variable for this karpenter_sqs_queue_arn since we are not guaranteed that the queue name will always be the cluster name


actions = [
"sqs:DeleteMessage",
"sqs:GetQueueAttributes",
"sqs:GetQueueUrl",
"sqs:ReceiveMessage",
]
}
}

resource "aws_iam_policy" "karpenter_controller" {
Expand Down