Skip to content

fix(ec2): a valueless tag: filter on DescribeImages matches nothing (#686) - #694

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/686-describeimages-tag-filters
Aug 21, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/686-describeimages-tag-filters

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

describeImages parsed Filter.N itself instead of calling extractEC2Filters, and the
two parsers disagreed in three ways that compounded into one wrong answer.

The defect #686 reports. A tag:<key> filter with no value matched any value:

if t.Key == tagKey && (len(f.values) == 0 || containsStr(f.values, t.Value)) {

That is tag-key's question, and tag-key was unsupported — so this operation had the
wrong spelling of the any-value question and not the right one. DescribeInstances
(default: return false) and DescribeVolumes both match nothing for the valueless form.
AWS settles neither reading: Using_Filtering says only "You can't specify a filter value
of null". Matching nothing is substrate's reading, and it is now substrate's answer at all
three sites rather than two of three.

What the hand-rolled walk added. if fv == "" { break } truncated the value list, so
Filter.1.Value.1= arrived as no values and inherited the rule above. An empty filter
value is a value — it asks for a tag whose value is the empty string — and every other
caller of extractEC2Filters distinguishes the two. Adopting the shared extractor fixes
this and the first defect together, and leaves one filter parser in the plugin instead of
two that disagreed.

What adopting it would have broken, so it is fixed here too. extractEC2Filters keyed
a map by name and overwrote, so a repeated filter name kept only the last. The old walk
appended each Filter.N to a slice and ANDed them, which is right for distinct names —
and extractEC2Filters gets those right too, since they are separate map keys. The
collision is the same name twice, where overwriting silently discarded the first entry
with no indication. AWS documents filters ANDed and values within a filter ORed, and says
nothing about a repeated name; merging the value lists answers it as an OR, which is
substrate's reading. Overwriting was not a reading of anything. This affects every EC2
describe that parses filters
, which is why it is pinned by its own test.

tag-key arrives in the same PR because the first fix takes away the spelling callers were
using for it. Without it the change would be a pure removal.

Fail-before

The issue's acceptance criterion asks that the test pinning the old rule be updated. No
such test existed — only three tests in the repo pin any unknown/empty filter behaviour and
none covers DescribeImages — so emulator/ec2_image_filters_test.go is written here as
the fail-before. Recorded against unfixed code:

Test Before
ValuelessTagFilterMatchesNothing FAIL — tag:Env with no value returned the Env=prod AMI
ExplicitEmptyTagValue FAIL — tag:Env= returned the Env=prod AMI
TagKeyFilter FAIL — the name was dropped, so both AMIs came back
DistinctFilterNamesAreANDed PASS — the regression guard; it must not start failing
RepeatedFilterNameORsItsValues FAIL — verified separately by reverting the append to filters[name] = vals, which returned only staging

Verification

gofmt -l clean, go build ./..., go vet ./..., golangci-lint run ./... (0 issues),
go test -race -count=1 ./emulator/ (full package, no -run filter),
go test -C test/e2e ./..., make docs-reference-check, scripts/check-doc-versions.sh,
npm --prefix docs run build — all pass.

Nothing else needed changing: no test asserts a DescribeImages response byte-exactly, and
no golden-XML fixture exists in the repo.

Compatibility

Three behaviour changes, all named in CHANGELOG.md and docs/services.md: the valueless
tag: form now matches nothing (use tag-key), an explicitly empty filter value is now
honoured as the empty string, and a repeated filter name now ORs rather than dropping the
earlier entry — the last on every EC2 describe, not only this one.

Closes #686

…686)

describeImages parsed Filter.N itself rather than through extractEC2Filters,
and the two disagreed three ways: a tag: filter with no values matched any
value (which is tag-key's job, and tag-key was unsupported); the walk broke
out of its value loop on the first empty string, so an explicitly empty value
arrived as no values at all; and adopting the shared extractor would have
collapsed a repeated filter name to whichever came last.

Adopt extractEC2Filters, fix its map collapse by appending so repeated names
OR their values, and add tag-key so the any-value question keeps a spelling.
@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

❌ Patch coverage is 86.20690% with 4 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/ec2_plugin.go 86.20% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 8c50798 into main Aug 21, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the fix/686-describeimages-tag-filters branch August 21, 2026 05:00
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: describeImages' valueless tag: filter behaves as tag-key, disagreeing with describeInstances

1 participant