Repository navigation
fix(launch): honour --vpc instead of always using the default VPC - #700
Merged
Merged
Conversation
The flag was bound to a global nothing read — there was no VPCID field on LaunchConfig at all — and all five consumers called GetDefaultVPC unconditionally. So --vpc was accepted, exited 0, and launched in the DEFAULT VPC with its security group created there too. All five sites now go through one ResolveVPC: the MPI and Windows security groups, FSx's subnet choice when --subnet-id is absent, and GetSubnetForAZ. The storage paths matter as much as the SG ones — a filesystem in the default VPC while the instance is elsewhere presents as a broken mount, not a dropped flag. --vpc with --subnet-id is validated up front, since EC2's own mismatch error arrives only at RunInstances and names neither flag. A gate fails the build on any direct GetDefaultVPC call from the launch path: five sites each assuming the default is why this did nothing, and fixing some but not others is how #539 and #667 each ended up half-fixed. Fixes #673
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #673. The last of the three flags #688's wiring gate turned up, and the only one that needed implementing rather than deprecating.
The bug
--vpcwas bound to a package global that nothing read. There was noVPCIDfield onLaunchConfigat all, and all five consumers calledGetDefaultVPCunconditionally — sospawn launch --vpc vpc-0abc…was accepted, exited 0, and launched the instance in the default VPC, with its managed security group created there too.Silent, and it lands on network placement: wrong subnet, wrong route table, no route to an EFS or FSx mount target, and SG rules written into a VPC the instance is not in. An account whose research VPC is not the default could not target a VPC at all.
One resolver, not five fixes
All five launch-path sites now go through
ResolveVPC(ctx, region, explicit):spawn-mpi-*group lives in--subnet-id)GetSubnetForAZGetDefaultVPCdirectlyThe storage sites matter as much as the SG ones, and they are the ones easy to miss: a filesystem created in the default VPC while the instance is in another presents as a broken mount, not as a dropped flag. The reporter would spend the debugging time on NFS and security groups.
I made it a shared resolver rather than four separate edits deliberately. Five sites each independently assuming the default VPC is why this flag did nothing, and fixing some while leaving others is precisely how #539 and #667 each ended up fixed on one path and broken on another. The class gate fails the build on a direct
GetDefaultVPCcall from the launch path, so the sixth site can't reintroduce it.cmd/app.go,cmd/image.goandpkg/doctorstill callGetDefaultVPCand are excluded from the gate on purpose — they are not launches and have no--vpcto honour.--vpc+--subnet-idValidated up front. Passing both is the natural way to use
--vpc, and EC2's own error for a mismatch arrives only atRunInstancesand names neither flag:Advisory on a
DescribeSubnetsfailure rather than fail-closed — EC2 still rejects a genuine mismatch, so this is a better error, not a new gate that a describe hiccup could turn into a failed launch.Verification
Three gates, each confirmed to fail when its half is reverted:
VPCID = "", want "vpc-0abc…"GetDefaultVPC→ names the file and lineI checked each by reverting and watching it fail, because four tests I wrote earlier today passed vacuously.
Standard gates:
gofmt -lempty,go vet ./...,go test -short ./...(including the fullpkg/awssuite),make check-docsregenerated, changelog gate,semgrep→ 0 findings.Not hardware-verified. The flag plumbing is pure and the gates cover the call sites, but "the security group is created in the right VPC and the FSx mount routes" is an AWS-side claim.
make smoke-neededflagspkg/aws/securitygroup.goandcmd/launch_single.go, so this is covered by the smoke before the next tag — a launch with--vpcpointing at a non-default VPC would settle it.Housekeeping
--vpcis removed fromknownUnwiredFlags; only--cartesianand--use-reservationremain there, both now deliberately deprecated rather than pending. InsweepFlagCoverageit stays a known gap, re-pointed at #697 — implemented for single launches, still dropped on sweeps.