Repository navigation
feat(cloudformation,ec2): stamp aws:cloudformation:* on the EC2 resources a stack creates (#746) - #766
Merged
Conversation
…rces a stack creates (#746) AWS puts aws:cloudformation:stack-name, aws:cloudformation:stack-id and aws:cloudformation:logical-id on every resource a stack creates; substrate's deployer put none. That left AmazonECS_FullAccess's ManagedCloudformationResourcesCleanupPolicy permanently unsatisfiable: it conditions on ec2:ResourceTag/aws:cloudformation:stack-name, the resolution for that key already worked (#730), CreateTags refuses an aws: key as AWS does, and no path existed by which the tag could ever exist. The stamp is written from deployResource, the sole caller of dispatchResource, which already holds the logical ID, the physical ID and the stack's name, account and region — so none of the 110 dispatch arms is touched. It is a state write rather than a synthesized CreateTags because that call refuses the aws: keys it would carry, and because every synthesized request is authorized, so the parameter route would newly require ec2:CreateTags of every principal whose deployment succeeds today. resourceTags and applyTagsToResource are promoted to free functions taking a StateManager, as ec2LookupDefaultVPC already is, since the deployer holds no plugin. Scoped to EC2, which is what the bundled statement needs: the resolver maps an ID prefix to a state key and only EC2 keeps tags in a store shaped that way, so all nine EC2 types the deployer creates are covered by prefix. A non-EC2 physical ID is skipped silently, as is a resource that failed to deploy or has no physical ID. Extending the stamp is #765; caller-supplied stack tags, still dropped, are #764. Only aws:cloudformation:stack-name appears on any reachable AWS CloudFormation page, so the triple is observed behavior rather than the API model and docs/services.md records it as such. Closes #746
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
AWS puts three tags on every resource a stack creates —
aws:cloudformation:stack-name,aws:cloudformation:stack-idandaws:cloudformation:logical-id— and substrate's deployer put none. That is not only amissing member: it left a bundled policy permanently unsatisfiable.
AmazonECS_FullAccess'sManagedCloudformationResourcesCleanupPolicyallows four EC2deletes on any resource whose
ec2:ResourceTag/aws:cloudformation:stack-nameis likeEC2ContainerService-*; the resolution for that key already worked (#730),CreateTagsrefuses an
aws:key as AWS does, and no path existed by which the tag could ever exist —so the statement granted nothing at all, and nothing distinguished that from a policy bug.
Design
The stamp is written from
deployResource, the sole caller ofdispatchResource, whichalready holds the logical ID, the physical ID and the stack's name, account and region. So
none of the 110 dispatch arms is touched.
It is deliberately a state write and not a synthesized
CreateTags: that call refuses theaws:keys it would be carrying, andStackDeployer.dispatchrunsCheckAccesson everysynthesized request, so the parameter route would newly require
ec2:CreateTagsof everyprincipal whose deployment succeeds today.
resourceTagsandapplyTagsToResourcearepromoted to free functions taking a
StateManager, the same refactorec2LookupDefaultVPCalready had, because the deployer holds no plugin.
The stack ID written is the ARN
AWS::StackIdresolves to rather than a second derivation ofit — two derivations of one identity is the defect #517 was. The write is an upsert, so
re-deploying rewrites the three tags rather than accumulating them, and
aws:keys arealready outside the 50-tag limit, so the stamp cannot push a caller's own tags over it.
Scoped to EC2, which is what the bundled statement needs: the resolver maps an ID prefix to a
state key and only EC2 keeps tags in a store shaped that way, so all nine EC2 types the
deployer creates are covered by prefix and a tenth arrives free. A non-EC2 physical ID is
skipped silently — a stack creates far more non-EC2 resources than EC2 ones, so a warning per
resource would bury a real one — as is a resource that failed to deploy or has no physical ID.
Provenance
Of the three keys, only
aws:cloudformation:stack-nameappears on any AWS CloudFormation pagethat was reachable: every user-guide page documenting the set returned an empty body, and
API_CreateStack.htmldocuments caller-supplied stack-tag propagation, which is the othermechanism. The triple is observed behavior rather than the API model, and
docs/services.mdrecords it as such.Verification
gofmt/go build/go vet/golangci-lintclean (0 issues);make testgreen with race;coverage holds at emulator 83.4%, total 82.8%;
make docs-reference docs-reference-check docs-versionspass; the VitePress build succeeds with nohref="#…"lacking anid;test/e2evet and test green.Six new tests (
emulator/cfn_stack_tags_test.go), the last of which asserts the whole chainrather than the tag: it attaches the bundled
AmazonECS_FullAccess, deploysEC2ContainerService-webandunrelated-stack, and has the policy actually authorize aDeleteSecurityGroupfor the first and refuse it for the second. Fail-before: 14FAILlinesacross 5 tests with the stamp call removed.
Live SDK fail-before/pass-after against built binaries,
awsCLI over--endpoint-url,deploying a ten-resource stack (nine EC2 types plus a bucket):
mainaws:cloudformation:stack-idvs theAWS::StackIdoutputNonecreate-tags Key=aws:cloudformation:stack-nameby a callerInvalidParameterValueInvalidParameterValueEC2ContainerService-live's SGAccessDeniedReturn: trueunrelated-stack's SGAccessDeniedAccessDeniedCarve-outs, filed not dropped
CreateStackTags.member.N, still dropped, and their propagation.no tag store until elbv2: tagging, so elasticloadbalancing:CreateAction has a producer #748).
Also fixes a lazy-continuation bug in
docs/services.mdintroduced by #744, where a paragraphfollowing a bullet list was rendered into the list item.
Compatibility
A test asserting an exact tag set on a CFN-deployed EC2 resource now sees three more tags, and
a tag-scoped policy that matched nothing before may now match.
Closes #746