-
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_stepfunctions: StateMachine construct doesn't generate a valid policy for default StateMachineRole #31714
Comments
Hi @JamieClayton7 , thanks for reaching out. I tried to deploy the source code - const cluster = new ecs.Cluster(this, 'Cluster', {
vpc: new cdk.aws_ec2.Vpc(this, 'Vpc', { maxAzs: 1 }),
});
cluster.addCapacity('DefaultAutoScalingGroup', {
instanceType: new cdk.aws_ec2.InstanceType('t2.micro'),
});
const taskDefinition = new ecs.FargateTaskDefinition(this, 'TaskDefinition', {
cpu: 256,
memoryLimitMiB: 512,
runtimePlatform: {
operatingSystemFamily: ecs.OperatingSystemFamily.LINUX,
cpuArchitecture: ecs.CpuArchitecture.X86_64
},
});
taskDefinition.addContainer('Container', {
image: ecs.ContainerImage.fromRegistry('amazonlinux'),
memoryLimitMiB: 512,
cpu: 256,
});
const stateMachineDefinition = new tasks.EcsRunTask(this, 'Run Traffic DB maintenance jobs', {
cluster,
launchTarget: new tasks.EcsFargateLaunchTarget(),
taskDefinition,
integrationPattern: sfn.IntegrationPattern.RUN_JOB,
});
const stateMachine = new sfn.StateMachine(this, 'StateMachine', {
definition: stateMachineDefinition,
stateMachineName: 'StateMachine',
stateMachineType: sfn.StateMachineType.STANDARD,
timeout: cdk.Duration.hours(2),
tracingEnabled: true,
});
new cdk.CfnOutput(this, 'StateMachineArn', {
value: stateMachine.stateMachineArn,
}) and see this {
"Version": "2012-10-17",
"Statement": [
{
"Action": "ecs:RunTask",
"Resource": "arn:aws:ecs:us-west-1:123456789012:task-definition/StepfunctionIssueStackTaskDefinition64A4E983:*",
"Effect": "Allow"
}, which seems exactly as its supposed to be. This PR introduced the change to correct the arn returned -(Original issue). |
I found an article on this task definition with revision number - and this PR seems to be merged 3 days ago -#31615 which addresses the same issue for event-targets. Marking this issue as P1 as the Task definition ARN in IAM policy resource should include revision number. Reaching out to on-call to provide inputs here as if its something already on their radar or share insights if possible. |
…alid policy for default StateMachineRole (#31801) ### Issue # (if applicable) Closes #31714. ### Reason for this change Currently, the step functions `runEcsTask()` will create an IAM policy. The `Resource` section is an ARN constructed by CDK with wildcard `*` appending at the end. However, CDK should `Ref` the resource directly instead of constructing the ARN, while keeping the revision number. ### Description of changes The same solution as #31615. However this change needs to behind a feature flag because it could be a breaking change. ### Description of how you validated changes Integration test. Also checked the synth template. ### Checklist - [ ] 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*
Comments on closed issues and PRs are hard for our team to see. |
Describe the bug
When using
aws_stepfunctions.StateMachine
, the default IAM policy for the state machine role does not generate the correct statement for the actionecs:RunTask
.The difference being that we now must specify the revision number (or all revisions by omitting the number and simply adding
:
) tagged onto the task definition ARN.From 15th October 2024, the statement generated will result in an AccessDeniedException when the state machine attempts to RunTask on the non-tagged task definition ARN.
Regression Issue
Last Known Working CDK Version
N/A
Expected Behavior
The valid statement that should be generated:
Current Behavior
The statement generated:
Reproduction Steps
Possible Solution
CDK synth should generate the correct IAM statement for state machines ecs:RunTask by using the task definition role ARN with the revision tag attached to the task definition.
Work around for the time being:
Additional Information/Context
No response
CDK CLI Version
2.161.1 (build 0a606c9)
Framework Version
No response
Node.js Version
v22.9.0
OS
MacOS
Language
TypeScript
Language Version
No response
Other information
No response
The text was updated successfully, but these errors were encountered: