Skip to content

--efa attaches one EFA per network card; Elastic IP for multi-interface launches (#661) - #1206

Merged
scttfrdmn merged 3 commits into
mainfrom
fix/661-multi-card-efa
Oct 20, 2026
Merged

scttfrdmn merged 3 commits into
mainfrom
fix/661-multi-card-efa

Conversation

@scttfrdmn

@scttfrdmn scttfrdmn commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #661.

The change. spawn launch --efa now attaches every EFA interface the type supports, one per network card. --efa-interfaces N picks the count: 0 (default) means the maximum and 1 means the old single interface.

  • Layout: card 0 / device 0 is efa; card i / device 0 is efa-only, per https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/efa-acc-inst-types.html. A type whose card 0 has no EFA gets an ENA primary.
  • Elastic IP: with more than one interface, EC2 assigns no public IP, so Client.Launch allocates one after running and associates it to the primary ENI. It is tagged spawn:managed, spawn:instance-id and spawn:purpose=efa-public-ip. If association fails, the address is released and the instance terminated.
  • Release:
    • spawn terminate releases the address after TerminateInstances.
    • The ttl-reaper net-resources sweep releases orphans (unassociated, instance gone, older than 15 min); it follows REAPER_NET_RESOURCES, which defaults to report.
    • spawn cleanup releases unassociated spawn-allocated addresses.
  • Subnet: RunInstances needs a subnet on every interface once there are several. spawn uses the --az's subnet when --subnet-id is empty.
  • Dry run: --dry-run shows the layout and the Elastic IP plan.

Real-AWS check (2026-10-19, us-east-1a, c8gn.48xlarge spot, scttfrdmn/adit G2 #48):

  • The launch came up with interfaces 0/0 efa (Elastic IP associated) and 1/0 efa-only.
  • /sys/class/infiniband shows rdmap83s0 and rdmap166s0, and fi_info -p efa lists both domains. S3 is reachable over the Elastic IP.
  • spawn terminate printed "Released Elastic IP …". Afterwards describe-addresses by spawn:instance-id is empty and the instance is terminated.
  • The first attempt, without a subnet, hit InvalidParameterValue: Each network interface requires either a subnet…, which is fixed in the second commit.

Tests:

  • go build, go vet (darwin, linux and windows) and go test ./... pass, including the root meta-tests, nested modules and tidy.
  • New tests cover:
    • layouts for 1, 2, 16 and 32 cards;
    • --efa-interfaces bounds;
    • the Elastic IP lifecycle against fake EC2 (allocate, tag, associate, release on failure, terminate ordering);
    • the reaper orphan sweep and cleanup partitioning;
    • dry-run output;
    • the subnet requirement.

Not done / for the maintainer (original list; see the takeover notes below for what's now settled):


Takeover changes (field notes from adit G2)

The branch is rebased onto main at v0.137.0. All the original entries are under ## [Unreleased], make changelog-fix is clean, and the released-sections gate passes.

Field note 1: a released or reclaimed instance left its Elastic IP billing

Every way an instance ends now releases the address.

spored:

  • EC2Provider.Terminate releases the address after its TerminateInstances. That covers TTL, idle, cost-limit and on-complete.
  • A Spot interruption notice with action terminate releases it once, 20s before the interruption time (stop and hibernate keep it).
  • spored makes one ReleaseAddress call per address and never calls DisassociateAddress. The address is the instance's only egress, so once it is disassociated the instance can no longer send the release.
    • In a default VPC, ReleaseAddress also disassociates.
    • In a nondefault VPC, EC2 returns InvalidIPAddress.InUse. spored logs it and leaves the address to the reaper.
  • For the same reason the release always runs after the terminate, never before. A failed terminate releases nothing.
  • The shared logic is in a new pkg/elasticip package, which spored and the reaper both import.

Launch:

  • The address also gets the tag spawn:instance-arn=arn:<partition>:ec2:<region>:<owner>:instance/<id>.
  • The owner comes from the RunInstances ownerId, so no extra call is needed.

Instance role (both spored policies, the dynamic baseline and the static shared/DCV one). It gains these two statements:

{"Sid":"DescribeElasticIPs","Effect":"Allow","Action":"ec2:DescribeAddresses","Resource":"*"}
{"Sid":"ReleaseOnlyOwnElasticIP","Effect":"Allow","Action":"ec2:ReleaseAddress","Resource":"*",
 "Condition":{"StringEquals":{"ec2:ResourceTag/spawn:managed":"true",
                              "ec2:ResourceTag/spawn:instance-arn":"${ec2:SourceInstanceARN}"}}}

Reaper:

  • terminate() releases the address of an instance it has just terminated. It uses ReleaseAddress only, so the reaper role needs no DisassociateAddress. In a nondefault VPC the address is released by the sweep on a later cycle.
  • This is skipped when REAPER_NET_RESOURCES=off.

Orphan sweep default (decision):

  • The sweep releases orphaned launch Elastic IPs in report, the default, as well as in reap. Only off and REAPER_DRY_RUN hold it back. The security-group and placement-group sweep stays staged (gated).
  • Why this is safe:
    • The address is selected by three tags, spawn:managed=true, spawn:purpose=efa-public-ip (a new requirement) and spawn:instance-id. Only spawn writes them, and the instance is denied from writing them.
    • It must be unassociated.
    • Its instance must be absent from a DescribeInstances that just succeeded.
    • It must be older than the 15-minute grace.
    • Nothing references an unassociated address, and its age is the allocation stamp. That makes it unlike the SG/PG case, where staging was needed because membership and age were inferred.
  • Cost of a mistake: the IP number is lost.
  • Cost of report mode: these addresses bill until someone notices. Two leaked in seven minutes in G2.

Other: RELEASED is now an ActionSentinel, so spawn reaper teardown --if-idle-for counts it as activity. The existing sentinel-discovery gate caught this.

Field note 2: the Elastic IP quota

  • ensureAMIAndPreflight checks the quota for every multi-interface launch and its --dry-run. It counts the region's addresses with DescribeAddresses and reads Service Quotas ec2/L-0263D0A3 ("EC2-VPC Elastic IPs").
    • I verified the code against AWS's re:Post/CLI examples and the Redshift SLR policy.
    • If the account has no applied value, it falls back to GetAWSDefaultServiceQuota.
  • It needs one address per --count instance. When the launch would exceed the quota it fails before anything is created, with "N of M Elastic IPs in use in , and this launch needs K more" and a note that --efa-interfaces 1 needs no Elastic IP.
  • If the quota can't be read, it warns and the launch continues. The terminate-on-AllocateAddress-failure is still the backstop.

Permissions (in the CHANGELOG)

Gates

Each gate was watched failing against a revert that compiles. I ran 21 reverts and the gates caught all 21:

  • IAM:
    • the ARN condition dropped;
    • an extra unconditioned ReleaseAddress statement;
    • the ARN tag removed from the deny list;
    • the DCV policy missing the statements.
  • The launch ARN tag set to "".
  • spored:
    • the release removed from Terminate;
    • the release moved before the terminate;
    • an address of another instance released;
    • the Spot handler not scheduling the release;
    • no lead time;
    • a release on stop;
    • no fire-once.
  • Reaper:
    • the sweep staged like SG/PG;
    • the purpose not required;
    • no release on terminate;
    • a release on terminate even when off.
  • Quota:
    • the check not wired in;
    • --count ignored;
    • the headroom never refusing;
    • no default fallback;
    • an unreadable quota refusing the launch.

The IAM test evaluates each whole spored policy with a small evaluator (explicit deny wins, and an unmodelled operator fails the test):

  • The instance can release its own address.
  • It is denied another instance's address, a user's address, a spawn address without the ARN tag, an ARN-tagged address that isn't spawn:managed, and any request without a SourceInstanceARN.
  • It is denied forging or deleting the ARN or instance-id tag on another instance's address.

Checks

Check Result
make check Every step passes except check-build-tags, which fails identically on unmodified main because of the /private/tmp paths
make lint 0 issues in all 10 modules
make check-docs Clean
semgrep --config=auto --error Clean. I added a bare // nosemgrep above one test-fixture write that came in with the original PR
make api-snapshot Regenerated; additions only

Unverified (no AWS calls in this takeover)

  • IAM storage: whether IAM stores the new ReleaseAddress condition. Check with PutRolePolicy on a throwaway role at release time.
  • Real-instance behaviour: whether the condition allows the instance's own address and refuses another's on a real instance.
  • Default-VPC release: that a ReleaseAddress sent from the instance through its own associated Elastic IP in a default VPC takes effect, even if the response is lost.
  • Address/role coverage: addresses allocated before this change have no spawn:instance-arn, and instance roles keep their old policy until a launch refreshes it. In both cases the reaper is what releases the address.

@scttfrdmn

Copy link
Copy Markdown
Contributor Author

Field notes from the first real use, scttfrdmn/adit G2 (us-west-2, 2026-10-20):

  1. Spot reclaim leaves the Elastic IP behind. Two c8gn.48xlarge spot proxies were reclaimed (Server.SpotInstanceTermination) about 7 min after launch. Their Elastic IPs stayed allocated, unassociated and tagged with the dead instance id; I released them by hand. With the ttl-reaper in report mode by default, those addresses would bill until someone notices. Worth either defaulting the address sweep to reap or having spored's spot-interruption handler release its own address.
  2. The account Elastic IP limit (10 per region) caps multi-card fleets. With 8 multi-card boxes plus 2 addresses from other work, the 9th launch failed at AllocateAddress and spawn correctly terminated it. A clearer preflight error ("N Elastic IPs in use of 10") would help, as would a hint that --efa-interfaces 1 avoids the address. I used --efa-interfaces 1 for that box.

…i-interface launches (#661)

`spawn launch --efa` attached exactly one EFA interface at card 0 / device 0,
so multi-network-card instances ran on a fraction of their fabric
(c8gn.48xlarge 1 of 2, p5en.48xlarge 1 of 16, p5.48xlarge 1 of 32).

- --efa now attaches EfaInfo.MaximumEfaInterfaces interfaces (per-card
  InterfaceTypes from DescribeInstanceTypes): primary card 0 / device 0
  InterfaceType efa; every other EFA card device 0 efa-only, per AWS's
  "Maximize network bandwidth ... multiple network cards" guide. New
  --efa-interfaces N (0 = all, 1 = the old single interface, > max refused
  before anything is created). Resolved in ensureAMIAndPreflight, so the
  non-MPI path, --mpi and --dry-run all get it.
- EC2 auto-assigns no public IP with >1 interface, so Launch waits for running,
  allocates an Elastic IP tagged spawn:managed / spawn:instance-id /
  spawn:created / spawn:iam-user and associates it to the primary ENI. On
  failure the address is released and the instance terminated.
- Client.Terminate disassociates and releases that address after
  TerminateInstances (best-effort, warns). spawn cleanup releases an
  unassociated spawn-allocated address; user-owned EIPs are still never
  released (#262). The TTL reaper releases orphans (managed + instance tag,
  unassociated, instance gone, > 15 min) under the NetResources mode; reaper
  IAM gains ec2:DescribeAddresses and tag-railed ec2:ReleaseAddress.
- Dry run shows the interface layout and the Elastic IP plan.
- pkg/aws additions only (api/public-surface.txt regenerated);
  ValidateInstanceTypeForEFAInRegion and EFANetworkInterface keep their
  signatures, pipeline orchestrator unchanged.
RunInstances rejects a multi-interface request whose interfaces carry no
subnet (seen on a real c8gn.48xlarge launch). Resolve the --az's subnet when
--subnet-id is empty; without either, stop before RunInstances.
…lastic IP quota (#661)

Field notes from the first real use (adit G2):

1. A Spot reclaim, and every other ending but spawn terminate, left the
   launch Elastic IP allocated and billing. spored now releases its own
   address after its self-terminate and 20s before a Spot terminate
   interruption; the reaper releases the address of an instance it
   terminates; the orphan sweep releases in report mode too. The spored
   role gains DescribeAddresses and a ReleaseAddress conditioned on
   spawn:instance-arn == ${ec2:SourceInstanceARN}, and the instance-id/arn
   tags join the instance's tag-write deny list.
2. A multi-interface launch now checks the EC2-VPC Elastic IPs quota
   (L-0263D0A3) before creating anything.

Refs #661
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.

--efa attaches a single EFA interface (DeviceIndex 0); multi-network-card instances get a fraction of their fabric

1 participant