Skip to content

Commit

Permalink
fix: Correct aws arn partition for service account eks (#235)
Browse files Browse the repository at this point in the history
Co-authored-by: Xin Chen <chenxin@konvery.com>
Co-authored-by: Bryant Biggs <bryantbiggs@gmail.com>
  • Loading branch information
3 people committed Apr 22, 2022
1 parent 8ab86ca commit e51b6c3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
8 changes: 8 additions & 0 deletions modules/iam-role-for-service-accounts-eks/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ data "aws_iam_policy_document" "this" {
variable = "${replace(statement.value.provider_arn, "/^(.*provider/)/", "")}:sub"
values = [for sa in statement.value.namespace_service_accounts : "system:serviceaccount:${sa}"]
}

# https://aws.amazon.com/premiumsupport/knowledge-center/eks-troubleshoot-oidc-and-irsa/?nc1=h_ls
condition {
test = var.assume_role_condition_test
variable = "${replace(statement.value.provider_arn, "/^(.*provider/)/", "")}:aud"
values = ["sts.amazonaws.com"]
}

}
}
}
Expand Down
18 changes: 9 additions & 9 deletions modules/iam-role-for-service-accounts-eks/policies.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ data "aws_iam_policy_document" "cert_manager" {

statement {
actions = ["route53:GetChange"]
resources = ["arn:aws:route53:::change/*"]
resources = ["arn:${local.partition}:route53:::change/*"]
}

statement {
Expand Down Expand Up @@ -550,9 +550,9 @@ data "aws_iam_policy_document" "karpenter_controller" {
statement {
actions = ["ec2:RunInstances"]
resources = [
"arn:aws:ec2:*:${local.account_id}:launch-template/*",
"arn:aws:ec2:*:${local.account_id}:security-group/*",
"arn:aws:ec2:*:${local.account_id}:subnet/*",
"arn:${local.partition}:ec2:*:${local.account_id}:launch-template/*",
"arn:${local.partition}:ec2:*:${local.account_id}:security-group/*",
"arn:${local.partition}:ec2:*:${local.account_id}:subnet/*",
]

condition {
Expand All @@ -565,10 +565,10 @@ data "aws_iam_policy_document" "karpenter_controller" {
statement {
actions = ["ec2:RunInstances"]
resources = [
"arn:aws:ec2:*::image/*",
"arn:aws:ec2:*:${local.account_id}:instance/*",
"arn:aws:ec2:*:${local.account_id}:volume/*",
"arn:aws:ec2:*:${local.account_id}:network-interface/*",
"arn:${local.partition}:ec2:*::image/*",
"arn:${local.partition}:ec2:*:${local.account_id}:instance/*",
"arn:${local.partition}:ec2:*:${local.account_id}:volume/*",
"arn:${local.partition}:ec2:*:${local.account_id}:network-interface/*",
]
}

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

# arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy
# arn:${local.partition}:iam::aws:policy/AmazonEKS_CNI_Policy
dynamic "statement" {
for_each = var.vpc_cni_enable_ipv4 ? [1] : []
content {
Expand Down

0 comments on commit e51b6c3

Please sign in to comment.