Description
Describe the bug
When provisioning an EKS cluster in Auto Mode using the L2 construct within the aws_eks_v2_alpha
library, construct users may elect to define their own node classes and pools, disabling the default node classes and pools as a result. After defining their own node classes and pools, they must create/use an IAM role to act as the "Node Role". This role must be explicitly granted access to the cluster.
When creating an access entry, the following must be specified:
- Principal ARN
- Type
- Access Policies
However, the grantAccess method on the Cluster class does not currently support specifying a type argument, instead defaulting to STANDARD
- which is incorrect for an Node Role when using EKS Auto Mode which requires the type EC2
.
Within CloudFormation, the AWS::EKS::AccessEntry (now) supports the following types:
STANDARD
FARGATE_LINUX
EC2_LINUX
EC2_WINDOWS
EC2
(for EKS Auto Mode)HYBRID_LINUX
HYPERPOD_LINUX
Even if grantAccess
were to accept a type, currently AccessEntry only accepts the following types:
STANDARD
FARGATE_LINUX
EC2_LINUX
EC2_WINDOWS
Regression Issue
- Select this option if this issue appears to be a regression.
Last Known Working CDK Library Version
No response
Expected Behavior
The grantAccess
method should accept and honour a given type
argument so EKS Node Roles can be correctly authorised.
Current Behavior
When an IAM role (intended to be used as an EKS Node Role) is granted access via grantAccess
, an access entry of type STANDARD
is created which prevents node creation.
Reproduction Steps
- Define an EKS cluster using the L2
aws_eks_v2_alpha
construct and specify an empty node pool within the compute config - Use/create an appropriate IAM Role intended to be used as an EKS Node Role
- Define at least one custom node class and pool
- Grant IAM Role access to the cluster via
cluster.grantAccess
After provisioning the above, the access entry for the IAM Role is only STANDARD
and as a result no nodes are created.
Possible Solution
Suggested Solution
- In
Cluster
, for thegrantAccess
method, accept an optionaltype
argument and pass it along accordingly - Update the list of available choices in
AccessEntryType
to reflect that which is available within CloudFormation
Workarounds
Option 1
A manual workaround would be to delete the corresponding access entry (as the type
can't be changed), then manually recreate it with the type EC2
. Afterwards nodes will start being created as expected.
Option 2
Use an L1 CfnAccessEntry
construct to create the required access entry in lieu of using grantAccess
on the L2 cluster construct.
Option 3
Use an escape hatch to change the type
property in the corresponding AccessEntry
(Python example):
# Define the cluster
cluster = ...
# Define an IAM Role to use as the EKS Node
node_role = ...
# Grant the node role access to the cluster
cluster.grant_access(
'DefaultNodeRoleClusterAdminAccess',
node_role.role_arn,
[eks_v2.AccessPolicy.from_access_policy_name('AmazonEKSAutoNodePolicy', access_scope_type=eks_v2.AccessScopeType.CLUSTER)]
)
# Find the corresponding L1 CfnAccessEntry for the previously referenced node role
access_entry = next(filter(
lambda c: isinstance(c, eks_v2.AccessEntry) and c.node.default_child.principal_arn == node_role.role_arn,
cluster.node.children
))
# Use an escape-hatch to override the Access Entry type for the node role from STANDARD to EC2
access_entry.node.default_child.add_property_override('Type', 'EC2')
Additional Information/Context
If relevant, this was observed on a fully-private cluster but shouldn't be a factor for this issue.
AWS CDK Library version (aws-cdk-lib)
2.182.0
AWS CDK CLI version
2.1012.0 (build e4c1f15)
Node.js Version
v22.14.0
OS
macOS
Language
Python
Language Version
3.11.11
Other information
No response