Skip to content

fix(eks): allow access policies on AccessEntryType.EC2 access entries - #38782

Merged
mergify[bot] merged 5 commits into
aws:mainfrom
krantboy:fix/eks-ec2-access-entry-policies
Oct 6, 2026
Merged

mergify[bot] merged 5 commits into
aws:mainfrom
krantboy:fix/eks-ec2-access-entry-policies

Conversation

@krantboy

@krantboy krantboy commented Sep 7, 2026 •

Copy link
Copy Markdown
Contributor

Issue # (if applicable)

Closes #37496.

Reason for this change

AccessEntry rejected accessPolicies on AccessEntryType.EC2 entries at synth time, even though the EKS API accepts them.

validateAccessPoliciesForRestrictedTypes grouped EC2 with HYBRID_LINUX and HYPERPOD_LINUX:

const restrictedTypes = [AccessEntryType.EC2, AccessEntryType.HYBRID_LINUX, AccessEntryType.HYPERPOD_LINUX];

That guard runs from both the AccessEntry constructor and addAccessPolicies(), so either path threw Access entry type 'EC2' cannot have access policies attached.

Attaching AmazonEKSAutoNodePolicy to an EC2 type entry is the documented way to grant an EKS Auto Mode node class access to the cluster — see Create node class access entry, which creates the entry with --type EC2 and then associates that policy. The equivalent CfnAccessEntry (Type: "EC2" with AccessPolicies) deploys fine, so the L2 was strictly more restrictive than the resource underneath it and users had to drop to L1 to express it.

aws-eks-v2's README already documented exactly this call:

cluster.grantAccess('nodeAccess', nodeRole.roleArn, [
  eks.AccessPolicy.fromAccessPolicyName('AmazonEKSAutoNodePolicy', {
    accessScopeType: eks.AccessScopeType.CLUSTER,
  }),
], { accessEntryType: eks.AccessEntryType.EC2 });

directly above a note saying EC2 cannot have policies. That example throws at synth today. README blocks are compiled by Rosetta but never executed, so nothing caught the contradiction.

Description of changes

  • Remove AccessEntryType.EC2 from restrictedTypes in aws-eks and aws-eks-v2. HYBRID_LINUX and HYPERPOD_LINUX keep their guard — this PR makes no claim about those.
  • Correct the EC2 enum JSDoc and the README notes in both modules, which asserted the opposite of the new behaviour.

No feature flag. This relaxes a synth-time guard that rejected input CloudFormation would have accepted, so no app that synthesizes today can change behaviour — per CONTRIBUTING, a flag is required for the opposite direction (newly rejecting input that used to work).

Two decisions worth a maintainer's opinion:

  1. The integ test uses AmazonEKSAutoNodePolicy because it is the documented real-world pairing, on the existing non-Auto-Mode cluster in that test. AmazonEKSViewPolicy would exercise the same code path with less dependence on Auto Mode specifics if you would prefer that.
  2. I did not add an EC2 entry to the aws-eks-v2 integ test, since its own comments state EC2 requires an Auto Mode cluster. That file gets a comment correction only, no resource change and no snapshot impact.

Describe any new or updated permissions being added

None. No IAM policy is generated or changed by CDK here — this only stops CDK from rejecting an AccessPolicies value the user supplies, which is then passed through to AWS::EKS::AccessEntry unchanged.

Description of how you validated changes

Unit tests in both modules — EC2 moved from the two throws-lists into the two allows-lists, so it is now asserted to accept policies both at construction and via addAccessPolicies(). 56 tests pass across aws-eks/test/access-entry.test.ts and aws-eks-v2/test/access-entry.test.ts.

I confirmed the tests are load-bearing rather than vacuous: re-adding EC2 to restrictedTypes fails exactly 3 of them (creates a new AccessEntry for AccessEntryType EC2, allows EC2 type with access policies, allows adding policies to EC2 type via addAccessPolicies()).

Integ test: added an EC2 type entry carrying AmazonEKSAutoNodePolicy to integ.eks-grant-access-with-type.ts. The snapshot diff is the two intended resources:

[+] AWS::IAM::Role EC2AutoNodeRoleC9A6A37A
[+] AWS::EKS::AccessEntry EC2AccessWithPolicyD4A5AB73

The integration test has since been deployed against a live EKS cluster through the automated integration test workflow, and passed.

Note on the postCliContext removal: the integ test pinned two Lambda feature flags unrelated to this fix (createNewPoliciesWithAddToRolePolicy, useCdkManagedLogGroup), both set opposite to their recommendedValue, so it was exercising legacy behaviour. Removing them lets the test synthesize on current defaults. It is isolated in its own commit, and the effect is confined to the test's own nested stacks: the provider inline policies fold back into the default policies and CDK-managed log groups are added. No library code changes.

