Skip to content

fix(ec2): a filter naming no values matches nothing, everywhere (#696) - #717

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/696-empty-filter-value-list
Aug 21, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/696-empty-filter-value-list

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Three EC2 describes answered a Filter.N entry naming no Value.N with every resource, where the other nine answered with none.

The permissive three were DescribeSecurityGroups — whose group-name, vpc-id and group-id arms each carried a hand-written ok && len(vals) > 0 && guard — and DescribeTags and DescribeInstanceTypeOfferings, which both route their value comparisons through ec2FilterAccepts. The nine strict ones got there by calling containsStr with no guard at all, which is why the split was never deliberate on their side.

Corrections to the issue body

  • "Each existing comment argues for the behaviour it has" is half false. Only ec2FilterAccepts carried a rationale; the three describeSecurityGroups arms carried no comment whatsoever.
  • Two operations undercounts it. Three diverged — DescribeTags inherits the permissive rule through the shared matcher, which ec2: DescribeTags is unimplemented #688 recorded at the time as something to reconcile here.

The decision

An empty value list matches nothing, on every operation. AWS documents no rule — Using_Filtering says only that "You can't specify a filter value of null" — so both answers were readings, and what made this a defect is the disagreement rather than either answer. #686 had already settled the same question for tag:<key> on DescribeImages, so the two permissive sites converge on the nine strict ones rather than the other way round.

The old rationale was that dropping every result turns a malformed request into a silently empty answer. The unfiltered answer is silent in exactly the same way and wrong in the more dangerous direction: a caller who asked for a subset and got everything back cannot distinguish that from a genuine match on every resource. ec2FilterAccepts' comment is rewritten to record the reversal rather than deleted, per the issue's own criterion, and ec2TagMatchesFilter's now-false sentence ("ec2FilterAccepts answers it by matching everything") is corrected.

The nil-slice trap

describeInstanceTypeOfferings passed filters["instance-type"] straight into the matcher. A bare map index yields the same nil slice for absent and for present with no values, so under the new rule an unfiltered query would have returned an empty catalog. Both lookups move to the two-value form; extractEC2Filters records a valueless filter as a present key with a nil value, so ok distinguishes them. ec2FilterAccepts' doc comment now states that contract for future callers. The pre-existing "no filter returns the whole catalog" row in TestEC2_DescribeInstanceTypeOfferings_InstanceTypeFilter is the other half of that guard.

Blast radius

Quiet. An over-broad answer becomes an empty one; nothing that succeeds today starts failing. Two distinctions are untouched:

  • A filter carrying one empty value (Filter.1.Value.1=) asks for the empty string and is a value like any other — DescribeTags' own Example 6 does this, and ec2_describetags_test.go:144 pins it.
  • An absent filter still constrains nothing.

Tests

New emulator/ec2_valueless_filter_test.go. All three operations, every evaluated filter name on each — the SG guard was written out three times, so fixing two of three would have left the divergence standing on the third. Plus TestEC2_ValuelessFilter_MajorityOperationsUnchanged, which asserts the convergence went in the right direction on DescribeSnapshots, DescribeImages and DescribeSubnets.

Fail-before verified by restoring the three source files and re-running: all twelve subtests fail, and the majority-unchanged test is green both before and after — nothing in it had to change to make the fix pass.

Docs

docs/services.md' "Filter semantics that apply everywhere" gains the general rule, replacing the tag:<key>-only bullet, and states the absent-vs-valueless-vs-empty-value distinction. The "Two gaps, deliberately left standing" paragraph loses its third gap, and its #695 count is corrected from thirteen describes to twelve — DescribeSubnets (#685) and DescribeTags (#688) have both landed since it was written.

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

Closes #696

Three EC2 describes answered a valueless Filter.N with every resource:
DescribeSecurityGroups, whose group-name, vpc-id and group-id arms each
carried a hand-written `len(vals) > 0` guard, and DescribeTags and
DescribeInstanceTypeOfferings, which share ec2FilterAccepts. The other
nine matchers already selected nothing, by calling containsStr with no
guard at all.

AWS documents no rule here — Using_Filtering says only that "You can't
specify a filter value of null" — so both answers were readings, and the
defect was the disagreement rather than either answer. The two permissive
sites converge on the nine strict ones, extending the rule #686 settled
for tag:<key> on DescribeImages.

The old rationale was that dropping every result turns a malformed
request into a silently empty answer. But the unfiltered answer is silent
in the same way and wrong in the more dangerous direction: a caller who
asked for a subset and got everything cannot tell that from a genuine
match on every resource. ec2FilterAccepts' comment is rewritten to say
so rather than deleted, and ec2TagMatchesFilter's stale sentence — which
said the shared matcher "answers it by matching everything" — is
corrected.

describeInstanceTypeOfferings now looks its two filters up with the
two-value map form. A bare filters[name] index yields the same nil slice
for "absent" and "present with no values", which under the new rule would
have emptied the catalog for an unfiltered query; extractEC2Filters
records a valueless filter as a present key, so `ok` tells them apart.

Quiet change: an over-broad answer becomes an empty one, and nothing that
succeeds today starts failing. A filter carrying one *empty* value
(Filter.1.Value.1=) still asks for the empty string, which is what
DescribeTags' Example 6 does, and an absent filter still constrains
nothing.

Closes #696
@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 0ec80c1 into main Aug 21, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the fix/696-empty-filter-value-list branch August 21, 2026 23:25
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: an empty filter value list matches everything on DescribeSecurityGroups and in ec2FilterAccepts

1 participant