Skip to content

Conversation

@pahud
Copy link
Contributor

@pahud pahud commented Dec 9, 2025

Issue # (if applicable)

Closes #34394.

Reason for this change

When provisioning an EKS cluster in Auto Mode with custom node roles, users need to grant the node role access to the cluster with the EC2 access entry type. Currently, the grantAccess() method doesn't support specifying the access entry type, defaulting to STANDARD, which prevents nodes from joining Auto Mode clusters.

Additionally, the AccessEntryType enum is missing three CloudFormation-supported types: EC2, HYBRID_LINUX, and HYPERPOD_LINUX.

Description of changes

This PR adds support for specifying access entry types in the grantAccess() method and extends the AccessEntryType enum with missing CloudFormation-supported values.

Changes made:

  • Extended AccessEntryType enum with three new values:
    • EC2 - For EKS Auto Mode node roles
    • HYBRID_LINUX - For EKS Hybrid Nodes
    • HYPERPOD_LINUX - For Amazon SageMaker HyperPod
  • Added optional accessEntryType parameter to Cluster.grantAccess() method
  • Updated private addToAccessEntry() method to pass type through to AccessEntry constructor
  • Applied changes to both @aws-cdk/aws-eks-v2-alpha (alpha) and aws-cdk-lib/aws-eks (stable) packages

API changes:

// Before (still works - backward compatible)
cluster.grantAccess('MyAccess', roleArn, [policy]);

// After (new capability)
cluster.grantAccess('MyAccess', roleArn, [policy], AccessEntryType.EC2);

CloudFormation impact:

  • When accessEntryType is provided: Type property is set in AWS::EKS::AccessEntry
  • When accessEntryType is not provided: Type property remains undefined (backward compatible)

No breaking changes: This is a fully backward-compatible feature addition. The new parameter is optional and placed at the end of the method signature. All existing code continues to work without modification.

Describe any new or updated permissions being added

N/A - No new IAM permissions required. This change only exposes existing CloudFormation access entry types through the CDK L2 API.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

- Add `grantAccessWithType` method to EKS cluster for type-safe access entry management
- Update `AccessEntry` class to support access entry type configuration
- Add integration test for EKS grant access with type functionality
- Update README documentation with new access entry type feature
- Generate snapshot files for integration test validation
- Enable fine-grained access control for EKS cluster users and roles
@github-actions github-actions bot added feature-request A feature should be added or improved. p2 labels Dec 9, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team December 9, 2025 22:32
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Dec 9, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2025

⚠️ Experimental Feature: This security report is currently in experimental phase. Results may include false positives and the rules are being actively refined.
Please try merge from main to avoid findings unrelated to the PR.


TestsPassed ✅SkippedFailed
Security Guardian Results144 ran144 passed
TestResult
No test annotations available

@github-actions
Copy link
Contributor

github-actions bot commented Dec 9, 2025

⚠️ Experimental Feature: This security report is currently in experimental phase. Results may include false positives and the rules are being actively refined.
Please try merge from main to avoid findings unrelated to the PR.


TestsPassed ✅SkippedFailed
Security Guardian Results with resolved templates144 ran144 passed
TestResult
No test annotations available

pahud added 2 commits January 13, 2026 12:59
- Add concise README documentation for EC2, HYBRID_LINUX, and HYPERPOD_LINUX access entry types
- Enhance JSDoc comments with detailed usage guidance and AWS service links
- Document access policy constraints for non-STANDARD types
- Update both stable and alpha packages consistently

Addresses missing documentation for EKS Auto Mode, Hybrid Nodes, and SageMaker HyperPod integration.
@aws-cdk-automation aws-cdk-automation added the pr/needs-further-review PR requires additional review from our team specialists due to the scope or complexity of changes. label Jan 13, 2026
…hanges

