feat(eks): support for ServiceAccount without IAM role #35961
+233
−93
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue # (if applicable)
Closes #35892.
Reason for this change
AWS accounts have a default limit of 1,000 IAM roles. When deploying many EKS ServiceAccounts, users can hit this limit because the ServiceAccount construct always creates an IAM role, even when the workload doesn't need AWS permissions. This forces users to request quota increases or implement workarounds.
Additionally, creating IAM roles for ServiceAccounts that only need Kubernetes-level permissions violates the principle of least privilege and creates unnecessary security surface area.
Description of changes
This PR adds
IdentityType.NONEas a new member of theIdentityTypeenum, allowing users to create ServiceAccounts without IAM roles when AWS permissions are not needed.Key changes:
IdentityTypeenum withNONEmemberidentityTypeidentityTypeisNONE:eks.amazonaws.com/role-arnannotationroleproperty isundefinedaddToPrincipalPolicy()returns{ statementAdded: false }Breaking change: The
roleproperty onServiceAccountis now optional (role?: IRoleinstead ofrole: IRole). This is necessary because whenidentityTypeisNONE, no IAM role is created.Migration path for existing code:
Note: Existing code that doesn't specify
identityTypewill continue to work without modification (defaults toIdentityType.IRSA). Only code that directly accesses theroleproperty needs to be updated to handle the optional type.Migration considerations when changing existing ServiceAccounts to
IdentityType.NONE:IAM role removal: The IAM role will be deleted from CloudFormation. Any resources that reference this role (e.g., trust policies, resource-based policies) will be impacted and may need updates.
Kubernetes ServiceAccount update behavior: The ServiceAccount itself will NOT be deleted and re-created. Behind the scenes,
kubectl applywill update the Kubernetes manifest:eks.amazonaws.com/role-arnannotation and will not have AWS credentialsTesting recommendation: For large-scale ServiceAccount migrations, we strongly recommend testing in a non-production environment first to validate that your workloads function correctly without AWS IAM permissions.
Usage example:
Describe any new or updated permissions being added
N/A - This change does not add any new IAM permissions. In fact, it provides a way to avoid creating IAM roles when they are not needed.
Description of how you validated changes
Unit tests: Added 4 comprehensive tests for
IdentityType.NONE:addToPrincipalPolicy()returns{ statementAdded: false }gracefullyRegression testing:
CloudFormation validation: Verified that when using
IdentityType.NONE:AWS::IAM::Roleresources are created for the ServiceAccountAWS::EKS::PodIdentityAssociationresources are createdChecklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license