Repository navigation
fix(ec2): a filter naming no values matches nothing, everywhere (#696) - #717
Merged
Merged
Conversation
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 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.
Three EC2 describes answered a
Filter.Nentry naming noValue.Nwith every resource, where the other nine answered with none.The permissive three were
DescribeSecurityGroups— whosegroup-name,vpc-idandgroup-idarms each carried a hand-writtenok && len(vals) > 0 &&guard — andDescribeTagsandDescribeInstanceTypeOfferings, which both route their value comparisons throughec2FilterAccepts. The nine strict ones got there by callingcontainsStrwith no guard at all, which is why the split was never deliberate on their side.Corrections to the issue body
ec2FilterAcceptscarried a rationale; the threedescribeSecurityGroupsarms carried no comment whatsoever.DescribeTagsinherits 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>onDescribeImages, 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, andec2TagMatchesFilter's now-false sentence ("ec2FilterAcceptsanswers it by matching everything") is corrected.The nil-slice trap
describeInstanceTypeOfferingspassedfilters["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;extractEC2Filtersrecords a valueless filter as a present key with a nil value, sookdistinguishes them.ec2FilterAccepts' doc comment now states that contract for future callers. The pre-existing "no filter returns the whole catalog" row inTestEC2_DescribeInstanceTypeOfferings_InstanceTypeFilteris 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:
Filter.1.Value.1=) asks for the empty string and is a value like any other —DescribeTags' own Example 6 does this, andec2_describetags_test.go:144pins it.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. PlusTestEC2_ValuelessFilter_MajorityOperationsUnchanged, which asserts the convergence went in the right direction onDescribeSnapshots,DescribeImagesandDescribeSubnets.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 thetag:<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#695count is corrected from thirteen describes to twelve —DescribeSubnets(#685) andDescribeTags(#688) have both landed since it was written.Closes #696