Skip to content

fix(ec2): one rule for an unrecognized filter name — refuse it (#687) - #698

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/687-unrecognized-ec2-filter-name
Aug 21, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/687-unrecognized-ec2-filter-name

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #687

A Filter.N.Name outside the set an operation's own API reference documents now answers
InvalidParameterValue / The filter "<name>" is not valid for this request, HTTP 400, on
all nine EC2 describes that parse filters.

The defect

Substrate had three answers to the same mistake, not the three the issue names in that
order — the issue says three behaviours exist and it is right about the count, but the
mapping is worth stating exactly:

Former behaviour Operations
Dropped — the filter constrained nothing, so the query returned everything DescribeVolumes, DescribeSnapshots, DescribeSecurityGroups, DescribeRouteTables, DescribeNatGateways, DescribeFleets, DescribeImages
Matched nothing — the query returned nothing DescribeInstances
Refused DescribeInstanceTypeOfferings

Two of the three came back inside a successful response, so a consumer's test could pass
on a filter that was never applied.

The change

A new emulator/ec2_filters.go carries one ec2FilterSpec per operation:

type ec2FilterSpec struct {
	evaluated      []string // substrate applies these
	accepted       []string // AWS documents them; substrate has no state to answer them
	tagValueFilter bool     // whether the operation documents tag:<key>
}

Three design points, each load-bearing:

  • Each list is transcribed from that operation's own reference page, not shared between
    them. AWS documents different filters for each, so a shared list would refuse a name one
    operation accepts because a sibling does not. tag:<key> is the conspicuous case: valid on
    DescribeInstances, refused on DescribeFleets and DescribeInstanceTypeOfferings,
    which document no tag filter at all — even though a fleet carries tags and DescribeFleets
    renders them. That is AWS's set, not an omission in the transcription, so tagValueFilter
    is per spec and cannot be inferred from the presence of tag-key.
  • The check runs before the state scan. ec2IDFilter.unresolved already documents the
    same ordering rule from the other side ("a resource that a filter excluded still counts as
    resolved"), so a refusal must not depend on whether any resource matched. An empty account
    and a populated one answer a typo identically.
  • check walks Filter.N in request order, not the extracted map. A map has no order:
    given two undocumented names, the map form would name an arbitrary one and two replays of
    one recorded request could report different refusals. describeInstanceTypeOfferings' own
    bespoke check had exactly this defect and is deleted in favour of the spec.

Refusal reproduces AWS's set, not substrate's coverage

The two lists are what keeps the refusal from exceeding real EC2's. A name AWS documents
that substrate keeps no state to answer stays accepted and inert — refusing encrypted
or ipv6-cidr-block-association.state would deny a filter real EC2 accepts. Those names are
now listed per operation in docs/services.md rather than left to be discovered.

DescribeInstances' inert case changes with them: default: return false becomes
return true. That branch was defensible while an unknown name landed there too ("never
return resources the caller meant to exclude"), but a refused typo answers that concern
directly, and match-nothing is the worse half of the remaining choice — an empty answer
cannot be told apart from "the resource does not exist", so a consumer's wait loop polls
forever where over-matching fails once and visibly. Neither answer is real EC2's, which
would apply the filter; only one of them can be a single rule.

Provenance

Refusal is real EC2's observed behaviour, not its documented behaviour. Neither
Using_Filtering
nor the Filter type
says what happens to a name outside the documented set — both are silent. Recorded in
ec2FilterSpec.check's doc comment, the CHANGELOG and the docs, and it belongs in the
release's ## Provenance.

InvalidParameterValue is the documented code; the message text is substrate's own
(ec2InvalidFilterError, unchanged and now with nine callers instead of one), so a consumer
should dispatch on the code.

What AWS does document, and this PR relies on: filter names and values are
case-sensitive (so VPC-Id is refused), filters AND, and values within one filter OR.

Fail-before

Recorded by neutralizing the refusal (return ec2InvalidFilterError(name) → continue), by
file copy with restoration verified byte-identical — never git stash, and gofmt -w +
go vet first so a non-compiling mutant would be BROKEN rather than a result. Full-package
run, no -run filter:

--- FAIL: TestEC2_FilterNames_UndocumentedNameRefused              (all 9 subtests)
--- FAIL: TestEC2_FilterNames_CaseIsSignificant                    (all 3 subtests)
--- FAIL: TestEC2_FilterNames_TagFilterFollowsTheOperation/refused_where_the_operation_documents_no_tag_filter
--- FAIL: TestEC2_FilterNames_RefusalIsDeterministic
--- FAIL: TestEC2_FilterNames_UndocumentedNameRefusedBeforeTheScan
--- FAIL: TestEC2_DescribeInstanceTypeOfferings_UnknownFilterRefused (all 3 subtests)
--- FAIL: TestEC2_DescribeInstances_FilterOrderIndependent
RESTORED identical: True

The last two are pre-existing tests, which is the point: the offerings operation's refusal
still holds after its bespoke check was deleted.

A second mutation for the inert change (return true → return false in
ec2InstanceMatchesFilter's default arm) fails TestEC2_FilterNames_InertMeansEveryResource
(all 3 subtests) and nothing else — no existing test depended on match-nothing.

Tests

emulator/ec2_filter_names_test.go, new, six tests. The issue asks for "one operation per
former behaviour class"; the table covers all nine operations rather than three, since each
spec is transcribed separately and a fabricated or missing name would be a false deny —
the failure mode worth over-testing. Beyond the classes:

  • InertMeansEveryResource asserts the returned instance IDs, not the status: an empty
    result set is also HTTP 200, so status alone cannot tell inert from match-nothing.
  • CaseIsSignificant pins VPC-Id/Tag-Key/Instance-Id as refused, per the Filter
    type's "Filter names are case-sensitive".
  • RefusalIsDeterministic sends two undocumented names 20 times and asserts the first in
    request order
    is the one reported — a map-order implementation passes once by luck, not
    twenty times.
  • TagFilterFollowsTheOperation pins both directions of the DescribeFleets split.

Two existing assertions were rewritten rather than extended:

  • ec2_plugin_test.go's "Unknown filter key matches nothing" passed for the wrong reason
    — it used a count helper that decodes an error document to zero instances, so it would
    have kept passing after the refusal landed. It now asserts 400 + InvalidParameterValue
    through ec2ErrorDetail.
  • ec2_volume_tags_test.go's "an unknown filter name is still dropped" row now pins the
    documented-but-unevaluated case (encrypted=false → every volume), which is the
    behaviour that survives.

Deliberately out of scope

Three gaps, each now filed and named in the docs rather than left implicit:

Compatibility

A filter name that was silently dropped — including a typo — now produces
InvalidParameterValue/400.
That is real EC2's behaviour and the reason the issue exists,
but it will break a caller who misspelled a filter and never noticed. A documented name
substrate cannot evaluate is not affected: it stays accepted.

DescribeInstances additionally changes what such an accepted-but-unevaluated name answers,
from an empty set to every instance.

Docs

docs/services.md gains One rule for an unrecognized filter name — the rule, its
provenance, the three-way split (evaluated / inert / refused), a per-operation table of both
lists, the shared semantics (AND/OR, repeated names, case-sensitivity, valueless tag:), and
the three gaps above. The three sites that asserted the old three-behaviour split — the
DescribeVolumes tag-filter prose, the DescribeImages filter prose and the offerings
section — now point at it, as does ec2_block_devices.go's comment that spelled the split
out. Six operations-table rows link to it.

The table also states the surface's weakest point in the other direction: only
DescribeInstances, DescribeVolumes and DescribeImages actually filter on tags, so on
snapshots, security groups, route tables and NAT gateways a tag:<key> filter is accepted
and inert. #685 and #688 close that.

Verification

gofmt -l . && go build ./... && go vet ./... && golangci-lint run ./...   # 0 issues
make test                                                                 # race, green
make coverage                                                             # emulator 82.8%, total 82.1%
make docs-reference docs-reference-check docs-versions
npm --prefix docs run build
go vet -C test/e2e ./... && go test -C test/e2e ./...

A Filter.N.Name outside the set an operation's own API reference documents now
answers InvalidParameterValue / `The filter "<name>" is not valid for this
request`, HTTP 400, on all nine EC2 describes that parse filters.

Substrate had three answers to the same mistake: dropped (volumes, snapshots,
security groups, route tables, NAT gateways, fleets, images), matched nothing
(instances), refused (instance-type offerings). So a typo returned everything,
nothing, or an error depending on which operation received it — and in two of the
three cases inside a successful response, where a consumer's test could pass on a
filter that was never applied.

A new ec2FilterSpec carries each operation's documented names, transcribed from
that operation's own reference page rather than shared between them, because AWS
documents different filters for each: tag:<key> is valid on DescribeInstances and
refused on DescribeFleets, which documents no tag filter at all. The check runs
before the state scan, so a refusal never depends on whether a resource matched,
and it walks Filter.N in request order rather than the extracted map, so two
undocumented names produce the same refusal on every replay.

Refusal reproduces AWS's documented set, not substrate's coverage: a name AWS
documents that substrate keeps no state to answer stays accepted and inert, since
refusing `encrypted` would deny a filter real EC2 accepts. Those names are now
listed per operation in docs/services.md. DescribeInstances' inert case changes
with them — it matched nothing, which cannot be told apart from "the resource does
not exist" — so a wait loop polled forever where over-matching fails once.

Provenance: refusal is real EC2's observed behavior. Neither Using_Filtering nor
the Filter type's page says what happens to an unrecognized name.

Closes #687
@scttfrdmn scttfrdmn added this to the v0.106.0 milestone Aug 21, 2026
@codecov

codecov Bot commented Aug 21, 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 bbbe193 into main Aug 21, 2026
23 of 24 checks passed
@scttfrdmn
scttfrdmn deleted the fix/687-unrecognized-ec2-filter-name branch August 21, 2026 05:26
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: three inconsistent unknown-filter-name behaviours, where real AWS refuses

1 participant