-
Notifications
You must be signed in to change notification settings - Fork 4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
aws_eks: Support AccessConfig on aws_eks.Cluster #28588
Comments
Yes this is an awesome feature we just announced and we definitely should support that. Would you tell me more about your expected CDK experience with that? |
Sure. When creating an EKS cluster, we would like to opt in to access entries by passing the authentication mode to the constructor: cluster = aws_eks.Cluster(
self,
id="MyCluster",
# ...snipped
authentication_mode=aws_eks.AuthenticationMode.API_AND_CONFIG_MAP
) with For now we would go on to create aws_eks.AccessEntry(
self,
id="AdministatorAccessEntry",
cluster_name=cluster.cluster_name,
principal_arn=role.role_arn,
# other options
) or with a helper method on the cluster: cluster.add_access_entry(self, id="AdministatorAccessEntry", principal_arn=role.role_arn, ...) |
Thanks @TirTech for raising this one. @pahud to complement what has been shared above around the expected CDK experience with
# Grant cluster admin (system:masters RBAC group)
cluster.grant_admin(IGrantable)
# Grant read only (similarly to what a console user needs to navigate the cluster resources)
cluster.grant_read_only(IGrantable)
# General purpose grant where explicit mapping to RBAC access management can be expressed.
# Eventually this one could also take care of the heavy lifting by creating the Kubernetes' Role/ClusterRole/Binding/Group behind the scenes.
cluster.grant(IGrantable, <rbac mapping>) |
This makes sense to me. Thank you for the user experience sharing. I am bumping this issue to p1 now but we still welcome any pull requests from the community. |
Is this possible/safe to use the escape hatch to enable API_AND_CONFIG mode until this feature is released? Asking because if it’s enabled manually, it cannot be set in the CDK stack anymore since the deployment is going to fail (which seems unnecessary, it could have simply succeeded, but that’s not the point here). Thanks. |
Just self-assigned. I will pick up this issue and see if I can submit a PR in the next few days. I can't guarantee any ETA but this is something I am really looking forward to. |
FYI, I attempted to use an escape hatch like this: export default class MyEks extends Construct {
public readonly cluster: eks.Cluster
// other constructs here
this.cluster = eks.Cluster(this, 'MyEksCluster', {
// Various props here
});
const cfnCluster = this.cluster.node.defaultChild as eks.CfnCluster;
cfnCluster.accessConfig = {authenticationMode: 'API_AND_CONFIG_MAP'};
} But this did not set the authentication mode value. It doesn't appear in the synthesized cloudformation and the option isn't selected in the console. |
We are discussing with the team what is the best option for us to rollout this feature. Will update here in the next few days. |
looking forward for the update... |
@pahud Any updates on this? :) |
@pahud we are also interested in this feature |
Thanks for all the upvotes. We are still discussing with the team as adding this feature is not as simply as just adding the What I am planning for the low hanging fruits is:
This should be a small PR to unblock this for now. And after that, we could have another PR to implement the AccessEntry L2 for better developer experience. Let me know if you have different thoughts and feel free to chat with me for more details on cdk.dev slack. |
### Background Amazon EKS originally uses `ConfigMap` as its access management and in aws-eks we use AwsAuth to leverage the kubectl from kubectl-lambda-layer to create the AwsAuth configmap for that. The ConfigMap has been very difficult to maintain due to its lack support of EKS API but thanks to the AwsAuth class, it's been very smooth in CDK. In AWS reInvent 2023 we [announced](https://aws.amazon.com/blogs/containers/a-deep-dive-into-simplified-amazon-eks-access-management-controls/) the access API support that simplifies the management as a replacement of the traditional ConfigMap. In CloudFormation we have the [AccessConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-eks-cluster.html#cfn-eks-cluster-accessconfig) with [AuthenticationMode](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-eks-cluster-accessconfig.html#cfn-eks-cluster-accessconfig-authenticationmode) and `BootstrapClusterCreatorAdminPermissions` now. The `AuthenticationMode` supports `CONFIG_MAP`, which is the default, `API_AND_CONFIG_MAP` and `CONFIG_MAP`. It allows users to switch the mode on cluster creation or update. When the mode has API support, users have to define the `AccessEntry` to map the access policies and the IAM principals. This PR introduces the `AccessEntry` and `AccessPolicy` classes for that to simplify it with similar experience just as the [iam.ManagedPolicy ](https://github.com/aws/aws-cdk/blob/3928eae1ee92a03ba9959288f05f59d6bd5edcba/packages/aws-cdk-lib/aws-iam/lib/managed-policy.ts#L104)class. This PR also introduces the `grantAccess()` method that allows a cluster to `grant` its access to a specific principal and abstracts away the complexity. Overview of the API experience from this PR: ```ts const cluster = new eks.Cluster(this, 'Cluster', { vpc, mastersRole: clusterAdminRole, version: eks.KubernetesVersion.V1_30, kubectlLayer: new KubectlV29Layer(this, 'KubectlLayer'), authenticationMode: eks.AuthenticationMode.API_AND_CONFIG_MAP, }); // Cluster Admin role for this cluster cluster.grantAccess('clusterAdminAccess', clusterAdminRole.roleArn, [ eks.AccessPolicy.fromAccessPolicyName('AmazonEKSClusterAdminPolicy', { accessScopeType: eks.AccessScopeType.CLUSTER, }), ]); // EKS Admin role for specified namespaces of thie cluster cluster.grantAccess('eksAdminRoleAccess', eksAdminRole.roleArn, [ eks.AccessPolicy.fromAccessPolicyName('AmazonEKSAdminPolicy', { accessScopeType: eks.AccessScopeType.NAMESPACE, namespaces: ['foo', 'bar'], }), ]); // EKS Admin Viewer role for specified namespaces of thie cluster cluster.grantAccess('eksAdminViewRoleAccess', eksAdminViewRole.roleArn, [ eks.AccessPolicy.fromAccessPolicyName('AmazonEKSAdminViewPolicy', { accessScopeType: eks.AccessScopeType.NAMESPACE, namespaces: ['foo', 'bar'], }), ]); ``` ### Issue # (if applicable) Closes #28588 This PR introduces the `authenticationMode`, `AccessEntry` and `AccessPolicy` for both `Cluster` and `FargateCluster` construct. - [x] bump `@aws-sdk/client-eks` to [v3.476.0](https://github.com/aws/aws-sdk-js-v3/releases/tag/v3.476.0)(the minimal version with EKS Cluster Access Management support) - [x] make sure it deploys with the new AccessConfig support for a new cluster - [x] make sure an existing cluster can update by adding this new prop - [x] make sure it deploys with a new FargateCluster - [x] make sure an existing FargateCluster can update by adding this new prop - [x] make sure it works with CfnAccessEntry L1 resources - [x] AccessEntry L2 construct support - [x] AccessPolicy class - [x] bootstrapClusterCreatorAdminPermissions - [x] unit tests - [x] integ tests - [x] update README - [x] add PR notes ### Notes 1. Switching authentication modes on an existing cluster is a one-way operation like: undefined(CONFIG_MAP) -> API_AND_CONFIG_MAP -> API You can switch from undefined or CONFIG_MAP to API_AND_CONFIG_MAP. You can then switch from API_AND_CONFIG_MAP to API. You cannot revert these operations in the opposite direction. Meaning you cannot switch back to CONFIG_MAP or API_AND_CONFIG_MAP from API. And you cannot switch back to CONFIG_MAP from API_AND_CONFIG_MAP. (see [here](https://aws.amazon.com/blogs/containers/a-deep-dive-into-simplified-amazon-eks-access-management-controls/)) This PR adds relevant checks in the custom resource and add docstring in the `authenticationMode` prop. 2. Switching `bootstrapClusterCreatorAdminPermissions` would cause cluster replacement, we callout in the README and construct prop docstring as a headsup. This option is [available](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-eks-cluster-accessconfig.html#cfn-eks-cluster-accessconfig-bootstrapclustercreatoradminpermissions) in CFN which triggers replacement on resource update as well. I have created #30107 for further improvement. 3. This feature does not support AWS China regions at this moment as the JS SDK version of lambda node18 runtime in China regions is `3.462.0` while this feature requires SDK [3.476.0](https://github.com/aws/aws-sdk-js-v3/releases/tag/v3.476.0) or above. It's `3.552.0` in us-east-1. Use [this example](https://docs.aws.amazon.com/lambda/latest/dg/lambda-nodejs.html#nodejs-sdk-included) to check the version. ### Reason for this change ### Description of changes ### Description of how you validated changes ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
|
Hi folks, this feature was just merged. Let me know if you have any issues and feel free to reach out to me on cdk.dev slack. @TirTech @codeJack @akefirad @mikelane @venkates67 @hbjydev @derbauer97 |
Somewhat unrelated to this thread, but the CDK.dev slack link is broken. |
One thing I noticed is that the L2 construct does not support the KubernetesGroups parameter, which would be very useful for cases where we need more fine-grained options than what the pre-defined AccessPolicies provide. |
### Background Amazon EKS originally uses `ConfigMap` as its access management and in aws-eks we use AwsAuth to leverage the kubectl from kubectl-lambda-layer to create the AwsAuth configmap for that. The ConfigMap has been very difficult to maintain due to its lack support of EKS API but thanks to the AwsAuth class, it's been very smooth in CDK. In AWS reInvent 2023 we [announced](https://aws.amazon.com/blogs/containers/a-deep-dive-into-simplified-amazon-eks-access-management-controls/) the access API support that simplifies the management as a replacement of the traditional ConfigMap. In CloudFormation we have the [AccessConfig](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-eks-cluster.html#cfn-eks-cluster-accessconfig) with [AuthenticationMode](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-eks-cluster-accessconfig.html#cfn-eks-cluster-accessconfig-authenticationmode) and `BootstrapClusterCreatorAdminPermissions` now. The `AuthenticationMode` supports `CONFIG_MAP`, which is the default, `API_AND_CONFIG_MAP` and `CONFIG_MAP`. It allows users to switch the mode on cluster creation or update. When the mode has API support, users have to define the `AccessEntry` to map the access policies and the IAM principals. This PR introduces the `AccessEntry` and `AccessPolicy` classes for that to simplify it with similar experience just as the [iam.ManagedPolicy ](https://github.com/aws/aws-cdk/blob/3928eae1ee92a03ba9959288f05f59d6bd5edcba/packages/aws-cdk-lib/aws-iam/lib/managed-policy.ts#L104)class. This PR also introduces the `grantAccess()` method that allows a cluster to `grant` its access to a specific principal and abstracts away the complexity. Overview of the API experience from this PR: ```ts const cluster = new eks.Cluster(this, 'Cluster', { vpc, mastersRole: clusterAdminRole, version: eks.KubernetesVersion.V1_30, kubectlLayer: new KubectlV29Layer(this, 'KubectlLayer'), authenticationMode: eks.AuthenticationMode.API_AND_CONFIG_MAP, }); // Cluster Admin role for this cluster cluster.grantAccess('clusterAdminAccess', clusterAdminRole.roleArn, [ eks.AccessPolicy.fromAccessPolicyName('AmazonEKSClusterAdminPolicy', { accessScopeType: eks.AccessScopeType.CLUSTER, }), ]); // EKS Admin role for specified namespaces of thie cluster cluster.grantAccess('eksAdminRoleAccess', eksAdminRole.roleArn, [ eks.AccessPolicy.fromAccessPolicyName('AmazonEKSAdminPolicy', { accessScopeType: eks.AccessScopeType.NAMESPACE, namespaces: ['foo', 'bar'], }), ]); // EKS Admin Viewer role for specified namespaces of thie cluster cluster.grantAccess('eksAdminViewRoleAccess', eksAdminViewRole.roleArn, [ eks.AccessPolicy.fromAccessPolicyName('AmazonEKSAdminViewPolicy', { accessScopeType: eks.AccessScopeType.NAMESPACE, namespaces: ['foo', 'bar'], }), ]); ``` ### Issue # (if applicable) Closes aws#28588 This PR introduces the `authenticationMode`, `AccessEntry` and `AccessPolicy` for both `Cluster` and `FargateCluster` construct. - [x] bump `@aws-sdk/client-eks` to [v3.476.0](https://github.com/aws/aws-sdk-js-v3/releases/tag/v3.476.0)(the minimal version with EKS Cluster Access Management support) - [x] make sure it deploys with the new AccessConfig support for a new cluster - [x] make sure an existing cluster can update by adding this new prop - [x] make sure it deploys with a new FargateCluster - [x] make sure an existing FargateCluster can update by adding this new prop - [x] make sure it works with CfnAccessEntry L1 resources - [x] AccessEntry L2 construct support - [x] AccessPolicy class - [x] bootstrapClusterCreatorAdminPermissions - [x] unit tests - [x] integ tests - [x] update README - [x] add PR notes ### Notes 1. Switching authentication modes on an existing cluster is a one-way operation like: undefined(CONFIG_MAP) -> API_AND_CONFIG_MAP -> API You can switch from undefined or CONFIG_MAP to API_AND_CONFIG_MAP. You can then switch from API_AND_CONFIG_MAP to API. You cannot revert these operations in the opposite direction. Meaning you cannot switch back to CONFIG_MAP or API_AND_CONFIG_MAP from API. And you cannot switch back to CONFIG_MAP from API_AND_CONFIG_MAP. (see [here](https://aws.amazon.com/blogs/containers/a-deep-dive-into-simplified-amazon-eks-access-management-controls/)) This PR adds relevant checks in the custom resource and add docstring in the `authenticationMode` prop. 2. Switching `bootstrapClusterCreatorAdminPermissions` would cause cluster replacement, we callout in the README and construct prop docstring as a headsup. This option is [available](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-eks-cluster-accessconfig.html#cfn-eks-cluster-accessconfig-bootstrapclustercreatoradminpermissions) in CFN which triggers replacement on resource update as well. I have created aws#30107 for further improvement. 3. This feature does not support AWS China regions at this moment as the JS SDK version of lambda node18 runtime in China regions is `3.462.0` while this feature requires SDK [3.476.0](https://github.com/aws/aws-sdk-js-v3/releases/tag/v3.476.0) or above. It's `3.552.0` in us-east-1. Use [this example](https://docs.aws.amazon.com/lambda/latest/dg/lambda-nodejs.html#nodejs-sdk-included) to check the version. ### Reason for this change ### Description of changes ### Description of how you validated changes ### Checklist - [x] My code adheres to the [CONTRIBUTING GUIDE](https://github.com/aws/aws-cdk/blob/main/CONTRIBUTING.md) and [DESIGN GUIDELINES](https://github.com/aws/aws-cdk/blob/main/docs/DESIGN_GUIDELINES.md) ---- *By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Describe the feature
Support setting AccessConfig (or at least AuthenticationMode) on
aws_eks.Cluster
.Use Case
We currently use
aws_eks.Cluster
to create our clusters, and would like to start using EKS access modes (specificallyAPI_AND_CONFIG_MAP
)Proposed Solution
No response
Other Information
No response
Acknowledgements
CDK version used
2.118.0
Environment details (OS name and version, etc.)
Ubuntu 22.04.3 LTS on Windows 11 x86_64, python 3.10
The text was updated successfully, but these errors were encountered: