Skip to content

fix(ec2): parse every network interface a launch declares (#455) - #558

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/ec2-network-interfaces
Aug 4, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/ec2-network-interfaces

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #455.

NetworkInterface.N.* was parsed for N=1 only, at both sites that read it —
runInstances and createLaunchTemplate — and EC2Instance had no interface list to
hold a second one. So a launch or a template declaring two interfaces was accepted,
answered 200, and quietly became a one-interface instance: no error, and nothing in
the response to reveal the loss. That is this release's shape, reached by a sixth
route.

What changed

Both sites parse all N, by the convention every other indexed list in the plugin
follows — contiguously from 1, stopping at the first missing index (indexedParams),
extended from a string per index to a struct per index. An index counts as present
when any of its members is, since a specification naming only DeviceIndex and
SubnetId is as real as one naming ten, and requiring a chosen member would drop an
interface for spelling reasons.

Identity is keyed on DeviceIndex, not the parameter index. The reference defines
DeviceIndex as "the position of the network interface in the attachment order" and
does not require it to agree with the position the request writes the interface at, so
NetworkInterface.1.DeviceIndex=3 with NetworkInterface.2.DeviceIndex=0 makes the
second one primary. An implementation using the parameter index would name the wrong
interface primary and put the wrong subnet on the instance — verified live:

$ aws ec2 run-instances … --network-interfaces 'DeviceIndex=3,SubnetId=$SB' 'DeviceIndex=0,SubnetId=$SA'
{"TopLevelSubnet": "subnet-…A", "DevOrder": [0, 3]}

RunInstances and DescribeInstances now report networkInterfaceSet>item.
That was decided from the reference rather than assumed: the RunInstances sample
response carries the member, so a caller parsing the documented shape found it
missing. Reporting it on both means the interfaces a launch declared are readable back
without a follow-up describe.

The instance's flat subnetId, privateIpAddress and groupSet continue to describe
the primary interface, which is what real EC2 puts at the top level — they are not
superseded by the new set. AssociatePublicIpAddress is still honored only on the
primary, as the reference requires ("can only be assigned to a network interface for
eth0"); a secondary interface asking for a public IP is not a statement about the
instance's.

DeleteOnTermination defaults per the reference's reasoning rather than to one value:
true for an interface the launch creates, false for an existing one it attaches by
NetworkInterfaceId, since deleting an interface the caller brought would destroy
something the launch did not make. An explicit value wins over either.

Replay

Both the instance and the launch-template shapes grew a slice, so both keep their flat
fields as the primary's values. An instance or a template version stored by an earlier
substrate reads back with an empty slice, and ec2LTVersionData's single-interface
synthesis from the flat fields still runs for it — so a replayed event log still
launches into the right subnet with the right groups and still describes its
networking rather than reporting an empty set over a record that plainly holds a
subnet. TestEC2NetworkInterfaces_PreSliceTemplateStateStillWorks writes that stored
shape by hand, because CreateLaunchTemplate can no longer produce it — which is what
makes it a migration gate rather than a round-trip.

Substrate's own choices

Recorded in docs/services.md, since the API model does not decide them:

  • A secondary interface naming no PrivateIpAddress is given one derived from its
    instance index and device index, so every interface of every instance in a
    multi-Count launch has a distinct, replay-stable address a test can assert on. AWS
    refuses a launch that names an address with a count above one; substrate does not,
    so it has to make them differ.
  • There are no standalone ENI resources — CreateNetworkInterface is not modeled,
    so an interface exists only as part of the instance that declared it and an eni-
    ID is minted for one the request did not name. A launch declaring no interface
    reports an empty set rather than a synthesized phantom eth0.
  • Interfaces report status: in-use and attachment status: attached immediately,
    because substrate's instances are already running when RunInstances answers; an
    attaching attachment would contradict the instance state reported beside it.

Tests

16 tests in emulator/ec2_network_interfaces_test.go, asserting on the wire XML
rather than the stored record — an interface substrate parses and stores but does not
report is a write with no observable, which is the defect shape this release is about.
The gate was proven both ways: with the four source files at HEAD, 13 of 16 fail;
the 3 that pass are the deliberate no-regression guards. The whole existing EC2 suite
passes unedited, which is what proves the index-1 path is unchanged.

Mutation testing: 24 mutants, 23 CAUGHT, 1 EQUIVALENT with a written proof, 0
survivors.
Both mutants the plan named by name are caught by a single test each — the
parse loop not stopping at the first gap (_GapStopsTheParse) and DeviceIndex
ignored in favour of the parameter index (_DeviceIndexKeysIdentity). The equivalent
one replaces ec2PrimaryInterface's lowest-device-index comparison with "first entry":
all three call sites sort ascending immediately before calling it, so interfaces[0]
is the lowest at every call and no observable distinguishes them. The comparison is
defense in depth against a future caller that does not sort, and the sort it leans on
is itself covered by a mutant that reverses it, caught by 8 tests.

networkInterfaceSet was mutated out of each response builder separately, since a
test that only reads one of them would not prove the other.

Verification

gofmt -l ., go build ./..., go vet ./..., golangci-lint run ./... → 0
issues
, make test (race) green, make docs-reference docs-reference-check docs-versions clean (no plugin added, so the generated tables are unchanged),
npm --prefix docs run build, go vet -C test/e2e ./..., go test -C test/e2e ./....

Live against substrate server: a two-interface run-instances reports 2
interfaces in both the RunInstances response and describe-instances (was 1), a
two-interface template describes both versions' interfaces and launches with both, a
brought ENI reports DeleteOnTermination: false beside a created one's true, and a
launch declaring none reports 0.

Compatibility

A test asserting that a multi-interface launch yields one interface, or that an
instance item has no networkInterfaceSet, will go red — that is the fix.

NetworkInterface.N.* was read for N=1 only, in both runInstances and
createLaunchTemplate, and EC2Instance had no interface list to hold a
second one — so a launch or a template declaring two interfaces was
answered 200 and quietly became a one-interface instance.

Both sites now parse all N by the indexedParams convention: contiguously
from 1, stopping at the first missing index. Identity is keyed on
DeviceIndex rather than the parameter index, which the reference defines
as the position in the attachment order and does not require to agree
with the position the request writes the interface at.

RunInstances and DescribeInstances both report networkInterfaceSet — the
RunInstances reference's own sample response carries it. The flat
subnetId, privateIpAddress and groupSet continue to describe the primary
interface, as real EC2 does, so an instance or launch-template version
stored by an earlier substrate reads back with an empty slice and its
flat fields still describe its one interface.

Signed-off-by: Scott Friedman <[email protected]>
@codecov

codecov Bot commented Aug 4, 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 b6ae33b into main Aug 4, 2026
16 checks passed
@scttfrdmn
scttfrdmn deleted the feat/ec2-network-interfaces branch August 9, 2026 17:48
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: only network interface index 1 is modeled on RunInstances and launch templates

1 participant