Skip to content

Commit

Permalink
fix(ecs): outdated linux commands for `canContainersAccessInstanceRol…
Browse files Browse the repository at this point in the history
…e=false` and also deprecate property (#32763)

### Issue # (if applicable)

Closes #28518.

### Reason for this change

When `canContainersAccessInstanceRole=false`, wrong commands are added to the ASG UserData, as described in the issue linked above.

Reason for deprecating the `canContainersAccessInstanceRole` option is detailed in #32609.

### Description of changes

- Added deprecation tag to all `canContainersAccessInstanceRole` options. 
- Created two feature flags to control the `canContainersAccessInstanceRole` behaviour
- Added new commands if customer opted to use them via setting the right feature flags

### Describe any new or updated permissions being added

None

### Description of how you validated changes

A new integ test is added to ensure the commands in UserData executes without throwing errors.

The existing integ tests are updated to have the default feature flag values and they are passing. This should prove that there will not be any change to existing CDK apps.

Unit tests are added for each platform, combination of possible values for `canContainersAccessInstanceRole` + possible values for the feature flags (3 platforms * 3 possible values for `canContainersAccessInstanceRole` * 2 possible values for `@aws-cdk/aws-ecs:disableEcsImdsBlocking` * 2 possible values for `@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature` = 36 unit tests).

### 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*
  • Loading branch information
samson-keung authored Jan 7, 2025
1 parent 3d56efa commit bbdd42c
Show file tree
Hide file tree
Showing 54 changed files with 4,038 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import * as ecsPatterns from 'aws-cdk-lib/aws-ecs-patterns';
const app = new cdk.App({
postCliContext: {
'@aws-cdk/aws-ecs:removeDefaultDeploymentAlarm': true,
'@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature': false,
'@aws-cdk/aws-ecs:disableEcsImdsBlocking': false,
},
});
const stack = new cdk.Stack(app, 'aws-ecs-integ-alb-ec2-cmd-entrypoint');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import * as integ from '@aws-cdk/integ-tests-alpha';
import { ApplicationLoadBalancedEc2Service } from 'aws-cdk-lib/aws-ecs-patterns';
import * as elbv2 from 'aws-cdk-lib/aws-elasticloadbalancingv2';

const app = new App();
const app = new App({
postCliContext: {
'@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature': false,
'@aws-cdk/aws-ecs:disableEcsImdsBlocking': false,
},
});
const stack = new Stack(app, 'aws-ecs-integ-alb');
const vpc = new Vpc(stack, 'Vpc', { maxAzs: 2, restrictDefaultSecurityGroup: false });
const cluster = new Cluster(stack, 'Cluster', { vpc });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import { IntegTest } from '@aws-cdk/integ-tests-alpha';

import { ApplicationMultipleTargetGroupsEc2Service } from 'aws-cdk-lib/aws-ecs-patterns';

const app = new App();
const app = new App({
postCliContext: {
'@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature': false,
'@aws-cdk/aws-ecs:disableEcsImdsBlocking': false,
},
});
const stack = new Stack(app, 'aws-ecs-integ-multiple-alb-healthchecks');
const vpc = new Vpc(stack, 'Vpc', { maxAzs: 2, restrictDefaultSecurityGroup: false });
const cluster = new Cluster(stack, 'Cluster', { vpc });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import { App, Stack } from 'aws-cdk-lib';
import { IntegTest } from '@aws-cdk/integ-tests-alpha';
import { NetworkMultipleTargetGroupsEc2Service } from 'aws-cdk-lib/aws-ecs-patterns';

const app = new App();
const app = new App({
postCliContext: {
'@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature': false,
'@aws-cdk/aws-ecs:disableEcsImdsBlocking': false,
},
});
const stack = new Stack(app, 'aws-ecs-integ-nlb-healthchecks');
const vpc = new Vpc(stack, 'Vpc', { maxAzs: 2, restrictDefaultSecurityGroup: false });
const cluster = new Cluster(stack, 'Cluster', { vpc });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const app = new App({
postCliContext: {
'@aws-cdk/aws-ecs:removeDefaultDeploymentAlarm': false,
'@aws-cdk/aws-ecs:reduceEc2FargateCloudWatchPermissions': false,
'@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature': false,
'@aws-cdk/aws-ecs:disableEcsImdsBlocking': false,
},
});
const stack = new Stack(app, 'aws-ecs-integ-alb-idle-timeout');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const app = new App({
postCliContext: {
[AUTOSCALING_GENERATE_LAUNCH_TEMPLATE]: false,
[REDUCE_EC2_FARGATE_CLOUDWATCH_PERMISSIONS]: false,
'@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature': false,
'@aws-cdk/aws-ecs:disableEcsImdsBlocking': false,
},
});
const stack = new Stack(app, 'aws-ecs-integ-multiple-alb');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import * as integ from '@aws-cdk/integ-tests-alpha';
import { NetworkLoadBalancedEc2Service } from 'aws-cdk-lib/aws-ecs-patterns';
import { IpAddressType } from 'aws-cdk-lib/aws-elasticloadbalancingv2';

const app = new App();
const app = new App({
postCliContext: {
'@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature': false,
'@aws-cdk/aws-ecs:disableEcsImdsBlocking': false,
},
});
const stack = new Stack(app, 'aws-ecs-integ-nlb');
const vpc = new Vpc(stack, 'Vpc', { maxAzs: 2, restrictDefaultSecurityGroup: false });
const cluster = new Cluster(stack, 'Cluster', { vpc });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import * as cdk from 'aws-cdk-lib';
import * as integ from '@aws-cdk/integ-tests-alpha';
import { ScheduledEc2Task } from 'aws-cdk-lib/aws-ecs-patterns';

const app = new cdk.App();
const app = new cdk.App({
postCliContext: {
'@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature': false,
'@aws-cdk/aws-ecs:disableEcsImdsBlocking': false,
},
});

class EventStack extends cdk.Stack {
constructor(scope: cdk.App, id: string) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@ import { Certificate } from 'aws-cdk-lib/aws-certificatemanager';
const certArn = process.env.CDK_INTEG_CERT_ARN || process.env.CERT_ARN;
if (!certArn) throw new Error('For this test you must provide your own Certificate as an env var "CERT_ARN". See framework-integ/README.md for details.');

const app = new App();
const app = new App({
postCliContext: {
'@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature': false,
'@aws-cdk/aws-ecs:disableEcsImdsBlocking': false,
},
});
const stack = new Stack(app, 'tls-network-load-balanced-ecs-service');
const vpc = new Vpc(stack, 'Vpc', { maxAzs: 2 });
const cluster = new Cluster(stack, 'Cluster', { vpc });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as cdk from 'aws-cdk-lib';
import * as ecs from 'aws-cdk-lib/aws-ecs';

const app = new cdk.App();
const app = new cdk.App({
postCliContext: {
'@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature': false,
'@aws-cdk/aws-ecs:disableEcsImdsBlocking': false,
},
});
const stack = new cdk.Stack(app, 'aws-ecs-integ-appmesh-proxy');

// Create a cluster
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import * as integ from '@aws-cdk/integ-tests-alpha';
const app = new cdk.App({
postCliContext: {
'@aws-cdk/aws-ecs:removeDefaultDeploymentAlarm': true,
'@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature': false,
'@aws-cdk/aws-ecs:disableEcsImdsBlocking': false,
},
});
const stack = new cdk.Stack(app, 'integ-ec2-capacity-provider-managed-draining');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as cdk from 'aws-cdk-lib';
import * as ecs from 'aws-cdk-lib/aws-ecs';

const app = new cdk.App();
const app = new cdk.App({
postCliContext: {
'@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature': false,
'@aws-cdk/aws-ecs:disableEcsImdsBlocking': false,
},
});
const stack = new cdk.Stack(app, 'integ-ec2-capacity-provider');

const vpc = new ec2.Vpc(stack, 'Vpc', { maxAzs: 2, restrictDefaultSecurityGroup: false });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import * as elb from 'aws-cdk-lib/aws-elasticloadbalancing';
import * as cdk from 'aws-cdk-lib';
import * as ecs from 'aws-cdk-lib/aws-ecs';

const app = new cdk.App();
const app = new cdk.App({
postCliContext: {
'@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature': false,
'@aws-cdk/aws-ecs:disableEcsImdsBlocking': false,
},
});
const stack = new cdk.Stack(app, 'aws-ecs-integ');

const vpc = new ec2.Vpc(stack, 'Vpc', { maxAzs: 2, restrictDefaultSecurityGroup: false });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import * as cloudmap from 'aws-cdk-lib/aws-servicediscovery';
import * as cdk from 'aws-cdk-lib';
import * as ecs from 'aws-cdk-lib/aws-ecs';

const app = new cdk.App();
const app = new cdk.App({
postCliContext: {
'@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature': false,
'@aws-cdk/aws-ecs:disableEcsImdsBlocking': false,
},
});
const stack = new cdk.Stack(app, 'aws-ecs-integ');
const vpc = new ec2.Vpc(stack, 'Vpc', {
restrictDefaultSecurityGroup: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import * as cdk from 'aws-cdk-lib';
import * as integ from '@aws-cdk/integ-tests-alpha';
import * as ecs from 'aws-cdk-lib/aws-ecs';

const app = new cdk.App();
const app = new cdk.App({
postCliContext: {
'@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature': false,
'@aws-cdk/aws-ecs:disableEcsImdsBlocking': false,
},
});
const stack = new cdk.Stack(app, 'integ-default-capacity-provider');

const vpc = new ec2.Vpc(stack, 'Vpc', { maxAzs: 2, restrictDefaultSecurityGroup: false });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import * as cdk from 'aws-cdk-lib';
import * as integ from '@aws-cdk/integ-tests-alpha';
import * as ecs from 'aws-cdk-lib/aws-ecs';

const app = new cdk.App();
const app = new cdk.App({
postCliContext: {
'@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature': false,
'@aws-cdk/aws-ecs:disableEcsImdsBlocking': false,
},
});
const stack = new cdk.Stack(app, 'integ-deployment-alarms');

const vpc = new ec2.Vpc(stack, 'Vpc', { maxAzs: 2 });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import * as ecs from 'aws-cdk-lib/aws-ecs';
const app = new cdk.App({
postCliContext: {
'@aws-cdk/aws-ecs:reduceEc2FargateCloudWatchPermissions': true,
'@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature': false,
'@aws-cdk/aws-ecs:disableEcsImdsBlocking': false,
},
});
const stack = new cdk.Stack(app, 'aws-ecs-integ-enable-execute-command');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import * as cdk from 'aws-cdk-lib';
import * as ecs from 'aws-cdk-lib/aws-ecs';
import { IntegTest } from '@aws-cdk/integ-tests-alpha';

const app = new cdk.App();
const app = new cdk.App({
postCliContext: {
'@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature': false,
'@aws-cdk/aws-ecs:disableEcsImdsBlocking': false,
},
});
const stack = new cdk.Stack(app, 'aws-ecs-integ');

// S3 bucket to host envfile without public access
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import * as s3 from 'aws-cdk-lib/aws-s3';
import * as cdk from 'aws-cdk-lib';
import * as ecs from 'aws-cdk-lib/aws-ecs';

const app = new cdk.App();
const app = new cdk.App({
postCliContext: {
'@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature': false,
'@aws-cdk/aws-ecs:disableEcsImdsBlocking': false,
},
});
const stack = new cdk.Stack(app, 'aws-ecs-integ-exec-command');

const vpc = new ec2.Vpc(stack, 'Vpc', { maxAzs: 2, restrictDefaultSecurityGroup: false });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import * as s3_assets from 'aws-cdk-lib/aws-s3-assets';
import * as cdk from 'aws-cdk-lib';
import * as ecs from 'aws-cdk-lib/aws-ecs';

const app = new cdk.App();
const app = new cdk.App({
postCliContext: {
'@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature': false,
'@aws-cdk/aws-ecs:disableEcsImdsBlocking': false,
},
});
const stack = new cdk.Stack(app, 'aws-ecs-integ');
const vpc = new ec2.Vpc(stack, 'Vpc', { maxAzs: 2, restrictDefaultSecurityGroup: false });
const cluster = new ecs.Cluster(stack, 'EcsCluster', { vpc });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as cdk from 'aws-cdk-lib';
import * as ecs from 'aws-cdk-lib/aws-ecs';

const app = new cdk.App();
const app = new cdk.App({
postCliContext: {
'@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature': false,
'@aws-cdk/aws-ecs:disableEcsImdsBlocking': false,
},
});
const stack = new cdk.Stack(app, 'aws-ecs-integ');

const vpc = new ec2.Vpc(stack, 'Vpc', { maxAzs: 2, restrictDefaultSecurityGroup: false });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import * as elbv2 from 'aws-cdk-lib/aws-elasticloadbalancingv2';
import * as cdk from 'aws-cdk-lib';
import * as ecs from 'aws-cdk-lib/aws-ecs';

const app = new cdk.App();
const app = new cdk.App({
postCliContext: {
'@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature': false,
'@aws-cdk/aws-ecs:disableEcsImdsBlocking': false,
},
});
const stack = new cdk.Stack(app, 'aws-ecs-integ');

const vpc = new ec2.Vpc(stack, 'Vpc', { maxAzs: 2, restrictDefaultSecurityGroup: false });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import * as elbv2 from 'aws-cdk-lib/aws-elasticloadbalancingv2';
import * as cdk from 'aws-cdk-lib';
import * as ecs from 'aws-cdk-lib/aws-ecs';

const app = new cdk.App();
const app = new cdk.App({
postCliContext: {
'@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature': false,
'@aws-cdk/aws-ecs:disableEcsImdsBlocking': false,
},
});
const stack = new cdk.Stack(app, 'aws-ecs-integ-ecs');

const vpc = new ec2.Vpc(stack, 'Vpc', { maxAzs: 2, restrictDefaultSecurityGroup: false });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import { Construct } from 'constructs';
import * as ecs from 'aws-cdk-lib/aws-ecs';
import { IntegTest } from '@aws-cdk/integ-tests-alpha';

const app = new cdk.App();
const app = new cdk.App({
postCliContext: {
'@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature': false,
'@aws-cdk/aws-ecs:disableEcsImdsBlocking': false,
},
});

// WHEN
class EcsStack extends cdk.Stack {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as ecs from 'aws-cdk-lib/aws-ecs';

const app = new cdk.App();
const app = new cdk.App({
postCliContext: {
'@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature': false,
'@aws-cdk/aws-ecs:disableEcsImdsBlocking': false,
},
});

class EcsStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import * as cdk from 'aws-cdk-lib';
import * as integ from '@aws-cdk/integ-tests-alpha';
import * as ecs from 'aws-cdk-lib/aws-ecs';

const app = new cdk.App();
const app = new cdk.App({
postCliContext: {
'@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature': false,
'@aws-cdk/aws-ecs:disableEcsImdsBlocking': false,
},
});
const stack = new cdk.Stack(app, 'aws-ecs-integ-pseudo-terminal');

// Create a cluster
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as cdk from 'aws-cdk-lib';
import * as ecs from 'aws-cdk-lib/aws-ecs';

const app = new cdk.App();
const app = new cdk.App({
postCliContext: {
'@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature': false,
'@aws-cdk/aws-ecs:disableEcsImdsBlocking': false,
},
});
const stack = new cdk.Stack(app, 'aws-ecs-integ-ecs');

const vpc = new ec2.Vpc(stack, 'Vpc', { maxAzs: 2, restrictDefaultSecurityGroup: false });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as cdk from 'aws-cdk-lib';
import * as ecs from 'aws-cdk-lib/aws-ecs';

const app = new cdk.App();
const app = new cdk.App({
postCliContext: {
'@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature': false,
'@aws-cdk/aws-ecs:disableEcsImdsBlocking': false,
},
});
const stack = new cdk.Stack(app, 'aws-ecs-integ-ecs');

const vpc = new ec2.Vpc(stack, 'Vpc', { maxAzs: 2, restrictDefaultSecurityGroup: false });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ import * as ec2 from 'aws-cdk-lib/aws-ec2';
import * as cdk from 'aws-cdk-lib';
import * as ecs from 'aws-cdk-lib/aws-ecs';

const app = new cdk.App();
const app = new cdk.App({
postCliContext: {
'@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature': false,
'@aws-cdk/aws-ecs:disableEcsImdsBlocking': false,
},
});
const stack = new cdk.Stack(app, 'aws-ecs-integ-spot');

const vpc = new ec2.Vpc(stack, 'Vpc', { maxAzs: 2, restrictDefaultSecurityGroup: false });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ import * as integ from '@aws-cdk/integ-tests-alpha';
import * as ecs from 'aws-cdk-lib/aws-ecs';
import { LinuxParameters } from 'aws-cdk-lib/aws-ecs';

const app = new cdk.App();
const app = new cdk.App({
postCliContext: {
'@aws-cdk/aws-ecs:enableImdsBlockingDeprecatedFeature': false,
'@aws-cdk/aws-ecs:disableEcsImdsBlocking': false,
},
});
const stack = new cdk.Stack(app, 'aws-ecs-integ');

const vpc = new ec2.Vpc(stack, 'Vpc', { maxAzs: 2, restrictDefaultSecurityGroup: false });
Expand Down
Loading

0 comments on commit bbdd42c

Please sign in to comment.