- Update EKS grant access integration test snapshots with new asset hashes
- Regenerate CloudFormation templates for cluster and kubectl providers
- Update manifest and tree JSON files to reflect current state
- Modify access entry implementation in both alpha and stable packages
- Add test coverage for access entry type functionality
- Update integration test to validate access entry type grants
- Add new asset snapshot for EKS grant access integration test
- Reorganize asset directory structure with updated hash references
- Update cfn-response.js, consts.js, and util.js asset files
- Add new framework.js asset file to custom resource handler
- Update CloudFormation template and assets manifest
- Refresh tree.json and manifest.json for snapshot consistency
- Remove obsolete asset files from previous snapshot version
@pahud pahud self-assigned this Jan 13, 2026
@pahud pahud marked this pull request as ready for review January 13, 2026 21:03
pahud added 3 commits January 13, 2026 17:18
Add missing declare statements for 'cluster' and 'nodeRole' variables
in the access entry type documentation example to fix Rosetta compilation.
@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Jan 14, 2026
Copy link
Member

@Abogical Abogical left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think grants in general should now use Grant classes instead of using grantX() methods. See #36616

I don't this will be accepted by our current linters.

Edit: This only applies to new grants.

@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Jan 14, 2026
@Abogical Abogical self-requested a review January 14, 2026 10:54
* @returns {void}
*/
private addToAccessEntry(id: string, principal: string, policies: IAccessPolicy[]) {
private addToAccessEntry(id: string, principal: string, policies: IAccessPolicy[], accessEntryType?: AccessEntryType) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is a private method we can safely be able to change the API for this. We should change the arguments to take in a props argument. Something like:

Suggested change
private addToAccessEntry(id: string, principal: string, policies: IAccessPolicy[], accessEntryType?: AccessEntryType) {
interface AddAccessEntryOptions {
id: string,
principal: string,
policies: IAccessPolicy[],
accessEntryType?: AccessEntryType
}
private addToAccessEntry(props: AddAccessEntryOptions) {

This would be helpful in case we need to add further arguments to the method; It will be easier to update in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Good catch! I'm on the way.

- Extract AddAccessEntryOptions interface for private addToAccessEntry method
- Refactor addToAccessEntry to accept a props object instead of individual parameters
- Update grantAccess to pass options object to addToAccessEntry
- Apply changes to both stable and alpha EKS packages
- Improves API stability for future method expansions
pahud added 5 commits January 14, 2026 11:20
- Fix indentation from 3 spaces to 2 spaces for @MethodMetadata decorator
- Apply fix to both stable and alpha EKS packages
- Fix closing */ comment indentation to match ESLint rules
- Applied to both stable and alpha EKS packages
- Add GrantAccessOptions interface to provide extensible options
- Update grantAccess method to use options object instead of direct accessEntryType parameter
- Update unit tests to use new options object syntax
- Apply changes to both stable and alpha EKS packages
- Makes API more consistent and easier to extend in the future
@Abogical Abogical added the pr/requires-two-approvers This PR is critical (e.g., security, broadly-impacting) and requires 2 approvers to be merged. label Jan 15, 2026
pahud added 2 commits January 15, 2026 14:45
- Add accessEntryType property to AccessEntry class to track entry type
- Validate restricted access entry types (EC2, HYBRID_LINUX, HYPERPOD_LINUX) cannot have policies attached in addAccessPolicies()
- Throw ValidationError with descriptive message when attempting to add policies to restricted types
- Add comprehensive unit tests for both restricted and allowed access entry types
- Apply changes to both aws-cdk-lib and aws-eks-v2-alpha packages
- Prevents invalid configurations where certain access entry types should not have access policies
- Import Token from aws-cdk-lib/core in both access-entry.ts files
- Add Token.isUnresolved() check before validating access policies length in constructor
- Add Token.isUnresolved() check before validating access policies length in addAccessPolicies method
- Prevent validation errors when access policies are defined as unresolved tokens (e.g., from Fn.importValue or other dynamic sources)
- Apply changes to both @aws-cdk/aws-eks-v2-alpha and aws-cdk-lib packages for consistency
@pahud
Copy link
Contributor Author

pahud commented Jan 15, 2026

self-reviewed with no risks.

@pahud pahud requested a review from Abogical January 15, 2026 20:08
Comment on lines 405 to 409
// Validate that restricted access entry types cannot have access policies
const restrictedTypes = [AccessEntryType.EC2, AccessEntryType.HYBRID_LINUX, AccessEntryType.HYPERPOD_LINUX];
if (this.accessEntryType && restrictedTypes.includes(this.accessEntryType) && newAccessPolicies.length > 0) {
throw new ValidationError(`Access entry type '${this.accessEntryType}' cannot have access policies attached. Use AccessEntryType.STANDARD for access entries that require policies.`, this);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As this validation logic is repeated, it can be moved to a single re-usable private method which can be re-used here and in the constructor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed.

const restrictedTypes = [AccessEntryType.EC2, AccessEntryType.HYBRID_LINUX, AccessEntryType.HYPERPOD_LINUX];
if (props.accessEntryType && restrictedTypes.includes(props.accessEntryType) && props.accessPolicies.length > 0) {
if (props.accessEntryType && restrictedTypes.includes(props.accessEntryType) &&
!Token.isUnresolved(props.accessPolicies) && props.accessPolicies.length > 0) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch to check for tokens

pahud added 2 commits January 20, 2026 09:55
- Extract duplicate validation logic into private validateAccessPoliciesForRestrictedTypes method
- Remove repeated restricted types array and validation checks from constructor and addAccessPolicies
- Add comprehensive JSDoc documentation for the new private method
- Apply changes to both aws-eks and aws-eks-v2-alpha packages for consistency
- Improves code maintainability and reduces duplication across validation points
- Add missing closing brace for validateAccessPolicies method
- Fixes syntax error that prevented proper method termination
- Ensures accessEntryRef getter is properly defined after validation logic
pahud added 4 commits January 23, 2026 20:41
- Replace old AWS CLI layer asset with updated version
- Update asset hashes and S3 object keys in CloudFormation template
- Rename EC2 role and access entry resources for clarity
- Remove HYBRID_LINUX and HYPERPOD access entry types from test
- Update manifest and tree.json snapshots to reflect changes
- Add ClusterClusterAdminRoleAccessF2BFF759 dependency to kubectl-ready output
@mergify
Copy link
Contributor

mergify bot commented Feb 3, 2026

Thank you for contributing! Your pull request will be automatically updated and merged (do not update manually, and be sure to allow changes to be pushed to your fork).

pahud added 2 commits February 3, 2026 11:53
- Separate type-only imports using `type` keyword in access-entry.ts files
- Remove duplicate import statements in cluster.ts files
- Consolidate imports from './access-entry' module with proper type separation
- Apply consistent import organization pattern across aws-eks and aws-eks-v2-alpha packages
- Align with established type-only import enforcement standards
@aws-cdk-automation aws-cdk-automation removed the pr/needs-further-review PR requires additional review from our team specialists due to the scope or complexity of changes. label Feb 3, 2026
@mergify
Copy link
Contributor

mergify bot commented Feb 3, 2026

Thank you for contributing! Your pull request will be automatically updated and merged (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify
Copy link
Contributor

mergify bot commented Feb 3, 2026

Merge Queue Status

✅ The pull request has been merged at 29c3210

This pull request spent 39 minutes 43 seconds in the queue, including 28 minutes 30 seconds running CI.
The checks were run in-place.

Required conditions to merge

@mergify mergify bot merged commit cc059c6 into aws:main Feb 3, 2026
22 of 23 checks passed
@github-actions
Copy link
Contributor

github-actions bot commented Feb 3, 2026

Comments on closed issues and PRs are hard for our team to see.
If you need help, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 3, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

contribution/core This is a PR that came from AWS. feature-request A feature should be added or improved. p2 pr/requires-two-approvers This PR is critical (e.g., security, broadly-impacting) and requires 2 approvers to be merged.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

aws-eks-v2-alpha: update EKS access entry types and add type property on grantAccess

4 participants