Skip to content

aws_eks: EKS Cluster Creation Fails Due to Invalid Cluster ARN in IAM Policy #35254

@Malok12

Description

@Malok12

Describe the bug

EKS cluster creation through AWS Service Catalog fails with an AccessDenied error due to malformed resource ARNs in the automatically generated IAM policy. The CDK generates an IAM policy for the EksEksClusterCreationRole that contains [object Object] instead of the actual cluster name or "*" in the resource ARN, causing AWS to reject EKS API calls even though the role has the correct permissions.

This is a synthesis-time vs runtime parameter resolution issue where CDK attempts to build specific resource ARNs during template synthesis using runtime parameters that are available during Service Catalog product deployment.

Lambda Functions with Faulty Role Generation
The error originates from these automatically generated Lambda functions:

  • OnEventHandler42BEBAE0 - Uses role: OnEventHandlerServiceRole15A26729
  • IsCompleteHandler7073F4DA - Uses role: IsCompleteHandlerServiceRole5810CC58
  • ProviderframeworkonEvent83C1D0A7 - Framework wrapper function

The OnEventHandler function is specifically responsible for calling eks:CreateCluster and uses the problematic EksClusterCreationRole.

Regression Issue

  • Select this option if this issue appears to be a regression.

Last Known Working CDK Library Version

No response

Expected Behavior

The EKS cluster should be created successfully through Service Catalog. Since Service Catalog creates a new Lambda function and role instance for each deployment, the CDK should properly resolve the CloudFormation parameter in the IAM policy resource ARN at deployment time.

The correctly generated policy should look like this:

  {
    "Action": [
      "eks:CreateCluster",
      "eks:CreateFargateProfile",
      "eks:DeleteCluster",
      "eks:DescribeCluster",
      "eks:DescribeUpdate",
      "eks:TagResource",
      "eks:UntagResource",
      "eks:UpdateClusterConfig",
      "eks:UpdateClusterVersion"
    ],
    "Effect": "Allow",
    "Resource": [
      {
        "Fn::Sub": "arn:${AWS::Partition}:eks:${AWS::Region}:${AWS::AccountId}:cluster/${cloudformation.parameter.cluster_name}"
      }
    ]
  }

This would create a specific policy for each deployment with the correct cluster name resolved at CloudFormation execution time, allowing the OnEventHandler Lambda function to successfully call eks:CreateCluster on the specific cluster being deployed. Since each
Service Catalog deployment creates its own Lambda function and role instance, this approach would provide proper least-privilege access while maintaining security.

Current Behavior

Cluster creation fails when the CDK attempts to generate specific resource ARNs using CloudFormation parameters that are only available at runtime. During synthesis, CDK cannot resolve the runtime parameter and defaults to JavaScript's string representation of an object, resulting in [object Object] in the policy resource ARN.

Error message:
Received response status [FAILED] from custom resource. Message returned: User: arn:aws:sts::443370674873:assumed-role/SC-443370674873-pp-d2iqrp-EksEksClusterCreationRole-ZMV8TCRtNZp7/AWSCDK.EKSCluster.Create.ce179586-8e76-49d6-955d-3618be0c416b is not authorized to perform: eks:CreateCluster on resource: arn:aws:eks:eu-west-1:443370674873:cluster/{clustername}

The issue occurs because CDK generates an IAM policy that attempts to use a CloudFormation parameter (cluster name) in the resource ARN during synthesis time, but the parameter is not available until Service Catalog deployment. This results in the following malformed policy:

  {
    "Action": [
      "eks:CreateCluster",
      "eks:CreateFargateProfile",
      "eks:DeleteCluster",
      "eks:DescribeCluster",
      "eks:DescribeUpdate",
      "eks:TagResource",
      "eks:UntagResource",
      "eks:UpdateClusterConfig",
      "eks:UpdateClusterVersion"
    ],
    "Effect": "Allow",
    "Resource": [
      {
        "Fn::Join": [
          "",
          [
            "arn:",
            {"Ref": "AWS::Partition"},
            ":eks:",
            {"Ref": "AWS::Region"},
            ":",
            {"Ref": "AWS::AccountId"},
            ":cluster/[object Object]"
          ]
        ]
      }
    ]
  }

The policy contains ":cluster/[object Object]" instead of a "*" or from the cloudformation parameter the cluster_name, causing AWS IAM to deny the eks:CreateCluster action since the resource ARN doesn't match.

Reproduction Steps

  1. Create a CDK stack that defines an EKS cluster with a CloudFormation parameter for cluster name:
  2. Run CDK synthesis to generate the CloudFormation template: cdk synth
  3. Examine the generated CloudFormation template and locate the EksClusterCreationRole IAM policy
  4. Observe that the policy contains [object Object] in the resource ARN instead of the CloudFormation parameter reference or wildcard

Possible Solution

The CDK should handle CloudFormation parameters properly when generating IAM policies for the EKS Custom Resource Provider. There are two viable approaches:

Option 1: Use wildcard resources (Recommended)
Modify the EKS construct to generate IAM policies with wildcard (*) resources instead of attempting to resolve runtime parameters:

  {
    "Action": [
      "eks:CreateCluster",
      "eks:DeleteCluster",
      "eks:DescribeCluster"
    ],
    "Effect": "Allow",
    "Resource": "*"
  }

Option 2: Proper parameter resolution
Ensure the CDK correctly passes CloudFormation parameters to the Custom Resource Provider's IAM policy using Fn::Sub:

  {
    "Action": [
      "eks:CreateCluster",
      "eks:DeleteCluster",
      "eks:DescribeCluster"
    ],
    "Effect": "Allow",
    "Resource": {
      "Fn::Sub": "arn:${AWS::Partition}:eks:${AWS::Region}:${AWS::AccountId}:cluster/${{cloudformation.parameter.cluster_name}"
    }
  }

Additional Information/Context

No response

AWS CDK Library version (aws-cdk-lib)

2.210.0

AWS CDK CLI version

2.1024.0

Node.js Version

11.5.2

OS

Windows

Language

Python

Language Version

3.11.0

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    @aws-cdk/aws-eksRelated to Amazon Elastic Kubernetes ServicebugThis issue is a bug.effort/mediumMedium work item – several days of effortp2

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions