Repository navigation
feat(ec2): reject reserved aws: tag keys on tag-on-create (#468) - #478
Merged
Merged
Conversation
#452 closed the reserved "aws:" prefix for CreateTags and DeleteTags but deliberately left tag-on-create alone, because substrate stamps aws:ec2:fleet-id through that same path. So a key real EC2 refuses was still accepted through any TagSpecification — on RunInstances, CreateFleet, CreateImage or CreateNatGateway — leaving a consumer's error branch unreachable on exactly the path the message is best evidenced for: both real-AWS captures behind it are of RunInstances tag-on-create. Collapse the four drifted copies of the TagSpecification.N parse into ec2LaunchTagsForResource, and check every one of them. The rejection lands before the resource is created, per the tagging documentation's rollback rule, so a refused RunInstances launches no instance and a refused CreateImage leaves behind neither the AMI nor its backing snapshot. The fleet-ID stamp is exempt structurally rather than by a flag. CreateFleet parses and checks the caller's tags exactly as RunInstances does; runInstancesWithTags takes already-parsed tags, and the stamp is appended there, on an entry point no request can address. A skip-validation flag would have made the outcome depend on internal state a consumer cannot observe, which is the opposite of the deterministic-replay property. A caller naming aws: anything in a CreateFleet request is now rejected, instance- and fleet-scoped alike, while the fleet's own stamp still lands beside the caller's legal tags. This also deletes passthroughFleetTagSpecs and fleetIDTagSpec: with tags travelling as values there is no free TagSpecification.N index to hunt for, which was the subtlest function in the fleet tag path. CreateImage additionally now honours its ResourceType. It read TagSpecification.1's tags whatever they were scoped to, so a request tagging only its snapshots put those tags on the AMI; snapshot-scoped tags now land on the snapshot, where DescribeSnapshots reports them. authz.go's own walk over the same params is left alone deliberately, with a comment saying why: it builds aws:RequestTag condition keys, where filtering by resourceType would silently narrow policy evaluation. Closes #468
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Merged
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.
What
Reserved
aws:tag keys are now rejected on every tag-on-create path —RunInstances,CreateFleet,CreateImageandCreateNatGateway— not juston
CreateTags/DeleteTags.Why
#452 closed this for
CreateTagsandDeleteTagsbut deliberately lefttag-on-create alone, because substrate stamps
aws:ec2:fleet-id(#443) throughthat same path and restricting it would have rejected substrate's own fleet
tagging. So a key real EC2 refuses was still accepted through any
TagSpecification, leaving a consumer's error branch unreachable on preciselythe path the message has the best evidence for: both real-AWS captures behind
Tag keys starting with 'aws:' are reserved for internal useare ofRunInstancestag-on-create, notCreateTags.The routing problem, and why not a flag
#468rules out an internal bypass flag, and the reason holds: askip-validation switch makes the check's outcome depend on state a consumer
cannot observe, which is the opposite of the deterministic-replay property
substrate exists for.
Instead the parse is split from the launch.
runInstancesparses the request'sTagSpecification.Ntags, checks them, and delegates torunInstancesWithTags(reqCtx, req, tags).CreateFleetparses and checks thecaller's tags the same way, then appends the fleet-ID tag to the resulting
slice. There is no param a request could set to reach that append — the
exemption is structural, not conditional.
Two tests pin both halves: a caller naming
aws:minein aCreateFleetrequest is rejected (instance- and fleet-scoped), and the fleet's own stamp
still lands alongside the caller's legal
Env/Teamtags on the sameinstance.
Rollback
The check runs before
generateReservationID()and the per-instancestate.Put, so nothing is created:A refused
RunInstanceslaunches no instance, a refusedCreateImageleavesbehind neither the AMI nor its backing snapshot, and a refused
CreateNatGatewaycreates no gateway.Deletions
passthroughFleetTagSpecsandfleetIDTagSpecare both gone. With tagstravelling as values there is no free
TagSpecification.Nindex to hunt for —that index hunt was the subtlest function in the fleet tag path, and an
off-by-one in it would have silently overwritten a caller's own tag. Four
drifted copies of the
TagSpecification.Nloop collapse into oneec2LaunchTagsForResource.One deviation from the plan: a fourth copy, and a behaviour change
The plan named three
TagSpecification.Nparsers besidesrunInstances. Therewere four —
passthroughFleetTagSpecswas a fifth copy of the loop thatre-emitted params rather than returning tags.
Folding
createImageonto the shared parser is also a behaviour change,which the plan did not anticipate:
createImagehardcodedTagSpecification.1.Tag.%dand ignoredResourceTypeentirely. Checked againstthe reference before changing it —
ResourceTypeis load-bearing there(
imageandsnapshotare both valid, and "If you specify other values forResourceType, the request fails"), andEC2Snapshotalready carriesTagsthat
DescribeSnapshotsemits. So honouring it is a fidelity gain: a requesttagging only its snapshots previously put those tags on the AMI. Called out in
### Changedand indocs/services.md, since a caller asserting onDescribeImagesfor snapshot-scoped tags will see them move.authz.go:519's walk over the same params is deliberately left alone, now witha comment saying why: it builds
aws:RequestTagcondition keys, wherefiltering by
resourceTypewould silently narrow policy evaluation.Verification
From the repo root:
gofmt -l .clean,go build ./...,go vet ./...,golangci-lint run ./...→ 0 issues,make test(race) all packages ok,make docs-reference docs-reference-check docs-versionspass,go test -C test/e2e ./...ok. The whole pre-existing EC2 and fleet suitepasses unchanged.
Mutation-tested, four mutants, all killed:
runInstancesRejectsReservedTagKeys(3 subtests),ReservedTagRejectionCreatesNothingShould be zero, but was 3), which is the ordering gateResourceTypein the shared parserCreateFleet_TagPropagation,FleetIDTagCoexistsWithCallerTags,ReservedTagRejectionCreatesNothing,CreateImage_HonorsTagResourceTypeCloses #468