Repository navigation
Description
Summary
EC2Plugin.describeInstances only parses a single filter (Filter.1.Name / Filter.1.Value.*) and only applies it if its key is instance-state-name. Any second-or-later filter (Filter.2+) is silently ignored, and tag:* filters are never applied at all. This makes DescribeInstances return instances the caller explicitly filtered out.
Where
ec2_plugin.go, describeInstances (~line 495):
filterNames := extractIndexedParams(req.Params, "Filter.1.Value")
filterKey := req.Params["Filter.1.Name"]
...
// Filter by state name.
if filterKey == "instance-state-name" && len(filterNames) > 0 && !containsStr(filterNames, inst.State.Name) {
continue
}Only Filter.1 is read, and the only key handled is instance-state-name.
Repro (real client behavior)
A client (e.g. spawn list --state running) issues DescribeInstances with two filters, tag first:
Filter.1=tag:spawn:managed = trueFilter.2=instance-state-name = running
Substrate reads only Filter.1 (tag:spawn:managed), which it doesn't know how to apply, so it applies nothing — and Filter.2 (the state filter) is never read. Result: a terminated instance (state code 48) is still returned for a running-only query.
Sequence:
- RunInstances → instance
i-…running. - TerminateInstances
i-…→ state correctly set to{Code:48, Name:"terminated"}and persisted (terminate is fine). - DescribeInstances with
Filter.1=tag:spawn:managed=true,Filter.2=instance-state-name=running→ terminated instance still returned.
If the state filter happens to be Filter.1, it works; any other position fails. So this is order-dependent, which is its own correctness smell.
Root cause
describeInstances predates the general-purpose extractEC2Filters helper (line ~2297) and never adopted it. That helper already parses all Filter.N.Name / Filter.N.Value.M pairs correctly.
Proposed fix
Use extractEC2Filters(req.Params) and apply every returned filter, AND-combining them. At minimum support the filter keys real callers use:
instance-state-name(matchinst.State.Name)instance-id(matchinst.InstanceID)tag:<key>(match a tag whose Key ==<key>and Value ∈ allowed values)tag-key(instance has a tag with that key, any value)instance-type,availability-zone/placement.availability-zone,vpc-id,subnet-id,key-name
Unknown filter keys: AWS errors with InvalidParameterValue; emulating "match nothing" (return empty) is acceptable and safer than silently ignoring. Whatever is chosen, it must not silently pass.
Impact
- Breaks
instance-state-namefiltering whenever it isn't the first filter (common — clients usually lead with atag:filter). tag:filtering doesn't work at all, so callers relying on server-side tag filtering get over-broad result sets.- Surfaced while building spawn's Tier 0 CLI-against-substrate integration suite:
TestTier0_TerminateRemovesFromListsaw a terminated instance still listed asrunning.
Acceptance
- All
Filter.Nparsed (not justFilter.1); filters AND-combined. tag:<key>,instance-id,instance-state-namefiltering all work regardless of filter order.- Unit test: launch + terminate, then DescribeInstances with
[tag:spawn:managed=true, instance-state-name=running]returns the instance before terminate and excludes it after. - Existing EC2 suite stays green.
Activity
fix: DescribeInstances multi-filter + tag: support (#305); bump Go to…