Skip to content

fix(ec2): a subnet reports its tags and filters on them; a snapshot honours its own (#685) - #699

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/685-subnet-snapshot-tags-filters
Aug 21, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/685-subnet-snapshot-tags-filters

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #685.

DescribeSubnets parsed no Filter.N at all and rendered no tagSet, so a request for
"the subnets of vpc-x" answered with every subnet in the region — with nothing in the
response to say the filter had been ignored — and every tag a caller applied to a subnet was
stored and invisible. DescribeSnapshots evaluated one of the fourteen filter names its
reference documents and read neither Owner.N nor RestorableBy.N.

Subnets

  • CreateSubnet honours TagSpecification.N scoped to subnet, under the same two rules
    every other tag path enforces (reserved aws: prefix, 50-tag limit); a refused request
    creates no subnet. Without it the filters below have nothing to find on a subnet the caller
    just made, which is how CDK and Terraform set tags.

  • One shared Subnet element for CreateSubnet and DescribeSubnets, which is what AWS
    documents. They rendered different subsets before — create omitted mapPublicIpOnLaunch, and
    neither carried tags, an ARN, an owner or defaultForAz — so a caller reading the create
    response saw a different subnet from the one it could describe. A test asserts the two are
    equal.

  • New members: tagSet, subnetArn, ownerId, defaultForAz. The ARN and owner are what
    subnet-arn and owner-id compare against, so rendering them is what lets a caller
    round-trip a value it read. ec2SubnetARN is now the one spelling, shared by the filter, the
    response and ec2_authz.go's launch resolver.

  • Eleven filters plus AWS's four inline aliases (availabilityZone, cidr, cidrBlock,
    defaultForAz), each answered beside its canonical name rather than normalized away — they
    are distinct names on the wire, and folding them would leave the documented alias silently
    inert. cidr-block is exact, per AWS's own sentence about it. The fourteen documented names
    substrate keeps no state for are accepted and inert; anything outside the twenty-five is
    refused by ec2: three inconsistent unknown-filter-name behaviours, where real AWS refuses #687's spec, which this PR gives the operation.

  • tagSet is absent on an untagged subnet, not present-and-empty: both of AWS's
    DescribeSubnets samples omit it. DescribeSnapshots' present-but-empty tagSet is left
    alone because its own page shows that shape — per-operation evidence, not a house rule.

    Worth recording for the next person: xml:"tagSet>item,omitempty" does not omit the
    parent element — encoding/xml emits <tagSet></tagSet> for a nil slice on a nested path.
    Omission needs a pointer-to-wrapper struct, verified empirically both ways (it decodes
    identically through tagSet>item). PR 6 (ec2: render CreateLaunchTemplate's warning/ValidationWarning element #693) needs the same shape for its warning member.

Snapshots

  • Ten of fourteen filters applied: description, encrypted, owner-id, snapshot-id,
    start-time, status, tag-key, tag:<key>, volume-id, volume-size. The other four
    (owner-alias, progress, storage-tier, transfer-type) name members substrate does not
    render, so there is nothing to compare against — accepted and inert.
  • Owner.N and RestorableBy.N honoured, with single-account semantics: self and the
    requesting account's ID match everything; anything else, amazon included, matches
    nothing, because answering "snapshots owned by amazon" with the account's own snapshots
    would claim they were public.
  • Ordering: ids.match runs before the filter match on both operations, so a resource a
    filter excluded still counts as resolved — naming an existing ID and filtering it out is an
    empty 200, not a NotFound. That is the rule ec2IDFilter.unresolved documents, and the
    difference between "not yet" and "never" to a consumer's wait loop.

Also in the same neighbourhood

The EC2 plugin's last two function-local tagItem copies (describeSnapshots,
describeFleets) are deleted in favour of the package-level ec2TagItems, finishing what #686
started. All four shapes matched, so nothing observable changes.

Fail-before proof

Recorded before the fix, with the anchor count asserted == 1 over the whole file, the file
copied to a .orig and restored in a finally with byte-identity checked by sha256, and
gofmt -w + go vet so a non-compiling mutant is BROKEN rather than a result. Full-package
runs, no -run filter.

Snapshots — the pre-#685 handler body (snapshot-id only, Owner.N/RestorableBy.N
unread): 15 subtests plus 4 parent tests fail. _StartTimeMatchesItsOwnSnapshot and
_InertFiltersReturnEverything correctly still pass — the first because its assertion is
positive, the second because inert is what the old code did to everything.

Subnets, two mutations:

Mutation Result
describeSubnets applies no filters (_ = filters) exit 1, 26 tests fail
createSubnet ignores TagSpecification.N (Tags: nil) exit 1, 8 tests fail — including the four tag* filter subtests, _TagSetIsAbsentWhenUntagged and _TagsOnCreateAndAgreesWithDescribe

Restore verified byte-identical after every mutation.

The first attempt at the second mutation printed ANCHOR COUNT 2 - skipped rather than
mutating: Tags: tags, appears in both createSubnet and createVolume. The
anchor was widened to include the neighbouring State: line rather than mutating blindly.

Tests

Two new files, 40-plus subtests. The fixture worth explaining: default-for-az and
map-public-ip-on-launch are only testable in both directions because a launch with no
SubnetId mints a default subnet with both true — createDefaultSubnet is the sole writer of
either. _TagSetIsAbsentWhenUntagged asserts on the raw body, since a decoder reports an
absent element and an empty one identically.

Verification

gofmt -l ., go build ./..., go vet ./..., golangci-lint run ./... (0 issues),
make test (race), make coverage (82.2% total, emulator 82.8%),
make docs-reference docs-reference-check docs-versions, npm --prefix docs run build,
go vet -C test/e2e ./... && go test -C test/e2e ./... — all clean.

Docs

docs/services.md gains two subsections (a subnet's tags and filters; a snapshot's filters and
account scopes), a DescribeSubnets row and a corrected DescribeSnapshots row in #687's
per-operation Evaluated/Inert table, and three corrections the change makes necessary: five
operations now filter on tags rather than three, DescribeSubnets is the tenth operation the
refusal rule covers, and #695's never-parse list drops from fourteen operations to thirteen
(verified by enumerating the dispatch arms, not by subtraction).

…onors its own (#685)

DescribeSubnets parsed no Filter.N at all and rendered no tagSet, so "the
subnets of vpc-x" answered with every subnet in the region and every tag a
caller had applied to a subnet was stored and invisible. DescribeSnapshots
evaluated one of the fourteen names its reference documents and read neither
Owner.N nor RestorableBy.N.

CreateSubnet now honors TagSpecification.N scoped to subnet, under the same
reserved-prefix and 50-tag rules every other tag path enforces, and both
subnet operations render one shared Subnet element — they previously rendered
different subsets of it. The element gains tagSet, subnetArn, ownerId and
defaultForAz; tagSet is absent on an untagged subnet, per both of AWS's
samples for this operation.

DescribeSnapshots applies ten of its fourteen filters, the other four naming
members substrate does not render, and honors Owner.N/RestorableBy.N with
single-account semantics: self and the own account match everything, amazon
and any other account match nothing.

Also deletes the EC2 plugin's last two function-local tagItem copies and
unifies the subnet ARN behind ec2SubnetARN, which the subnet-arn filter, the
response and the authorization resolver now all share.
@codecov

codecov Bot commented Aug 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.79518% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/ec2_plugin.go 94.44% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit ff5f0b7 into main Aug 21, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the fix/685-subnet-snapshot-tags-filters branch August 21, 2026 05:54
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: DescribeSubnets renders no tagSet and applies no filters at all

1 participant