Repository navigation
fix(cloudfront): add UntagResource, and stop routing an untag to the tag write (#883) - #900
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
Follow-up commit adds What remains uncovered on the patch is five lines, all of them the |
…tag write (#883) CloudFront implemented TagResource and ListTagsForResource and not UntagResource, and parseCloudFrontOperation mapped any Resource-bearing POST to TagResource — so POST /2020-05-31/tagging?Operation=Untag ran the tag path, where the <TagKeys> body decoded as <Tags> into an empty item list, the decode error was discarded, and the distribution was written back byte-identical with a 204. The removal was reported as done and the tag was still there. A tagging POST now resolves on the Operation value alone, per the request syntax the CloudFront API Reference publishes for the three operations sharing the /tagging path. A value that is neither Tag nor Untag resolves to no operation, so the request keeps its verb and is refused at the plugin's default arm rather than performing a write. Neither tagging arm discards its decode error any longer, so a body of the wrong shape is refused instead of read as an empty tag set, and an untag with no body is refused because TagKeys is documented Required: Yes. Removing an absent key succeeds and the Resource parameter is required on all three operations; AWS publishes neither, and both are labelled as substrate's reading in the code. The Resource Groups Tagging API is unaffected: resolveARN has no cloudfront arm, so UntagResources already refuses with InternalServiceException rather than reporting a removal it did not make, which its guard table now pins. Closes #883.
…like The three now share one target resolver, and a shared resolver is only worth having if all three are asserted against it. Also covers the resolver's two refusal branches, which the first pass reached from the untag arm only.
9829b0f to
f2ab207
Compare
CloudFront implemented
TagResourceandListTagsForResourceand notUntagResource, andparseCloudFrontOperationmapped anyResource-bearing POST toTagResource. SoPOST /2020-05-31/tagging?Operation=Untagran the tag path: the<TagKeys>body decoded as<Tags>into an empty item list, the decode error was discarded, the distribution was marshalled back byte-identical, and the response was the tagging success. The failure was not "operation not supported", which a caller can branch on, but a successful no-op — the removal reported as done,ListTagsForResourcestill reporting the tag, and nothing anywhere saying otherwise. Same class as theapplyTagsToResourcesilent-200 that v0.115.0 removed for ECS.Closes #883.
What changed
Operationvalue and on nothing else.Operation=Tag→TagResource,Operation=Untag→UntagResource(case-insensitively, asTagalready was),GETcarryingResource→ListTagsForResource. A value that is neither resolves to no operation at all, so the request keeps its verb, reachesHandleRequest's default arm, and is refused withInvalidAction/400 — a write is never the fallback for a word the resolver cannot name. The duplicate/taggingarm further down the path switch is gone; one block now owns all three.UntagResourcehandler removes the keys named in<TagKeys><Items><Key>and answers the documented 204 with an empty body.<Tags>document sent to the untag and a<TagKeys>document sent to the tag are now both refused withInvalidArgument/400 instead of read as an empty tag set. That closes the silent-no-op behaviour independently of the routing, which matters because the routing fix alone would leave the swallow in place for anyone who sent the wrong body deliberately. An untag with no body is refused for the same reason.resolveTagTarget) and the two writers share one state write (putDistribution), so a removal cannot drift from the tag it undoes on which resource an ARN names or which key it writes to.What AWS publishes
Verified against the CloudFront API Reference; all three pages loaded and are quoted, not recalled.
API_UntagResource— request syntaxPOST /2020-05-31/tagging?Operation=Untag, body<TagKeys xmlns="http://cloudfront.amazonaws.com/doc/2020-05-31/"><Items><Key>{{string}}</Key></Items></TagKeys>;TagKeys"Required: Yes",Items"Required: No"; responseHTTP/1.1 204— "an HTTP 204 response with an empty HTTP body"; errorsAccessDenied403,InvalidArgument400,InvalidTagging400,NoSuchResource404.API_TagResource— the same path withOperation=Tag, a<Tags>body, 204, the same four errors.API_ListTagsForResource—GET /2020-05-31/tagging?Resource={{Resource}}, and the only one of the three that documents the query parameter: "An ARN of a CloudFront resource. Pattern:arn:aws(-cn)?:cloudfront::[0-9]+:.*Required: Yes".What could not be verified, and how it is labelled
Two things the reference does not settle. Both are labelled in the code as substrate's reading, with the reasoning, rather than presented as the API model.
untagResourcein bold as substrate's reading and pinned byTestCloudFrontUntagResource_AnAbsentKeySucceeds.Resourceis a required query parameter on Tag/Untag. Both pages say "The request does not use any URI parameters", which cannot be right for operations whose whole request syntax is a bare/taggingpath with no other way to name a target, andListTagsForResourcedocuments it as required with a pattern. Substrate reads that as a documentation omission and requires it on all three; recorded onresolveTagTarget.Also recorded rather than silently chosen:
InvalidArgumentfor an unparsable body, since AWS does not publish which ofInvalidArgumentandInvalidTaggingit answers for one.Resource Groups Tagging API
Not affected, and deliberately not changed here. The issue's premise was that
tagging_plugin.goresolves CloudFront ARNs today; re-checked against the tree, it does not —TaggingPlugin.resolveARNhas nocloudfrontarm at all (the file contains no occurrence of the string), so a CloudFront ARN falls to the default and answers aFailedResourcesMapentry ofInternalServiceException/500, "the resource type in the request is not supported by the Resource Groups Tagging API". SoUntagResourcesrefuses loudly and has never had #883's silent-success shape. This is consistent with whatcfn_resource_tags.goalready records: CloudFront is one of the services that "keep tag state, but none has amergeResourceTagsarm that reaches it", filed as #835.Rather than leave that on trust, a
cloudfront distributioncase was added toTestTaggingResolveARN_AWrongTypeARNIsRefusedRatherThanMisKeyed, which drives bothTagResourcesandUntagResources. It passes on the parent commit as well as on this branch, which is the evidence that the hole is a different one. Giving CloudFront an arm there needs amergeResourceTagscase as well as a resolver case, and changes which resourcesGetResourcesenumerates — #835's work, not a misrouted request's. The reasoning is in a code comment at the head of the plugin's tagging section, not only here.Tests
New
emulator/cloudfront_untag_test.go, every case over the wire throughStartTestServeragainst a real server, every tag assertion read back through CloudFront's ownListTagsForResourcerather than out of the state store (#765's rule — a state read cannot tell a removal that happened from one that was reported as happening), and asserted on the raw XML, because an absent member and an empty one are the same value once decoded.TestCloudFrontUntagResource_IsNotAnsweredAsTheTaggingSuccess— the issue's gate: 204 and the tag gone.TestCloudFrontUntagResource_RemovesOnlyTheNamedKeys— a handler that cleared the map would pass the gate.TestCloudFrontUntagResource_AnAbsentKeySucceeds,..._AMissingARNIsRefused.TestCloudFrontTagging_ARequestThatNamesNoOperationNeverWrites— five cases (noOperation, an unrecognizedOperation, a<Tags>body sent to Untag, a<TagKeys>body sent to Tag, an untag with no body), each asserting the refusal and that the existing tag survived, since the refusal alone would pass on a handler that errored after writing.TestCloudFrontTagging_OperationNamesComeFromTheQueryString— the name the pipeline resolves, which is what authorization, metering and the event log record; an untag namedTagResourcewould also be authorized ascloudfront:TagResource.Confirmed against the parent commit by restoring
cloudfront_plugin.gofromHEADand re-running: 4 of the 6 new tests fail (12 subtests), including the gate. The two that pass on the old code are the absent-key and missing-ARN cases, which the old no-op happened to satisfy.Request bodies carry the
xmlns="http://cloudfront.amazonaws.com/doc/2020-05-31/"the reference publishes, so the decoders are exercised against what an SDK actually sends rather than a namespace-free simplification.Verification
No test was relaxed, and nothing was silently passing on the old behaviour: the pre-existing
TestCloudFrontPlugin_TagAndListTagsonly asserted that the list response was non-empty XML, which is why it never caught this.Compatibility
Three behaviour changes a consumer could notice, all of them refusals that previously answered 204 having written nothing:
Operation, or with anOperationthat is neitherTagnorUntag, is nowInvalidAction/400 instead of being performed asTagResource. A caller relying on the bare-ResourcePOST as a tag write must sendOperation=Tag, which is what the reference publishes and what every SDK sends.InvalidArgument/400 instead of being read as an empty tag set.InvalidArgument/400.An ARN naming no distribution still answers
NoSuchDistribution/404 rather than theNoSuchResourceall three tagging pages list, because that is what the rest of the plugin andloadDistributionanswer and one plugin should not report a missing distribution two ways. Aligning all three arms on the published code is a separate change from a misrouted request; noted inresolveTagTargetand worth its own issue.docs/services.md's hand-written CloudFront section now listsUntagResourceandListTagsForResource(the latter was implemented but undocumented), states how the three are told apart, and records the RGTA gap.CHANGELOG.mdcarries the full reasoning under## [Unreleased] → ### Fixed.