Skip to content

Missing amazonaws.com.cn condition in PassRole as required for AWS CN #3636

@ctav4

Description

@ctav4

Description

Our Karpenter instance runs on EKS in cn-northwest-1 (China). The logs indicate the following error: no identity-based policy allows the iam:PassRole action. I believe this issue was addressed in PR 3422. However, I noticed that the latest PR 3539 appears to have reverted the fix. @bryantbiggs @antonbabenko, could you please review this?

Versions

  • Module version:
    v21.15.1

  • Terraform version:
    v1.13.5

Reproduction Code

Code:

module "karpenter" {
  source = "terraform-aws-modules/eks/aws//modules/karpenter"

  iam_role_name      = "karpenter-controller-pod-identity"
  iam_policy_name    = "karpenter-controller-pod-identity-custom"
  node_iam_role_name = "karpenter-node-iam-role"

  iam_role_use_name_prefix      = false
  node_iam_role_use_name_prefix = false
  iam_policy_use_name_prefix    = false

  cluster_name = var.cluster_name

  node_iam_role_additional_policies = {
    AmazonSSMManagedInstanceCore = "arn:${data.aws_partition.current.partition}:iam::aws:policy/AmazonSSMManagedInstanceCore"
  }

  enable_spot_termination = false
}

Then login to China cn-northwest-1.

terraform init
terraform apply

With this config I see this output on terraform state file for data.aws_service_principal.ec2:

terraform state show 'module.example.module.karpenter.module.karpenter.data.aws_service_principal.ec2[0]'
# module.example.module.karpenter.module.karpenter.data.aws_service_principal.ec2[0]:
data "aws_service_principal" "ec2" {
    id           = "ec2.cn-northwest-1.amazonaws.com"
    name         = "ec2.amazonaws.com"
    region       = "cn-northwest-1"
    service_name = "ec2"
    suffix       = "amazonaws.com"
}

On AWS Console I see this:

Image

Finally, the Karpenter logs shows this error:

karpenter-5fb47b9fc6-9zwxb controller {"level":"ERROR","time":"2026-01-28T17:11:36.570Z","logger":"controller","message":"unauthorized to call ec2:RunInstances","commit":"f29079c","controller":"nodeclass","controllerGroup":"karpenter.k8s.aws","controllerKind":"EC2NodeClass","EC2NodeClass":{"name":"default"},"namespace":"","name":"default","reconcileID":"8dd0479a-0776-4bb9-b09e-0684df6fd449","aws-error-code":"UnauthorizedOperation","aws-operation-name":"RunInstances","aws-request-id":"4a96ba94-118d-4988-a34c-8b8e0992a811","aws-service-name":"EC2","aws-status-code":403,"error":"operation error EC2: RunInstances, https response error StatusCode: 403, RequestID: 4a96ba94-118d-4988-a34c-8b8e0992a811, api error UnauthorizedOperation: You are not authorized to perform this operation. User: arn:aws-cn:sts::123456123456:assumed-role/karpenter-controller-pod-identity/eks-example-karpenter--86b1bb05-916c-4bd3-bfb0-0e7dff5cc38a is not authorized to perform: iam:PassRole on resource: arn:aws-cn:iam::123456123456:role/karpenter-node-iam-role because no identity-based policy allows the iam:PassRole action. Encoded authorization failure message: ... (aws-error-code=UnauthorizedOperation, aws-operation-name=RunInstances, aws-request-id=4a96ba94-118d-4988-a34c-8b8e0992a811, aws-service-name=EC2, aws-status-code=403)"}

Expected behavior

I was expecting to see name = "ec2.amazonaws.com.cn" on terraform state file after the terraform apply:

data "aws_service_principal" "ec2" {
    id           = "ec2.cn-northwest-1.amazonaws.com"
    name         = "ec2.amazonaws.com.cn"
    region       = "cn-northwest-1"
    service_name = "ec2"
    suffix       = "amazonaws.com"
}

Actual behavior

Currently I see this output on terraform state file:

data "aws_service_principal" "ec2" {
    id           = "ec2.cn-northwest-1.amazonaws.com"
    name         = "ec2.amazonaws.com"
    region       = "cn-northwest-1"
    service_name = "ec2"
    suffix       = "amazonaws.com"
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions