Skip to content

feat(ec2): reject reserved aws:-prefixed tag keys (#452) - #463

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/452-reserved-tag-keys
Aug 2, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/452-reserved-tag-keys

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #452

Problem

CreateTags and DeleteTags accepted tag keys using the aws: 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.go holds the rule and its provenance in one place. Both operations now reject with:

InvalidParameterValue: Tag keys starting with 'aws:' are reserved for internal use

HTTP 400. The check runs before the first applyTagsToResource call, so the whole request is refused atomically — a request mixing a legal tag with a reserved one leaves every resource it named untouched. CreateTags accepts 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:foo and Aws:foo are 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 CreateTags reference'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 records Status Code: 400; Error Code: InvalidParameterValue). Both captures are of RunInstances tag-on-create rather than CreateTags; the message is evidently shared, but substrate has not observed it on CreateTags directly.

DeleteTags rests on weaker evidence still — no captured DeleteTags rejection 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". A DeleteTags that 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

  • RunInstances tag-on-create is unrestricted. Real EC2 rejects a reserved key there too — that is where both captures come from — but substrate stamps aws: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 building RunInstances TagSpecification params, parsed by its own loop rather than routed through createTags. Restricting that path would reject substrate's own fleet tagging and silently undo the only route from an instant fleet back to its live instances. TestEC2_ReservedTagCheck_DoesNotBreakFleetTagging pins that a fleet still stamps the tag and that DescribeInstances --filters tag:aws:ec2:fleet-id still finds its instances.
  • The 50-tag limit is unmodelled, so the companion rule that reserved tags are exempt from it has nothing to exempt them from. TagLimitExceeded never fires.

Both gaps get follow-up issues.

Tests

emulator/ec2_tags_test.go, table-driven:

  • Reserved key rejected with the exact code, status and message; the tag is not applied.
  • All-or-nothing: two resource IDs, a legal tag ahead of a reserved one — neither resource ends up with either tag.
  • AWS:foo, Aws:foo, aws-foo, awsfoo, my-aws:foo all accepted (case-sensitivity).
  • Bare aws: with an empty suffix rejected.
  • DeleteTags on a reserved key refused and the tag survives — using a fleet launch to create the tag, since CreateTags now refuses to.
  • DeleteTags on an ordinary key still works.
  • The fleet regression above.

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-versions green, test/e2e green.

Mutation-tested — each mutant compiles (go vet gate) and the new tests catch it:

Mutation Caught by
prefix check made case-insensitive the two case-sensitivity cases fail
check moved inside the apply loop every reject case + all-or-nothing fail
check added to runInstances' TagSpecification parse 8 fleet tests fail — the wrong-path implementation is loud

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

codecov Bot commented Aug 2, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit be6a780 into main Aug 2, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the feat/452-reserved-tag-keys branch August 2, 2026 22:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

EC2: CreateTags accepts reserved aws:-prefixed tag keys that real EC2 rejects

1 participant