Checklist


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

@github-actions github-actions Bot added beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. effort/small Small work item – less than a day of effort p1 labels Sep 7, 2026
@aws-cdk-automation
aws-cdk-automation requested a review from a team September 7, 2026 01:33
@maintainer-for-aws

maintainer-for-aws Bot commented Sep 25, 2026 •

Copy link
Copy Markdown

Automated review

A maintainer will still review this — treat the notes below as a starting point.

This PR fixes a bug in both the aws-eks and aws-eks-v2 modules where constructing an AccessEntry with AccessEntryType.EC2 and a non-empty accessPolicies list threw a synth-time validation error, even though the EKS API accepts the combination. The fix narrows the internal validateAccessPoliciesForRestrictedTypes guard by dropping EC2 from restrictedTypes (keeping HYBRID_LINUX and HYPERPOD_LINUX guarded), and brings the enum JSDoc, README notes, unit tests, and a new integ test case into line — correctly aligning the L2 construct with the documented EKS Auto Mode workflow of attaching AmazonEKSAutoNodePolicy to an EC2-type entry.

The change itself is small, well-scoped, symmetric across the two modules, and backed by AWS documentation; the API surface, synthesized template behavior, and documentation are all consistent and correct. One point is worth attention: an unrelated feature-flag block was removed from the integ test's App, which drives most of the snapshot churn and should either be restored or justified so the fix diff stays reviewable.

🔴 0 blocking · 🟡 1 recommended · ⚪ 0 optional

Files with findings (1)
File Findings
packages/@aws-cdk-testing/framework-integ/test/aws-eks/test/integ.eks-grant-access-with-type.ts 🟡 1

Generated automatically. React 👍 or 👎 to tell us whether this review helped, so we can improve these reviews.

@krantboy

Copy link
Copy Markdown
Contributor Author

Addressed the automated review note: updated the GrantAccessOptions.accessEntryType JSDoc in both aws-eks and aws-eks-v2 so it no longer says EC2 access entries can't have policies.

@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Experimental Feature: This security report is currently in experimental phase. Results may include false positives and the rules are being actively refined.
This security report is NOT a review blocker. Please try merge from main to avoid findings unrelated to the PR.
To suppress a specific rule, see Suppressing Rules.


TestsPassed ✅SkippedFailed
Security Guardian Results72 ran72 passed
TestResult
No test annotations available

@github-actions

github-actions Bot commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

⚠️ Experimental Feature: This security report is currently in experimental phase. Results may include false positives and the rules are being actively refined.
This security report is NOT a review blocker. Please try merge from main to avoid findings unrelated to the PR.
To suppress a specific rule, see Suppressing Rules.


TestsPassed ✅SkippedFailed
Security Guardian Results with resolved templates72 ran72 passed
TestResult
No test annotations available

@aws-cdk-automation aws-cdk-automation added the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Sep 28, 2026
@kumvprat kumvprat added the pr/needs-integration-tests-deployment Requires the PR to deploy the integration test snapshots. label Oct 2, 2026
@kumvprat
kumvprat deployed to deployment-integ-test October 2, 2026 15:44 — with GitHub Actions Active
@kumvprat
kumvprat deployed to automation October 2, 2026 15:44 — with GitHub Actions Active
@kumvprat
kumvprat deployed to automation October 2, 2026 15:44 — with GitHub Actions Active

@kumvprat kumvprat left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks @krantboy for the contribution. It closes the p1 (#37496) by removing AccessEntryType.EC2 from restrictedTypes in validateAccessPoliciesForRestrictedTypes in both aws-eks and aws-eks-v2, so EC2 access entries can now carry access policies while HYBRID_LINUX/HYPERPOD_LINUX keep their guard.

The integ tests passed through our automated integration test workflow so deployment should be fine with this new feature.

I have added an inline comment on the integration tests, can you have a look ? Apart from that the PR changes look ready to be merged.

Merge notes: the branch is behind main, so please rebase and regenerate the snapshot.

});
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

On the specific feature flag toggles below :

const app = new App({
  postCliContext: {
    '@aws-cdk/aws-lambda:createNewPoliciesWithAddToRolePolicy': true,
    '@aws-cdk/aws-lambda:useCdkManagedLogGroup': false,
  },
});

Can you check if these are the default values of these feature flags now ? If so we can remove these overloads and check again if the integration tests pass

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Checked both, and neither is at its default:

  • useCdkManagedLogGroup is pinned false while recommendedValue is true. Removing it adds two managed log groups.
  • createNewPoliciesWithAddToRolePolicy is pinned true while recommendedValue is false. Removing it restructures the provider IAM policies.

They're stale, but dropping either changes what the test synthesizes, so I've left them as they are.

Also rebased on main. The snapshot verifies unchanged against current main, so there was nothing to regenerate. The force-push reset the workflow approvals, so CI will need a nudge from you to run.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

