Skip to content
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

feat(eks): support AccessConfig for the Cluster construct #30016

Merged
merged 58 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 56 commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
955a94c
access config support
pahud Apr 30, 2024
04a395b
wip
pahud May 2, 2024
8bd96e8
AccessEntry L2 support
pahud May 3, 2024
396b4bb
minor
pahud May 3, 2024
98254fe
unit tests
pahud May 3, 2024
825203a
refactor AccessPolicy
pahud May 4, 2024
526db6c
update README
pahud May 4, 2024
9cb9c6b
disable awsAuth when authMode is API
pahudcc May 5, 2024
caaf04a
throw when configmap is not supported
pahudcc May 5, 2024
734cbca
add integ and snapshots
pahudcc May 6, 2024
fef2785
unit tests for AccessEntry
pahudcc May 6, 2024
3346c06
add more awsauth tests
pahudcc May 6, 2024
bebc33f
update yarn.lock per requested by CI
pahudcc May 6, 2024
d57d537
Merge branch 'main' into pahud/aws-eks-support-accessconfig-28588
pahud May 6, 2024
ee7def0
add unit tests for AccessPolicy and AccessPolicyArn
pahudcc May 6, 2024
67a2397
fix docstring
pahudcc May 6, 2024
ee00e00
fix integ test
pahudcc May 6, 2024
6249396
update tests
pahudcc May 7, 2024
bd90cb2
fix tests
pahudcc May 7, 2024
209ef32
update integ tests
pahudcc May 7, 2024
17dd42b
update tests
pahudcc May 8, 2024
6b349bf
update tests
pahud May 8, 2024
859ccde
fix README
pahud May 8, 2024
2432b07
updat cluster resource handler to handle
pahud May 8, 2024
4165464
Merge branch 'pahud/aws-eks-support-accessconfig-28588' of https://gi…
pahud May 8, 2024
5ecb856
callout bootstrapClusterCreatorAdminPermissions in README
pahud May 8, 2024
05d0019
Merge branch 'main' into pahud/aws-eks-support-accessconfig-28588
pahud May 13, 2024
ceac30a
update integ
pahud May 13, 2024
c9b0314
Update packages/aws-cdk-lib/aws-eks/lib/cluster.ts
pahud May 14, 2024
8782fea
improve doc string
pahud May 15, 2024
082c06b
make addToAccessEntry private
pahud May 15, 2024
54cdcbe
update fromAccessPolicyName()
pahud May 22, 2024
ae9a22c
Merge branch 'main' into pahud/aws-eks-support-accessconfig-28588
pahud Jun 5, 2024
101759f
fix typo and lint
pahud Jun 5, 2024
b930040
update tests
pahud Jun 5, 2024
e1146df
update README
pahud Jun 5, 2024
c4e9c40
improve the tests
pahud Jun 6, 2024
29968e5
Merge branch 'main' into pahud/aws-eks-support-accessconfig-28588
pahud Jun 6, 2024
6445773
add AccessEntryType
pahud Jun 6, 2024
f19805c
add test for accessEntryType
pahud Jun 6, 2024
8365348
Merge branch 'main' into pahud/aws-eks-support-accessconfig-28588
pahud Jun 6, 2024
1fddf0c
update
pahud Jun 6, 2024
1b25f92
update tests
pahud Jun 6, 2024
841d6b7
Merge branch 'main' into pahud/aws-eks-support-accessconfig-28588
pahud Jun 6, 2024
cb7802f
add more checks and tests
pahud Jun 6, 2024
7d1bcfe
fix README
pahud Jun 6, 2024
480bf4a
update README
pahud Jun 7, 2024
5a2191e
Merge branch 'main' into pahud/aws-eks-support-accessconfig-28588
mergify[bot] Jun 11, 2024
364f86b
chore: upgrade jsii to `~5.4.21` (#30518)
mrgrain Jun 11, 2024
74bcc1f
feat: implement node runtime region awareness for cdk vended custom r…
colifran Jun 11, 2024
11597a0
feat(opensearch): add OpenSearch 2.13 engine version (#30399)
timbru31 Jun 11, 2024
34f92df
Merge remote-tracking branch 'origin/main' into pahud/aws-eks-support…
pahud Jun 12, 2024
b98369a
update snaps
pahud Jun 12, 2024
5121217
fix conflict
pahud Jun 12, 2024
619e7bb
fix conflict
pahud Jun 12, 2024
ac72608
Merge branch 'main' into pahud/aws-eks-support-accessconfig-28588
pahud Jun 12, 2024
353fc93
update snapshots
pahud Jun 12, 2024
3294656
Merge branch 'main' into pahud/aws-eks-support-accessconfig-28588
pahud Jun 12, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
/* eslint-disable no-console */
// eslint-disable-next-line import/no-extraneous-dependencies
import * as EKS from '@aws-sdk/client-eks';
import { IsCompleteResponse, OnEventResponse } from 'aws-cdk-lib/custom-resources/lib/provider-framework/types';
import { EksClient, ResourceEvent, ResourceHandler } from './common';
import { compareLoggingProps } from './compareLogging';
import { IsCompleteResponse, OnEventResponse } from 'aws-cdk-lib/custom-resources/lib/provider-framework/types';

const MAX_CLUSTER_NAME_LEN = 100;

Expand Down Expand Up @@ -116,8 +116,7 @@ export class ClusterResourceHandler extends ResourceHandler {
// if there is an update that requires replacement, go ahead and just create
// a new cluster with the new config. The old cluster will automatically be
// deleted by cloudformation upon success.
if (updates.replaceName || updates.replaceRole ) {

if (updates.replaceName || updates.replaceRole || updates.updateBootstrapClusterCreatorAdminPermissions ) {
// if we are replacing this cluster and the cluster has an explicit
// physical name, the creation of the new cluster will fail with "there is
// already a cluster with that name". this is a common behavior for
Expand All @@ -129,6 +128,24 @@ export class ClusterResourceHandler extends ResourceHandler {
return this.onCreate();
}

// We can only update one type of the UpdateTypes:
type UpdateTypes = {
updateLogging: boolean;
updateAccess: boolean;
updateVpc: boolean;
updateAuthMode: boolean;
};
// validate updates
const updateTypes = Object.keys(updates) as (keyof UpdateTypes)[];
const enabledUpdateTypes = updateTypes.filter((type) => updates[type]);
console.log(enabledUpdateTypes);

if (enabledUpdateTypes.length > 1) {
throw new Error(
'Only one type of update - VpcConfigUpdate, LoggingUpdate, EndpointAccessUpdate, or AuthModeUpdate can be allowed',
);
}

// Update tags
if (updates.updateTags) {
try {
Expand Down Expand Up @@ -185,12 +202,7 @@ export class ClusterResourceHandler extends ResourceHandler {
return this.updateClusterVersion(this.newProps.version);
}

if ((updates.updateLogging && updates.updateAccess) || (updates.updateLogging && updates.updateVpc) ||
(updates.updateVpc && updates.updateAccess)) {
throw new Error('Only one type of update - VpcConfigUpdate, LoggingUpdate or EndpointAccessUpdate can be allowed');
}

if (updates.updateLogging || updates.updateAccess || updates.updateVpc) {
if (updates.updateLogging || updates.updateAccess || updates.updateVpc || updates.updateAuthMode) {
const config: EKS.UpdateClusterConfigCommandInput = {
name: this.clusterName,
};
Expand All @@ -203,13 +215,48 @@ export class ClusterResourceHandler extends ResourceHandler {
endpointPublicAccess: this.newProps.resourcesVpcConfig?.endpointPublicAccess,
publicAccessCidrs: this.newProps.resourcesVpcConfig?.publicAccessCidrs,
};
}
};

if (updates.updateAuthMode) {
// the update path must be
// `undefined or CONFIG_MAP` -> `API_AND_CONFIG_MAP` -> `API`
// and it's one way path.
// old value is API - cannot fallback backwards
if (this.oldProps.accessConfig?.authenticationMode === 'API' &&
this.newProps.accessConfig?.authenticationMode !== 'API') {
throw new Error(`Cannot fallback authenticationMode from API to ${this.newProps.accessConfig?.authenticationMode}`);
}
// old value is API_AND_CONFIG_MAP - cannot fallback to CONFIG_MAP
if (this.oldProps.accessConfig?.authenticationMode === 'API_AND_CONFIG_MAP' &&
this.newProps.accessConfig?.authenticationMode === 'CONFIG_MAP') {
throw new Error(`Cannot fallback authenticationMode from API_AND_CONFIG_MAP to ${this.newProps.accessConfig?.authenticationMode}`);
}
// cannot fallback from defined to undefined
if (this.oldProps.accessConfig?.authenticationMode !== undefined &&
this.newProps.accessConfig?.authenticationMode === undefined) {
throw new Error('Cannot fallback authenticationMode from defined to undefined');
}
// cannot update from undefined to API because undefined defaults CONFIG_MAP which
// can only change to API_AND_CONFIG_MAP
if (this.oldProps.accessConfig?.authenticationMode === undefined &&
this.newProps.accessConfig?.authenticationMode === 'API') {
throw new Error('Cannot update from undefined(CONFIG_MAP) to API');
}
// cannot update from CONFIG_MAP to API
if (this.oldProps.accessConfig?.authenticationMode === 'CONFIG_MAP' &&
this.newProps.accessConfig?.authenticationMode === 'API') {
throw new Error('Cannot update from CONFIG_MAP to API');
}
config.accessConfig = this.newProps.accessConfig;
};

if (updates.updateVpc) {
config.resourcesVpcConfig = {
subnetIds: this.newProps.resourcesVpcConfig?.subnetIds,
securityGroupIds: this.newProps.resourcesVpcConfig?.securityGroupIds,
};
}

const updateResponse = await this.eks.updateClusterConfig(config);

return { EksUpdateId: updateResponse.update?.id };
Expand Down Expand Up @@ -361,6 +408,8 @@ interface UpdateMap {
updateLogging: boolean; // logging
updateEncryption: boolean; // encryption (cannot be updated)
updateAccess: boolean; // resourcesVpcConfig.endpointPrivateAccess and endpointPublicAccess
updateAuthMode: boolean; // accessConfig.authenticationMode
updateBootstrapClusterCreatorAdminPermissions: boolean; // accessConfig.bootstrapClusterCreatorAdminPermissions
updateVpc: boolean; // resourcesVpcConfig.subnetIds and securityGroupIds
updateTags: boolean; // tags
}
Expand All @@ -376,6 +425,8 @@ function analyzeUpdate(oldProps: Partial<EKS.CreateClusterCommandInput>, newProp
const newPublicAccessCidrs = new Set(newVpcProps.publicAccessCidrs ?? []);
const newEnc = newProps.encryptionConfig || {};
const oldEnc = oldProps.encryptionConfig || {};
const newAccessConfig = newProps.accessConfig || {};
const oldAccessConfig = oldProps.accessConfig || {};

return {
replaceName: newProps.name !== oldProps.name,
Expand All @@ -390,6 +441,9 @@ function analyzeUpdate(oldProps: Partial<EKS.CreateClusterCommandInput>, newProp
updateVersion: newProps.version !== oldProps.version,
updateEncryption: JSON.stringify(newEnc) !== JSON.stringify(oldEnc),
updateLogging: JSON.stringify(newProps.logging) !== JSON.stringify(oldProps.logging),
updateAuthMode: JSON.stringify(newAccessConfig.authenticationMode) !== JSON.stringify(oldAccessConfig.authenticationMode),
updateBootstrapClusterCreatorAdminPermissions: JSON.stringify(newAccessConfig.bootstrapClusterCreatorAdminPermissions) !==
JSON.stringify(oldAccessConfig.bootstrapClusterCreatorAdminPermissions),
updateTags: JSON.stringify(newProps.tags) !== JSON.stringify(oldProps.tags),
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import * as EKS from '@aws-sdk/client-eks';
export function compareLoggingProps(oldProps: Partial<EKS.CreateClusterCommandInput>,
newProps: Partial<EKS.CreateClusterCommandInput>): Partial<EKS.CreateClusterCommandInput> {
const result: Partial<EKS.CreateClusterCommandInput> = { logging: {} };
let enabledTypes: (EKS.LogType | string)[] = [];
let disabledTypes: (EKS.LogType | string)[] = [];
let enabledTypes: EKS.LogType[] = [];
let disabledTypes: EKS.LogType[] = [];

if (newProps.logging?.clusterLogging === undefined && oldProps.logging?.clusterLogging === undefined) {
return newProps;
Expand Down
2 changes: 1 addition & 1 deletion packages/@aws-cdk/custom-resource-handlers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"@aws-sdk/client-route-53": "3.421.0",
"@aws-sdk/client-cloudwatch-logs": "3.421.0",
"@aws-sdk/client-dynamodb": "3.421.0",
"@aws-sdk/client-eks": "3.421.0",
"@aws-sdk/client-eks": "3.476.0",
"@aws-sdk/client-sts": "3.421.0",
"@aws-sdk/node-http-handler": "^3.370.0",
"@smithy/util-stream": "^2.2.0",
Expand Down
Loading
Loading