Repository navigation
feat(ec2): reject reserved aws:-prefixed tag keys (#452) - #463
Merged
Merged
Conversation
CreateTags and DeleteTags accepted tag keys using the aws: prefix that real EC2 reserves for itself, so a consumer could tag a resource in a way AWS refuses — and a test asserting that refusal passed against substrate while the same call failed against AWS. Both now reject with InvalidParameterValue / 400 / "Tag keys starting with 'aws:' are reserved for internal use", before any resource is modified: a request mixing a legal tag with a reserved one leaves every resource it named untouched. CreateTags accepts up to 1000 resource IDs, so a mid-loop rejection would leave a prefix tagged, a state real EC2 never produces. The match is case-sensitive, correcting the assumption the issue was filed with. AWS documents tag keys as case-sensitive and every observed rejection quotes the lowercase form, so AWS:foo and Aws:foo remain ordinary user tags. Provenance is stated plainly in the code, docs, and changelog rather than implying a doc citation: the CreateTags reference's Errors section is empty, so the code and message come from observed real-AWS responses. DeleteTags rests on weaker evidence still and inherits the wording. RunInstances tag-on-create is deliberately left unrestricted — substrate stamps aws:ec2:fleet-id (#443) through that path, and restricting it would undo the only route from an instant fleet back to its instances. A regression test pins that a fleet still stamps and still filters on the tag.
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
6 tasks
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 #452
Problem
CreateTagsandDeleteTagsaccepted tag keys using theaws:prefix that real EC2 reserves for its own use. A consumer could tag a resource in a way AWS refuses, so a test asserting that refusal passed against substrate while the same call failed against AWS — the recurring shape on this tracker.What changed
New
emulator/ec2_tags.goholds the rule and its provenance in one place. Both operations now reject with:HTTP 400. The check runs before the first
applyTagsToResourcecall, so the whole request is refused atomically — a request mixing a legal tag with a reserved one leaves every resource it named untouched.CreateTagsaccepts up to 1000 resource IDs, and rejecting partway through the loop would leave a prefix tagged, a state real EC2 never produces.The match is case-sensitive — this corrects the issue
#452 asks to confirm whether the prefix match is case-insensitive. It is not: the EC2 tag-restrictions page documents tag keys and values as case-sensitive, and every observed rejection quotes the lowercase
'aws:'.AWS:fooandAws:fooare ordinary user tags and are accepted. A case-folded check would have traded this infidelity for a new one in the opposite direction.Provenance, stated plainly
The
CreateTagsreference's Errors section is empty, so neither the code nor the message is derivable from the API model. Both come from observed real-AWS responses — two independent captures giving byte-identical text (jcjorel/ec2-spot-converter#13; dtan4/terraforming#343, which recordsStatus Code: 400; Error Code: InvalidParameterValue). Both captures are ofRunInstancestag-on-create rather thanCreateTags; the message is evidently shared, but substrate has not observed it onCreateTagsdirectly.DeleteTagsrests on weaker evidence still — no capturedDeleteTagsrejection was found, so its code and message are inherited. What the documentation does state unambiguously is the outcome: such a tag "can't be edited or deleted". ADeleteTagsthat returned success while leaving the tag in place would be its own infidelity, so refusing is the closer of the two available behaviours. The code comment,docs/services.md, and the changelog all say this rather than implying a doc citation.Two parts of AWS's rule deliberately not covered
RunInstancestag-on-create is unrestricted. Real EC2 rejects a reserved key there too — that is where both captures come from — but substrate stampsaws:ec2:fleet-id(EC2: CreateFleet does not apply the aws:ec2:fleet-id tag, so a fleet's instances can't be found #443) by buildingRunInstancesTagSpecificationparams, parsed by its own loop rather than routed throughcreateTags. Restricting that path would reject substrate's own fleet tagging and silently undo the only route from aninstantfleet back to its live instances.TestEC2_ReservedTagCheck_DoesNotBreakFleetTaggingpins that a fleet still stamps the tag and thatDescribeInstances --filters tag:aws:ec2:fleet-idstill finds its instances.TagLimitExceedednever fires.Both gaps get follow-up issues.
Tests
emulator/ec2_tags_test.go, table-driven:AWS:foo,Aws:foo,aws-foo,awsfoo,my-aws:fooall accepted (case-sensitivity).aws:with an empty suffix rejected.DeleteTagson a reserved key refused and the tag survives — using a fleet launch to create the tag, sinceCreateTagsnow refuses to.DeleteTagson an ordinary key still works.ec2FleetIDTagKey's doc comment, whose last sentence said substrate enforced neither rule, is updated to say which one it now enforces and why the other has nothing to exempt.Verification
From the repo root:
gofmt -l .clean,go build ./...,go vet ./...,golangci-lint run ./...→ 0 issues,make test(race) green,make docs-reference-check docs-versionsgreen,test/e2egreen.Mutation-tested — each mutant compiles (
go vetgate) and the new tests catch it:runInstances'TagSpecificationparse