They're stale, but dropping either changes what the test synthesizes, so I've left them as they are.

If these are not the specific requirements to make this feature work, can we remove the overrides and re-synth the test ? We can run the integration test automation post that to test the functionality

Approved the previous CI runs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Removed both overrides as requested and re-synthed. The test now runs on defaults.

Note the force-push reset the workflow approvals again, and the integ deployment needs additional approvals to release the deployment-integ-test environment.

@krantboy
krantboy force-pushed the fix/eks-ec2-access-entry-policies branch from 984ce2a to 9e2f364 Compare October 3, 2026 06:28
@krantboy
krantboy deployed to automation October 3, 2026 06:28 — with GitHub Actions Active
@krantboy
krantboy had a problem deploying to deployment-integ-test October 3, 2026 06:28 — with GitHub Actions Error
@krantboy
krantboy deployed to automation October 3, 2026 06:29 — with GitHub Actions Active
`validateAccessPoliciesForRestrictedTypes` listed `AccessEntryType.EC2`
alongside `HYBRID_LINUX` and `HYPERPOD_LINUX`, so passing `accessPolicies`
to an EC2 type `AccessEntry` (or calling `addAccessPolicies()` on one) threw
a ValidationError. The EKS API does support access policies on EC2 type
entries -- attaching `AmazonEKSAutoNodePolicy` to an EC2 type entry is the
documented way to grant an EKS Auto Mode node class access to the cluster.

Removes `EC2` from the restricted list in both `aws-eks` and `aws-eks-v2`,
and corrects the enum JSDoc and README notes that claimed otherwise. The
aws-eks-v2 README already documented an EC2 type `grantAccess` carrying
`AmazonEKSAutoNodePolicy`, an example that threw at synth time.

fixes aws#37496
…integ test

The integ test pinned two Lambda feature flags that are unrelated to the EKS
access entry feature under test, and both pinned the opposite of their
recommended value. Removing them lets the test synthesize on current defaults.

Dropping `useCdkManagedLogGroup: false` adds CDK-managed log groups, and
dropping `createNewPoliciesWithAddToRolePolicy: true` folds the provider
inline policies back into the default policies.
@krantboy
krantboy force-pushed the fix/eks-ec2-access-entry-policies branch from 9e2f364 to 8c50077 Compare October 5, 2026 16:35
@krantboy
krantboy deployed to automation October 5, 2026 16:37 — with GitHub Actions Active
@krantboy
krantboy deployed to deployment-integ-test October 5, 2026 16:37 — with GitHub Actions Active
@krantboy
krantboy deployed to automation October 5, 2026 16:37 — with GitHub Actions Active

@maintainer-for-aws maintainer-for-aws Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

See the review summary comment for the overview; the notes below are inline.

@krantboy
krantboy deployed to automation October 5, 2026 18:10 — with GitHub Actions Active
@krantboy
krantboy requested a review from kumvprat October 5, 2026 19:23
@kumvprat kumvprat removed the pr/needs-integration-tests-deployment Requires the PR to deploy the integration test snapshots. label Oct 6, 2026
@mergify

mergify Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

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

@mergify

mergify Bot commented Oct 6, 2026 •

Copy link
Copy Markdown
Contributor

Merge Queue Status

  • ✅ Entered queue — 2026-10-06 08:07 UTC · Rule: default-squash · triggered by rule automatic merge
  • ✅ Checks passed · in-place
  • ✅ Merged — 2026-10-06 10:56 UTC · at e507e07dcc2404845413e0a73c784bec0207aab3 · squash

This pull request spent 2 hours 48 minutes 36 seconds in the queue, including 1 hour 1 minute 57 seconds running CI.

Required conditions to merge

@kumvprat
kumvprat deployed to automation October 6, 2026 08:08 — with GitHub Actions Active
@aws-cdk-automation aws-cdk-automation removed the pr/needs-maintainer-review This PR needs a review from a Core Team Member label Oct 6, 2026
@mergify

mergify Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

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

@mergify
mergify Bot deployed to automation October 6, 2026 09:54 Active
@mergify
mergify Bot deployed to automation October 6, 2026 09:54 Active
@mergify

mergify Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

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

@mergify
mergify Bot merged commit e507e07 into aws:main Oct 6, 2026
23 of 24 checks passed
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

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 Oct 6, 2026

This branch was successfully deployed

2 active (1 outdated) deployments
automation — c9eee490 Deployed Oct 6, 2026 by mergify[bot] via validate-pr #371076
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK bug This issue is a bug. effort/small Small work item – less than a day of effort p1 pr/request-review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

(aws-eks, aws-eks-v2): AccessEntry` with AccessEntryType.EC2 incorrectly prevents accessPolicies from being attached

4 participants