Skip to content

feat(no-public-ip): count a working NAT instance as a way out (#1515) - #1516

Merged
scttfrdmn merged 6 commits into
mainfrom
feat/1515-nat-instance-preflight
Nov 3, 2026
Merged

scttfrdmn merged 6 commits into
mainfrom
feat/1515-nat-instance-preflight

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Refs #1515 (first sub-task: preflight). The issue has more sub-tasks, so this PR does not close it.

What

--no-public-ip's subnet preflight now counts a 0.0.0.0/0 route to a working NAT instance as a way out. Before this change it counted only a NAT gateway.

When the route names an instance (an ENI route attached to an instance carries InstanceId too), spawn reads that instance with ec2:DescribeInstances only. It counts the instance as a way out only if all of these hold:

  • the instance is running;
  • the routed interface has its source/destination check off. That is the route's ENI, or the primary ENI when the route names only the instance, and it is the interface that forwards;
  • at least one interface has a public IPv4 address and sits in a subnet whose route table sends 0.0.0.0/0 to an igw-. The route table is resolved with subnetRouteTable from the VPC tables already read. This interface can differ from the routed one, so a two-interface NAT passes: inside ENI in the private subnet, public IP on an outside ENI in a public subnet.

If any check fails, the launch is still refused, and each Missing entry names every failed check. For example: 0.0.0.0/0 goes to instance i-x, which is not a working NAT instance: its source/destination check is on (network interface eni-y), .... Other cases:

  • Public IP in the wrong subnet: if interfaces with a public IP exist but none is in an IGW-routed subnet, the message names each one and its subnet's route.
  • ENI with no instance: an ENI route with no instance is refused for that reason.
  • Blackholed route (a stopped NAT): still no route.
  • Unchanged: NAT gateway, internet gateway and transit gateway routes behave as before.
  • Read failure: if DescribeInstances fails, that is reported as a problem rather than an error, so the launch is refused saying why and --allow-missing-endpoints still lists the rest.

On success, Met says everything, through NAT instance i-x on route table rtb-y. A Warning says spawn cannot see the instance's IP forwarding or iptables config, so it trusts the route.

The model: PrivateNetwork gains NATInstanceID and NATInstanceProblem, an additive public-API change with the snapshot regenerated. CheckPrivateNetwork stays pure.

IAM

  • privateNetworkAPI gains only DescribeInstances. There is no DescribeNetworkInterfaces call and no other new action.
  • make cli-iam-actions adds ec2:DescribeInstances to exactly one command row: spawn schedule create. That command checks member subnets at creation, through detachedSubnetCheck. The doc's "Outside any command" section already requires ec2:DescribeInstances for every spawn invocation (startup and the root pre-run), so no user who can run spawn lacks it. No IAM work for users.
  • No Lambda calls PreflightNoPublicIP; only pkg/aws/client.go (Launch) and the cmd paths do. So no Lambda role changes.

Tests

TestNATInstanceIsAWayOut uses a typed fake privateNetworkAPI, with 19 cases:

  • Passing NAT instances: routed by instance ID, and by ENI+instance; through a secondary ENI that forwards; a two-interface NAT, routed by ENI and by instance ID.
  • Each failed check: source/dest check on (primary, and a secondary routed ENI); no public IP; a single-ENI NAT whose subnet has no IGW route; a single-ENI NAT in the subnet that routes back to it; a two-interface NAT whose public ENI's subnet has no IGW route; NAT stopping; all failures together.
  • Other route cases: a blackholed route (0 DescribeInstances calls); an ENI with no instance (0 calls); DescribeInstances denied; instance gone.
  • Unchanged behaviour: NAT gateway and IGW routes (0 calls).

Revert gate, on compiling reverts. Each failed the named cases, and restoring the code passed them:

  • disabling the NAT-instance pass in CheckPrivateNetwork failed the working-NAT cases;
  • ignoring the source/dest check failed the check-on cases;
  • checking egress on the routed ENI instead of the public-IP ENIs failed both two-interface pass cases.

Run locally: make check, go test ./... with AWS env stripped, and semgrep scan --config=auto --error ., all exit 0. No AWS access was used.

Docs

The --no-public-ip help text is updated and docs-gen/launch.md regenerated. docs/reference/cli-iam-actions.md and api/public-surface.txt are regenerated, and there is a CHANGELOG entry under [Unreleased] → Changed.

@codecov

codecov Bot commented Nov 3, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 84.84848% with 15 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/aws/private_network.go 84.53% 15 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 64bc8e5 into main Nov 3, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the feat/1515-nat-instance-preflight branch November 3, 2026 06:11
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