feat(ecs): allow specifying whether an imported task definition ARN includes a revision - #38633
Open
lemon0333 wants to merge 1 commit into
Open
feat(ecs): allow specifying whether an imported task definition ARN includes a revision#38633lemon0333 wants to merge 1 commit into
lemon0333 wants to merge 1 commit into
Conversation
…ncludes a revision Adds an optional `taskDefinitionArnIncludesRevision` boolean to `TaskDefinitionAttributes` (and the Fargate/EC2 variants via `CommonTaskDefinitionAttributes`) and threads it through `ImportedTaskDefinition` and the `ITaskDefinition` interface. When an imported task definition ARN is only known at deploy time (e.g. `Fn.importValue` or a CloudFormation parameter), its revision cannot be inferred from the string. The EventBridge `EcsTask` target's `ecs:RunTask` grant logic now uses this flag to decide between the exact ARN and a `:*` revision wildcard, falling back to the existing string inspection when the flag is not provided (preserving current behavior). Closes aws#32485.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Issue # (if applicable)
Closes #32485.
Reason for this change
fromFargateTaskDefinitionAttributes/fromEc2TaskDefinitionAttributes/fromTaskDefinitionAttributescannot record whether an imported task definition ARN is fully-qualified (...:task-definition/family:123) or revision-less (...:task-definition/family).When an
EcsTaskEventBridge target scopes down itsecs:RunTaskpermission (the case from #30390 / #31615), it must grant the exact ARN when a revision is present, or append a:*revision wildcard when it is not. Today that decision is made by string-inspecting the ARN:This breaks when the ARN is only known at deploy time (e.g.
Fn.importValue, or a CloudFormation parameter): the ARN is an unresolved token, so no revision can be inferred, and the:*wildcard is silently omitted even for a revision-less ARN. The maintainer (@ashishdhingra) confirmed this is a valid extension of #30390 / #31615.Description of changes
taskDefinitionArnIncludesRevision?: booleantoCommonTaskDefinitionAttributes(soTaskDefinitionAttributes,FargateTaskDefinitionAttributes, andEc2TaskDefinitionAttributesall inherit it) inpackages/aws-cdk-lib/aws-ecs/lib/base/task-definition.ts.ITaskDefinitioninterface and threaded it throughImportedTaskDefinitionand all threefrom*TaskDefinitionAttributesimport methods.createEventRolePolicyStatements()inpackages/aws-cdk-lib/aws-events-targets/lib/ecs-task.ts: when the flag is set it authoritatively decides whether the:*wildcard is needed; otherwise it falls back to the existing token/string inspection, so the default behavior is unchanged.Public API shape
Per my note on the issue, the preferred shape wasn't specified, so I went with a boolean flag (
taskDefinitionArnIncludesRevision) rather than a separate no-revision ARN field, because it maps directly onto the single decision the grant logic makes and keeps the import surface minimal. I'm happy to rename it or switch to a separate field if a maintainer prefers a different shape — feedback welcome.Describe any new or updated permissions being added
No new permissions. This changes how the resource scope of the existing
ecs:RunTaskpermission is computed for the EventBridgeEcsTasktarget: a revision-less imported ARN whose value is a deploy-time token is now correctly scoped with a:*revision wildcard whentaskDefinitionArnIncludesRevision: falseis supplied.Description of how you validated changes
aws-events-targets/test/ecs/event-rule-target.test.ts(tokenized ARN +false->:*wildcard; tokenized ARN +true-> ARN as-is; concrete ARN with explicit override) and 1 test inaws-ecs/test/fargate/fargate-task-definition.test.ts(attribute is recorded / defaults toundefined). Full suites pass: 39/39 (events-targets ecs) and 67/67 (ecs task-definition).integ.ecs-imported-task-def(which imports a family-only ARN built from region/account tokens) to settaskDefinitionArnIncludesRevision: false, and regenerated the snapshot. The only functional snapshot change is theecs:RunTaskresource going from.../task-definition/TaskDefinitionAto.../task-definition/TaskDefinitionA:*.tsccompiles the affected packages with 0 errors.aws-events-targets/README.md.Checklist
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license