Repository navigation
feat(cfn): the aws:cloudformation:* stamp reaches beyond EC2 (#765) - #828
Merged
Merged
Conversation
The deployer's stamp resolved a physical ID with ec2TaggableResource, which covers every EC2 type it creates and nothing else — so an S3 bucket, a Lambda function, an SQS queue, a DynamoDB table and every ELBv2 resource a stack created carried none of the three aws:cloudformation:* keys, and a policy or a cost-allocation assertion keyed on the stack name saw nothing on them. A second resolver keys on the CloudFormation resource type rather than on the physical ID's shape, because outside EC2 a physical ID is a bare name with nothing to switch on. Every state key is verified against the plugin that owns the record rather than copied from TaggingPlugin.resolveARN, which gets SQS wrong (#826). TaggingPlugin.mergeTags is extracted into a free function so the tagging API and the deployer share one merge.
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.
Closes #765.
The defect
StackDeployer.stampCFNResourceTagsresolved a physical ID to a state key withec2TaggableResource— a prefix switch over fifteen EC2 id forms. That covers every EC2 typethe deployer creates and nothing else, so most of a stack was unstamped: an S3 bucket, a Lambda
function, an SQS queue, a DynamoDB table and every ELBv2 resource carried none of
aws:cloudformation:stack-name,…:stack-idor…:logical-id. A policy conditioned onaws:ResourceTag/aws:cloudformation:stack-name— the shape AWS's own bundled cleanup policyuses — matched nothing on them, and neither did a cost-allocation assertion.
What changed
Nine types across six services are stamped now: EC2's nine as before, plus
AWS::S3::Bucket,AWS::Lambda::Function,AWS::SQS::Queue,AWS::DynamoDB::Tableand ELBv2's LoadBalancer,TargetGroup, Listener and ListenerRule.
New
emulator/cfn_resource_tags.goholds the second resolver, keyed onDeployedResource.Typerather than on the physical ID's shape. That is not a style choice:outside EC2 a physical ID is a bare name, so a bucket named
ordersand a queue namedordersare the same string and there is nothing in the ID to switch on. The CFN type is already carried
beside it, so this needed no new bookkeeping. ELBv2 is resolved separately through
elbResolveTaggedResource, because its four kinds are keyed by a generated suffix that is notderivable from a name.
TaggingPlugin.mergeTagsis extracted intomergeResourceTags, a free function taking aStateManager, followingec2ApplyTagsToResource's precedent — so the Resource Groups TaggingAPI and the deployer cannot drift into two merge behaviours. The method now delegates to it.
stampCFNResourceTagstries EC2's resolver first, then the new one, and still returns insilence when neither claims the resource.
Every key was verified against the plugin that owns it
TaggingPlugin.resolveARNcomputes a key for the same four services and gets SQS wrong: itaddresses
queue:<name>where the SQS plugin writesqueue:<account>/<name>, so a tag setthrough
TagResourcesis invisible toListQueueTags— and toGetResources, which lists byprefix and so reads the real record. Filed as #826, and deliberately not reproduced here. The
tie-breaker is #765's own criterion: the record the service's own tag call loads is the record
the stamp has to land in.
That is why every assertion in the tests reads the tag back through the owning service's tag
call rather than out of state. A state assertion would have passed against the wrong key.
Provenance, corrected
An earlier note in
cfn_deployer.goanddocs/services.mdsaid onlyaws:cloudformation:stack-nameappeared on any reachable AWS page and that the three-key setwas observed behaviour. The Template Reference's Resource tag page documents all three by
name; the pages consulted when #746 shipped had returned empty bodies. The same page supplies
the sentence that licenses a partial cut rather than an exhaustive list:
So
docs/services.mdstates substrate's rule — a resource is stamped when substrate models tagsfor its service — and names the ~20 services skipped because they keep no tag state, plus API
Gateway and Cognito, which carry tag state with no operation to read it back through (#819).
IAM is excluded on purpose: no page says an IAM entity receives the stamp, and
TagRolerefusesan
aws:-prefixed key, so a stamped IAM tag would be one no caller could set or remove.Tests
emulator/cfn_stamp_beyond_ec2_test.gois new;newCFNStampFixturegrew from two plugins toseven, because the plugin owning each record has to be present to answer for it.
GetBucketTagging,ListTags,ListQueueTags,ListTagsOfResourceand ELBv2DescribeTags, plus EC2 to pin that its resolver still wins;afterwards so a prefix match rather than an exact one would be caught;
logger since a silent skip is not observable any other way;
aws:ResourceTag/aws:cloudformation:stack-nameallows aDeleteBucketfor amatching stack's bucket and refuses it for another's — cfn: the aws:cloudformation:* stamp covers EC2 only, so the rest of a stack is unstamped #765's fourth criterion, and it goes
through a different reader (
AuthController.resourceTagsFor) than the assertions above;TestCFN_ANonEC2ResourceIsNotStampedis inverted intoTestCFN_ANonEC2ResourceIsStampedByItsOwnService. The old assertion read through EC2'sDescribeTags, so it would have passed unchanged — a bucket carries no EC2 tags either way.Fail-before: stubbing
cfnStampResourceTagstoreturn false, nilturns 4 tests and 6subtests red. The EC2 subtest and the silent-skip test stay green, which is correct — neither
depends on the new resolver.
Filed in passing
Refon an ELBv2 LoadBalancer or TargetGroup answers with the name where AWSanswers with the ARN, so AWS's own listener template does not deploy here. Worked around in
the test by deploying the parent in a separate stack and writing its ARN in literally.
Verification
gofmt,go build,go vet,golangci-lint(0 issues),make testandGOTOOLCHAIN=go1.26.6 make testall clean. Coverage holds at emulator 83.8% / total 83.1%.make docs-reference docs-reference-check docs-versions authz-reference-check,npm --prefix docs run build, andgo vet/go test -C test/e2eall pass.