Repository navigation
fix(ec2): one rule for an unrecognized filter name — refuse it (#687) - #698
Merged
Merged
Conversation
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
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
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.
Closes #687
A
Filter.N.Nameoutside the set an operation's own API reference documents now answersInvalidParameterValue/The filter "<name>" is not valid for this request, HTTP 400, onall 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:
DescribeVolumes,DescribeSnapshots,DescribeSecurityGroups,DescribeRouteTables,DescribeNatGateways,DescribeFleets,DescribeImagesDescribeInstancesDescribeInstanceTypeOfferingsTwo 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.gocarries oneec2FilterSpecper operation:Three design points, each load-bearing:
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 onDescribeInstances, refused onDescribeFleetsandDescribeInstanceTypeOfferings,which document no tag filter at all — even though a fleet carries tags and
DescribeFleetsrenders them. That is AWS's set, not an omission in the transcription, so
tagValueFilteris per spec and cannot be inferred from the presence of
tag-key.ec2IDFilter.unresolvedalready documents thesame 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.
checkwalksFilter.Nin 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' ownbespoke 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
encryptedor
ipv6-cidr-block-association.statewould deny a filter real EC2 accepts. Those names arenow listed per operation in
docs/services.mdrather than left to be discovered.DescribeInstances' inert case changes with them:default: return falsebecomesreturn true. That branch was defensible while an unknown name landed there too ("neverreturn 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_Filteringnor the
Filtertypesays 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 therelease's
## Provenance.InvalidParameterValueis the documented code; the message text is substrate's own(
ec2InvalidFilterError, unchanged and now with nine callers instead of one), so a consumershould dispatch on the code.
What AWS does document, and this PR relies on: filter names and values are
case-sensitive (so
VPC-Idis refused), filters AND, and values within one filter OR.Fail-before
Recorded by neutralizing the refusal (
return ec2InvalidFilterError(name)→continue), byfile copy with restoration verified byte-identical — never
git stash, andgofmt -w+go vetfirst so a non-compiling mutant would be BROKEN rather than a result. Full-packagerun, no
-runfilter: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 falseinec2InstanceMatchesFilter's default arm) failsTestEC2_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 performer 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:
InertMeansEveryResourceasserts the returned instance IDs, not the status: an emptyresult set is also HTTP 200, so status alone cannot tell inert from match-nothing.
CaseIsSignificantpinsVPC-Id/Tag-Key/Instance-Idas refused, per theFiltertype's "Filter names are case-sensitive".
RefusalIsDeterministicsends two undocumented names 20 times and asserts the first inrequest order is the one reported — a map-order implementation passes once by luck, not
twenty times.
TagFilterFollowsTheOperationpins both directions of theDescribeFleetssplit.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
counthelper that decodes an error document to zero instances, so it wouldhave kept passing after the refusal landed. It now asserts 400 +
InvalidParameterValuethrough
ec2ErrorDetail.ec2_volume_tags_test.go's "an unknown filter name is still dropped" row now pins thedocumented-but-unevaluated case (
encrypted=false→ every volume), which is thebehaviour that survives.
Deliberately out of scope
Three gaps, each now filed and named in the docs rather than left implicit:
Filter.Nat all. Bringing them inwould newly refuse filters callers pass harmlessly today, in a change whose point is
consistency, and each needs its own reference page transcribed first.
DescribeInstanceTypeOfferings; everywhere else matching is exact. AWS documents wildcardsgenerally, so this is a real divergence, but it is orthogonal to filter names.
DescribeSecurityGroupsand inec2FilterAccepts, where it matches nothing elsewhere. Both sites carry a comment arguingfor what they do; those arguments need answering, not deleting.
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.
DescribeInstancesadditionally changes what such an accepted-but-unevaluated name answers,from an empty set to every instance.
Docs
docs/services.mdgains One rule for an unrecognized filter name — the rule, itsprovenance, 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:), andthe three gaps above. The three sites that asserted the old three-behaviour split — the
DescribeVolumestag-filter prose, theDescribeImagesfilter prose and the offeringssection — now point at it, as does
ec2_block_devices.go's comment that spelled the splitout. Six operations-table rows link to it.
The table also states the surface's weakest point in the other direction: only
DescribeInstances,DescribeVolumesandDescribeImagesactually filter on tags, so onsnapshots, security groups, route tables and NAT gateways a
tag:<key>filter is acceptedand inert. #685 and #688 close that.
Verification