Skip to content

Commit de7ab7c

Browse files
authored
fix(ecs): reduce ecs service task role cloudwatch permissions when no log configured (under feature flag) (#31475)
### Issue # (if applicable) Closes #31397 ### Reason for this change If a FargateService or EC2 Service has `enableExecuteCommand: true` and the ECS cluster it runs on has `executeCommandConfiguration.logging` set to anything but `ecs.ExecuteCommandLogging.NONE` then the CDK automatically grants the underlying TaskDefinition overly broad cloudwatch logs permissions regardless of need even if the logging configuration has no cloudwatch logs config set. This is not right behaviour as these permissions are not needed. ### Description of changes Add feature flag and if feature flag is on and cloudwatch log is configured, reduce the permissions. ### Description of how you validated changes New unit tests, integration 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*
1 parent 60ce351 commit de7ab7c

29 files changed

+6883
-20
lines changed

packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/ec2/integ.multiple-application-load-balanced-ecs-service-idle-timeout.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { AUTOSCALING_GENERATE_LAUNCH_TEMPLATE } from 'aws-cdk-lib/cx-api';
1111
const app = new App({
1212
postCliContext: {
1313
'@aws-cdk/aws-ecs:removeDefaultDeploymentAlarm': false,
14+
'@aws-cdk/aws-ecs:reduceEc2FargateCloudWatchPermissions': false,
1415
},
1516
});
1617
const stack = new Stack(app, 'aws-ecs-integ-alb-idle-timeout');

packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/ec2/integ.multiple-application-load-balanced-ecs-service.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@ import { Cluster, ContainerImage } from 'aws-cdk-lib/aws-ecs';
33
import { App, Stack } from 'aws-cdk-lib';
44
import * as integ from '@aws-cdk/integ-tests-alpha';
55
import { ApplicationMultipleTargetGroupsEc2Service } from 'aws-cdk-lib/aws-ecs-patterns';
6-
import { AUTOSCALING_GENERATE_LAUNCH_TEMPLATE } from 'aws-cdk-lib/cx-api';
6+
import { AUTOSCALING_GENERATE_LAUNCH_TEMPLATE, REDUCE_EC2_FARGATE_CLOUDWATCH_PERMISSIONS } from 'aws-cdk-lib/cx-api';
77

8-
const app = new App({ postCliContext: { [AUTOSCALING_GENERATE_LAUNCH_TEMPLATE]: false } });
8+
const app = new App({
9+
postCliContext: {
10+
[AUTOSCALING_GENERATE_LAUNCH_TEMPLATE]: false,
11+
[REDUCE_EC2_FARGATE_CLOUDWATCH_PERMISSIONS]: false,
12+
},
13+
});
914
const stack = new Stack(app, 'aws-ecs-integ-multiple-alb');
1015
const vpc = new Vpc(stack, 'Vpc', { maxAzs: 2, restrictDefaultSecurityGroup: false });
1116
const cluster = new Cluster(stack, 'Cluster', { vpc });

packages/@aws-cdk-testing/framework-integ/test/aws-ecs-patterns/test/fargate/integ.alb-fargate-service-https.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ import { App, Stack } from 'aws-cdk-lib';
66
import * as integ from '@aws-cdk/integ-tests-alpha';
77
import { ApplicationLoadBalancedFargateService } from 'aws-cdk-lib/aws-ecs-patterns';
88

9-
const app = new App();
9+
const app = new App({
10+
postCliContext: {
11+
'@aws-cdk/aws-ecs:reduceEc2FargateCloudWatchPermissions': false,
12+
},
13+
});
1014
const stack = new Stack(app, 'aws-ecs-integ-alb-fg-https');
1115
const vpc = new Vpc(stack, 'Vpc', { maxAzs: 2, restrictDefaultSecurityGroup: false });
1216
const cluster = new Cluster(stack, 'Cluster', { vpc });

packages/@aws-cdk-testing/framework-integ/test/aws-ecs/test/ec2/integ.enable-execute-command.js.snapshot/asset.bde7b5c89cb43285f884c94f0b9e17cdb0f5eb5345005114dd60342e0b8a85a1/__entrypoint__.js

Lines changed: 155 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-ecs/test/ec2/integ.enable-execute-command.js.snapshot/asset.bde7b5c89cb43285f884c94f0b9e17cdb0f5eb5345005114dd60342e0b8a85a1/index.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/@aws-cdk-testing/framework-integ/test/aws-ecs/test/ec2/integ.enable-execute-command.js.snapshot/aws-ecs-integ-enable-execute-command.assets.json

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)