feat(eks): allow providing an existing IAM role to ServiceAccount with POD_IDENTITY#37392
Open
letsgomeow wants to merge 3 commits intoaws:mainfrom
Open
feat(eks): allow providing an existing IAM role to ServiceAccount with POD_IDENTITY#37392letsgomeow wants to merge 3 commits intoaws:mainfrom
letsgomeow wants to merge 3 commits intoaws:mainfrom
Conversation
…h POD_IDENTITY Add an optional `role?: IRoleRef` property to `ServiceAccountOptions`. When specified with `IdentityType.POD_IDENTITY`, the provided role is used for `CfnPodIdentityAssociation` instead of auto-generating one. Specifying `role` with IRSA throws a `ValidationError` at construction time. The `role`, `assumeRoleAction`, `grantPrincipal`, and `policyFragment` members are changed from `readonly` properties to getters so that construction succeeds even when an L1 `CfnRole` is passed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 #37299.
Reason for this change
When using
ServiceAccountwithIdentityType.POD_IDENTITY, there was no way toprovide an externally-created IAM role. The construct always auto-generated a new role,
making it impossible to use a pre-existing role (e.g., one managed by a separate stack
or created outside CDK).
Description of changes
Added an optional
role?: IRoleRefproperty toServiceAccountOptionsinaws-eks.roleis provided withIdentityType.POD_IDENTITY, the given role is used forthe
CfnPodIdentityAssociationinstead of auto-generating one.roleis omitted, behavior is unchanged (a new role is auto-generated).rolewithIdentityType.IRSA(or the default) throws aValidationErrorat construction time, since IRSA requires a cluster-specific OIDC trust policy that
cannot be set up on an external role.
roleproperty acceptsIRoleRefrather thanIRole, following CDK's Enhanced L1direction. Since
IRole extends IRoleRef, all existingIRolevalues (e.g.,iam.Role,iam.Role.fromRoleArn()) are accepted without any breaking change.ServiceAccount.rolegetter and relatedIPrincipalmembers (assumeRoleAction,grantPrincipal,policyFragment) were changed fromreadonlyproperties to gettersso that construction succeeds even when an L1
CfnRoleis passed; accessingsa.roleon a
CfnRole-backedServiceAccountthrows a descriptive error.POD_IDENTITYguard (throw Error(...)) is preserved in v1,since
aws-ekssupportsFargateClusterand Pod Identity is not compatible with Fargate.Describe any new or updated permissions being added
No new IAM permissions are introduced. When the caller provides an existing role, the
trust policy on that role is their responsibility.
Description of how you validated changes
service-account.test.tscovering:CfnPodIdentityAssociation(no auto-generated role)ValidationErroris thrown whenroleis specified withIRSAidentity typeValidationErroris thrown whenroleis specified with default identity typesa.rolegetter returns the provided L2 role as-isServiceAccountconstruction succeeds with an L1CfnRole, butsa.rolegetter throwssa.rolegetter returns auto-generated role when noroleprop is providedinteg.eks-pod-identities-external-role.tscovering:roleprop (new behavior)integ.eks-pod-identities.tsis unchanged to avoid snapshot churn)ap-northeast-1.Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license