Skip to content

fix(launch): security group goes in the --subnet-id's VPC, not the default VPC - #1522

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/mpi-sg-subnet-vpc
Nov 3, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/mpi-sg-subnet-vpc

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Bug

spawn launch --mpi --subnet-id <subnet in a non-default VPC>, without --vpc, created spawn-mpi-<name> in the region's default VPC. RunInstances then refused every member:

lp4-0: terminal/InvalidParameter: Security group sg-0c15f7f1b7b14ec24 and subnet subnet-0367ce5c83c33dffa belong to different networks.

This was found live on 2026-11-03 in #1515's egress-proxy test: aws account, us-east-1, a no-NAT test VPC. sg-0c15f7f1b7b14ec24 is in vpc-cd49bfb0 (the default VPC), and the subnet is in vpc-0a0d97d9dbf34dec7.

The Windows SG and --efa-group paths had the same shape. All three called ResolveVPC(ctx, config.Region, config.VPCID), which only knows --vpc and the default VPC. Every earlier MPI test ran in the default VPC, which hid it.

Fix

Client.ResolveLaunchVPC resolves the VPC as:

  1. --vpc, if given;
  2. else the --subnet-id's VPC, from one DescribeSubnets call;
  3. else the default VPC.

A subnet whose VPC cannot be read fails the launch before anything is created. All three security-group creators now use it. FSx and SubnetInAZ call ResolveVPC only when there is no subnet, so they were already right and are unchanged.

Tests

  • TestLaunchSecurityGroupVPCFollowsTheSubnet: the real client against an httptest EC2 fake. It covers explicit --vpc, the subnet's VPC, the default VPC, and an unreadable subnet, which fails closed.
  • TestLaunchSecurityGroupCreatorsUseTheSubnetAwareVPC: a source gate. No non-test file in cmd may call ResolveVPC(ctx, config.Region, config.VPCID), and the 3 creators must use ResolveLaunchVPC.
  • Revert check: putting one MPI call site back to ResolveVPC makes the gate fail, naming launch_single.go.

make check and semgrep pass. Additive public API: ResolveLaunchVPC, snapshot regenerated. IAM: ec2:DescribeSubnets is already in every launch path.

Refs #1515

With --subnet-id in a non-default VPC and no --vpc, the MPI, Windows and
--efa-group security groups were created in the default VPC, and
RunInstances refused every member ('belong to different networks'). Found
live in #1515's egress-proxy test. ResolveLaunchVPC: --vpc, else the
subnet's VPC, else the default VPC; an unreadable subnet fails closed.
@codecov

codecov Bot commented Nov 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 9.09091% with 10 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/aws/securitygroup.go 0.00% 8 Missing ⚠️
cmd/launch_single.go 0.00% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 1e26232 into main Nov 3, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the fix/mpi-sg-subnet-vpc branch November 3, 2026 21:34
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.

1 participant