Skip to content

Commit e51b6c3

Browse files
Xin ChenXin Chenbryantbiggs
authored
fix: Correct aws arn partition for service account eks (#235)
Co-authored-by: Xin Chen <[email protected]> Co-authored-by: Bryant Biggs <[email protected]>
1 parent 8ab86ca commit e51b6c3

File tree

2 files changed

+17
-9
lines changed

2 files changed

+17
-9
lines changed

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

+8
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,14 @@ data "aws_iam_policy_document" "this" {
1818
variable = "${replace(statement.value.provider_arn, "/^(.*provider/)/", "")}:sub"
1919
values = [for sa in statement.value.namespace_service_accounts : "system:serviceaccount:${sa}"]
2020
}
21+
22+
# https://aws.amazon.com/premiumsupport/knowledge-center/eks-troubleshoot-oidc-and-irsa/?nc1=h_ls
23+
condition {
24+
test = var.assume_role_condition_test
25+
variable = "${replace(statement.value.provider_arn, "/^(.*provider/)/", "")}:aud"
26+
values = ["sts.amazonaws.com"]
27+
}
28+
2129
}
2230
}
2331
}

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

+9-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ data "aws_iam_policy_document" "cert_manager" {
1717

1818
statement {
1919
actions = ["route53:GetChange"]
20-
resources = ["arn:aws:route53:::change/*"]
20+
resources = ["arn:${local.partition}:route53:::change/*"]
2121
}
2222

2323
statement {
@@ -550,9 +550,9 @@ data "aws_iam_policy_document" "karpenter_controller" {
550550
statement {
551551
actions = ["ec2:RunInstances"]
552552
resources = [
553-
"arn:aws:ec2:*:${local.account_id}:launch-template/*",
554-
"arn:aws:ec2:*:${local.account_id}:security-group/*",
555-
"arn:aws:ec2:*:${local.account_id}:subnet/*",
553+
"arn:${local.partition}:ec2:*:${local.account_id}:launch-template/*",
554+
"arn:${local.partition}:ec2:*:${local.account_id}:security-group/*",
555+
"arn:${local.partition}:ec2:*:${local.account_id}:subnet/*",
556556
]
557557

558558
condition {
@@ -565,10 +565,10 @@ data "aws_iam_policy_document" "karpenter_controller" {
565565
statement {
566566
actions = ["ec2:RunInstances"]
567567
resources = [
568-
"arn:aws:ec2:*::image/*",
569-
"arn:aws:ec2:*:${local.account_id}:instance/*",
570-
"arn:aws:ec2:*:${local.account_id}:volume/*",
571-
"arn:aws:ec2:*:${local.account_id}:network-interface/*",
568+
"arn:${local.partition}:ec2:*::image/*",
569+
"arn:${local.partition}:ec2:*:${local.account_id}:instance/*",
570+
"arn:${local.partition}:ec2:*:${local.account_id}:volume/*",
571+
"arn:${local.partition}:ec2:*:${local.account_id}:network-interface/*",
572572
]
573573
}
574574

@@ -1144,7 +1144,7 @@ resource "aws_iam_role_policy_attachment" "node_termination_handler" {
11441144
data "aws_iam_policy_document" "vpc_cni" {
11451145
count = var.create_role && var.attach_vpc_cni_policy ? 1 : 0
11461146

1147-
# arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy
1147+
# arn:${local.partition}:iam::aws:policy/AmazonEKS_CNI_Policy
11481148
dynamic "statement" {
11491149
for_each = var.vpc_cni_enable_ipv4 ? [1] : []
11501150
content {

0 commit comments

Comments
 (0)