Skip to content

feat(ec2): reject reserved aws: tag keys on tag-on-create (#468) - #478

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/468-reserved-tag-keys-on-create
Aug 2, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/468-reserved-tag-keys-on-create

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

What

Reserved aws: tag keys are now rejected on every tag-on-create path —
RunInstances, CreateFleet, CreateImage and CreateNatGateway — not just
on CreateTags/DeleteTags.

Why

#452 closed this for CreateTags and DeleteTags but deliberately left
tag-on-create alone, because substrate stamps aws:ec2:fleet-id (#443) through
that 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 precisely
the path the message has the best evidence for: both real-AWS captures behind
Tag keys starting with 'aws:' are reserved for internal use are of
RunInstances tag-on-create
, not CreateTags.

The routing problem, and why not a flag

#468 rules out an internal bypass flag, and the reason holds: a
skip-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. runInstances parses the request's
TagSpecification.N tags, checks them, and delegates to
runInstancesWithTags(reqCtx, req, tags). CreateFleet parses and checks the
caller'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:mine in a CreateFleet
request is rejected (instance- and fleet-scoped), and the fleet's own stamp
still lands alongside the caller's legal Env/Team tags on the same
instance.

Rollback

The check runs before generateReservationID() and the per-instance
state.Put, so nothing is created:

If tags cannot be applied during resource creation, we roll back the resource
creation process. This ensures that resources are either created with tags or
not created at all.

A refused RunInstances launches no instance, a refused CreateImage leaves
behind neither the AMI nor its backing snapshot, and a refused
CreateNatGateway creates no gateway.

Deletions

passthroughFleetTagSpecs and fleetIDTagSpec are both gone. With tags
travelling as values there is no free TagSpecification.N index 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.N loop collapse into one
ec2LaunchTagsForResource.

One deviation from the plan: a fourth copy, and a behaviour change

The plan named three TagSpecification.N parsers besides runInstances. There
were four — passthroughFleetTagSpecs was a fifth copy of the loop that
re-emitted params rather than returning tags.

Folding createImage onto the shared parser is also a behaviour change,
which the plan did not anticipate: createImage hardcoded
TagSpecification.1.Tag.%d and ignored ResourceType entirely. Checked against
the reference before changing it — ResourceType is load-bearing there
(image and snapshot are both valid, and "If you specify other values for
ResourceType, the request fails"), and EC2Snapshot already carries Tags
that DescribeSnapshots emits. So honouring it is a fidelity gain: a request
tagging only its snapshots previously put those tags on the AMI. Called out in
### Changed and in docs/services.md, since a caller asserting on
DescribeImages for snapshot-scoped tags will see them move.

authz.go:519's walk over the same params is deliberately left alone, now with
a comment saying why: it builds aws:RequestTag condition keys, where
filtering by resourceType would 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-versions pass,
go test -C test/e2e ./... ok. The whole pre-existing EC2 and fleet suite
passes unchanged.

Mutation-tested, four mutants, all killed:

Mutation Killed by
drop the check from runInstances RejectsReservedTagKeys (3 subtests), ReservedTagRejectionCreatesNothing
move the check after the launch same — and via the rollback assertion specifically (Should be zero, but was 3), which is the ordering gate
route the fleet stamp back through the checked path the entire fleet suite (9 tests) — the #443 regression the split prevents
stop honouring ResourceType in the shared parser CreateFleet_TagPropagation, FleetIDTagCoexistsWithCallerTags, ReservedTagRejectionCreatesNothing, CreateImage_HonorsTagResourceType

Closes #468

#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

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 1be18e4 into main Aug 2, 2026
16 checks passed
@scttfrdmn scttfrdmn mentioned this pull request Aug 2, 2026
@scttfrdmn
scttfrdmn deleted the fix/468-reserved-tag-keys-on-create branch August 2, 2026 22:02
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: RunInstances and other tag-on-create paths accept reserved aws: tag keys

1 participant