Skip to content

feat(launch): --bootstrap-egress proxy, find-or-create of the per-VPC egress proxy (#1515 phase 3) - #1518

Merged
scttfrdmn merged 8 commits into
mainfrom
feat/1515-egress-proxy-find-or-create
Nov 3, 2026
Merged

scttfrdmn merged 8 commits into
mainfrom
feat/1515-egress-proxy-find-or-create

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Refs #1515 (phase 3 of the build plan: find-or-create plus the opt-in).

What this does

  • Opt-in. --bootstrap-egress none|proxy (default none), --egress-proxy-idle (default 72h, capped at the proxy's 6-day life). The precedence is flag > SPAWN_BOOTSTRAP_EGRESS > bootstrap_egress in ~/.spawn/config.yaml (spawn defaults set bootstrap-egress proxy) > default.
    • libs/sporeconfig has a fixed [spore] table (profile/region/account/output). This key is spawn's, so it sits with spawn's other launch defaults, using the same precedence order.
    • An explicit --bootstrap-egress proxy without --no-public-ip is refused. A default from the environment or the config file is ignored on a public launch.
  • Preflight (pkg/aws/private_network.go):
    • Opted in: an internet need whose host passes egressproxy.Allowed is met "through the spawn egress proxy in vpc-…" and recorded in PrivateCheck.ViaEgressProxy. This is derived from the allowlist, not assumed.
    • Opted in, with no subnet routed to an igw-: refused, saying so.
    • Not opted in: a refusal the proxy could fix names --bootstrap-egress proxy.
    • The VPC-endpoint needs are unchanged. With a NAT route nothing changes and no proxy is made.
    • Windows never counts on the proxy.
    • Client.Launch refuses a check that counts on the proxy when the config has no EgressProxyAddr (SDK callers).
  • Max life. egressproxy.MaxLife = ttl.DefaultReaperMaxAge - 24h (6 days). The deadline is launch + max life, written through pkg/ttl.Tags. spored egress-proxy --idle now defaults to 72h, and spored refuses (does not serve, retires at the next tick) an idle longer than launch→deadline.
  • Find-or-create, per VPC (new pkg/egressproxy/deploy, behind an EC2/Prober seam). It is called in launchWithProgress right after the security-group step, so every single, job-array and --mpi member is cloned from a config that already has the proxy.
  • Security groups: spawn-egress-clients-<vpc> and spawn-egress-proxy-<vpc>, plus the deleter deploy.DeleteGroups, which phase 5 wires.
  • Refused before any AWS call: parameter sweeps, foreground and --detach, which covers the sweep orchestrator; Windows. Schedules and pools take no --no-public-ip, so they have nothing to refuse.

Design choices

  • Authenticity: no signature exists to verify. Implement spore.host authenticity key: signed spore tag that all spore tools verify before touching an instance #76 is open: no per-instance signed tag exists, and the only spore.host signatures (on spored and on the bootstrap body) come from a KMS key the CLI doesn't hold. Tags alone are forgeable by any spore's own role (Implement spore.host authenticity key: signed spore tag that all spore tools verify before touching an instance #76), so a compromised member could tag itself the proxy. deploy.Evaluate instead requires things an instance can't give itself:

    • its security groups are exactly the VPC's proxy group (the spored role has no ModifyInstanceAttribute/ModifyNetworkInterfaceAttribute);
    • it runs with spored-instance-profile;
    • its spawn:ttl-deadline is no later than its EC2 launch time + max life (ttl.LaunchAnchor), so a forged far-future deadline or launch-time is refused.

    It also requires spawn:version == buildinfo version, pending/running state, more than 12h left, and a passing readiness probe. A principal that can RunInstances with that group and PassRole the spored role can still forge one; that's the account trust boundary. Implement spore.host authenticity key: signed spore tag that all spore tools verify before touching an instance #76's signature should replace or extend this check when it exists.

  • Readiness: the existing spored check plus one probe. It waits for the spawn:last-heartbeat tag (the same evidence verifySporedReadyOn uses). Then an SSM RunShellScript on the proxy runs curl --proxy http://<private-ip>:3128 https://awscli.amazonaws.com/. That proves spored is up, the listener is bound, the allowlist passes, and the IGW path works. The wait is bounded at 6 min. If SSM is denied, that counts as a failure, not a pass. A proxy this call created that fails is terminated, with a context that a ^C can't cancel. A found proxy that fails isn't touched, and a new one is created.

  • Systemd unit: a drop-in, not a second unit. /etc/systemd/system/spored.service.d/egress-proxy.conf overrides ExecStart to spored egress-proxy --port 3128 --idle <idle>, followed by daemon-reload and restart. It's appended as custom user data after the standard bootstrap, so the published, signed body is unchanged and exactly one spored runs. spored listens on the private IP (the phase 2 default).

  • The instance: t4g.nano, AL2023 arm64 from /aws/service/ami-amazon-linux-latest/al2023-ami-kernel-default-arm64, in a public subnet (the launch's AZ preferred), AssociatePublicIpAddress=true, no EIP, IMDSv2 required (hop 1), spored-instance-profile (always, whatever the members use), InstanceInitiatedShutdownBehavior=terminate. Tags: the standard LaunchTagger set plus the proxy's ttl/deadline, Name=spawn-egress-proxy-<vpc> and spawn:egress-proxy=<vpc>, on the instance and its volume.

  • SG rules, exact, reconciled on every launch:

    • Clients: no rules at all; EC2's default allow-all egress is revoked, so attaching it never widens a member's egress.
    • Proxy: ingress tcp 3128 from the clients SG only; egress tcp 443 and tcp 80 to 0.0.0.0/0. DNS, IMDS and time sync are link-local and need no rule.
    • A member that named no SG gets the VPC default SG plus the clients SG, so it keeps what EC2 would have given it.
    • Each group carries LifecycleTags (spawn:managed, spawn:created, spawn:purpose) and spawn:egress-proxy=<vpc>, so the reaper's managed-network sweep is already a deleter. DeleteGroups refuses while any non-terminated instance uses either group, and deletes the proxy group first.
    • A same-named group without our tags is refused, not adopted.
    • On a readiness failure the SGs are kept (free, reused, reaped).
  • Superseded and racing proxies. A superseded proxy is never terminated, because another launch may be using it; it ends at its idle period or deadline. Two racing launches can each create one, and the spare idle-expires. This is documented in FindOrCreate.

New IAM actions (spawn launch)

  • ec2:RevokeSecurityGroupEgress: removes the default egress from both groups on creation.
  • ec2:RevokeSecurityGroupIngress: only when a proxy group's ingress drifted.

docs/reference/cli-iam-actions.md is regenerated. ec2:DeleteSecurityGroup is not reachable from launch. Provisioned policies: the nested-spawn policy (pkg/aws/nested_spawn.go, NestedSpawnManageManaged) does not grant either revoke. A nested spore using --bootstrap-egress proxy would be denied at the revoke, so that policy needs both actions gated on ec2:ResourceTag/spawn:managed. That change is left out of this PR because it has to be verified with a real PutRolePolicy. Workstation users run on their own credentials, as documented.

Public API (additive, api/public-surface.txt updated)

LaunchConfig.BootstrapEgress, LaunchConfig.EgressProxyAddr, PrivateNetwork.PublicSubnets, PrivateCheck.ViaEgressProxy, PublicSubnet, BootstrapEgress{None,Proxy,Flag}, InternetNeedHost, ErrNoEgressProxy.

Revert evidence

Each key decision was reverted with a change that compiles, and the named tests failed (24/24):

reverted decision failing tests
version-mismatch reuse TestEvaluate, TestFindOrCreateReplacesAnOldVersionWithoutTerminatingIt
provenance: exact SG set / profile TestEvaluate
forged far-future deadline TestEvaluate
12h reuse margin TestEvaluate
stopped/stopping proxy TestEvaluate
readiness-failure teardown TestFindOrCreateTerminatesAProxyThatIsNotReady
revoke extra egress / ingress source = clients SG TestEnsureGroupsRulesAreExact, TestEnsureGroupsRemovesDrift
public IP / IMDSv2 / deadline = launch+max life TestRunInput
idle cap (deploy / CLI) TestFindOrCreateRefusesAnIdleAboveMaxLife / TestBootstrapEgressRefusalsMakeNoAWSCall
allowlist derivation / public subnet required / names the flag TestCheckPrivateNetworkProxy{OnlyForAllowlistedHosts,IsLinuxOnly,NeedsAPublicSubnet}, TestCheckPrivateNetworkNotOptedInNamesTheFlag, TestPreflightNoPublicIPRefusalNamesTheFlag
Launch refuses without a proxy addr TestRequireEgressProxy
wired into launchWithProgress TestLaunchFindsOrCreatesTheProxyBeforeAnyInstance (single + job array)
members get the clients SG TestEnsureEgressProxy
env-opted sweep refusal / sweep guard TestBootstrapEgressRefusalsMakeNoAWSCall, TestSweepMemberGuardRefusesTheProxy, Test{Foreground,Detached}SweepCarriesOrRefusesEveryLaunchSetting
spored idle refusal / 72h default TestEgressProxyRefusesAnIdleLongerThanItsLife / TestEgressProxyCommandContract

Checks

make check passes. The hermetic go test ./... passes (AWS env stripped, /dev/null config). semgrep scan --config=auto --error . finds nothing. make api-snapshot, make cli-iam-actions and make gen-docs were all regenerated. CHANGELOG has entries under [Unreleased] (Added, and Changed for the spored default).

Not run against AWS

Nothing in this PR has touched AWS. See the live-test notes in the review thread.

@scttfrdmn

Copy link
Copy Markdown
Contributor Author

Live-test notes (nothing here has been run against AWS)

Prerequisite, or the proxy can never become ready. No published spored has egress-proxy: v0.156.0 predates #1517, and spawn/current/ is written only by releases. A dev-built CLI's proxy installs the latest published spored, and spored egress-proxy then fails to start, so readiness times out and the proxy is torn down. Before the success path can be tested, a linux/arm64 spored built from this branch or from main has to be where the proxy's bootstrap fetches it, signed (signature verification is on). The failure run is still worth doing on its own: it exercises the teardown path (step 6).

In a VPC with no NAT, with the s3 gateway, ec2, ssm, ssmmessages and ec2messages endpoints, and with one subnet routed to an IGW:

  1. Refused without the opt-in, nothing created.
    • Run spawn launch --no-public-ip --subnet-id <private> --mpi --efa --count 2 --job-array-name t --ttl 1h ....
    • The refusal's EFA line should end with "Pass --bootstrap-egress proxy …".
    • Check that no key pair, SG or instance was created.
  2. Opted in: the proxy instance. Run the same launch with --bootstrap-egress proxy.
    • Stderr should show ✓ --no-public-ip: internet: … through the spawn egress proxy in vpc-…, then ✓ egress proxy: launched i-… at 10.x.x.x:3128.
    • describe-instances on the proxy should show:
      • t4g.nano, in the public subnet (the launch's AZ if it has one), with a public IP and no EIP;
      • HttpTokens=required, hop limit 1, spored-instance-profile;
      • spawn-egress-proxy-<vpc> as its only SG;
      • InstanceInitiatedShutdownBehavior=terminate;
      • tags spawn:egress-proxy=<vpc>, spawn:ttl=144h0m0s, spawn:ttl-deadline = spawn:launch-time + 6d, and spawn:version = the CLI's version.
  3. Security groups.
    • spawn-egress-clients-<vpc> has zero ingress and zero egress rules.
    • spawn-egress-proxy-<vpc> has ingress = only tcp 3128 from the clients SG, and egress = only tcp 443 and tcp 80 to 0.0.0.0/0.
    • Both carry spawn:managed=true, spawn:created and spawn:purpose.
    • CloudTrail should show RevokeSecurityGroupEgress on both. This is the new IAM action; confirm your credentials allowed it.
  4. On the proxy (spawn connect):
    • systemctl cat spored shows the egress-proxy.conf drop-in.
    • journalctl -u spored (or /var/log/spored.log) shows egress-proxy: idle period 72h0m0s and listening on <private-ip>:3128.
    • CloudTrail shows the probe's SSM SendCommand, ending Success.
    • Note how long readiness took. The bound is 6 min.
  5. Members.
    • Each member's SGs are its own (the MPI SG) plus the clients SG.
    • No member RunInstances happened before the proxy was ready.
    • Members do not use the proxy yet (phase 4), so the EFA download still fails on them. That is expected for this phase.
  6. Teardown. If the proxy failed readiness, as it will without the prerequisite:
    • the launch fails with the egress proxy did not become ready … ; terminated it;
    • the proxy is shutting-down or terminated;
    • no member was launched;
    • the SGs remain. That is by design: they're reused and reaped.
  7. Reuse.
    • A second opted-in launch in the same VPC prints reusing i-… and makes no new RunInstances for a proxy.
    • A launch from a CLI with a different version prints not reused: it was launched by spawn X, not Y, launches a new proxy, and leaves the old one running.
  8. Refusals with no AWS call:
    • --egress-proxy-idle 145h;
    • --bootstrap-egress proxy without --no-public-ip;
    • a --params sweep with --bootstrap-egress proxy (both --detach and --no-detach);
    • SPAWN_BOOTSTRAP_EGRESS=proxy with a --no-public-ip --detach sweep.
  9. Leak check afterwards.
    • Terminate the members and the proxy (it would otherwise idle 72h or live 6d), and verify nothing is left running.
    • deploy.DeleteGroups isn't wired to a command yet (phase 5). Delete the two SGs by hand, proxy SG first, or leave them for the reaper's managed-network sweep.

@codecov

codecov Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

@scttfrdmn

Copy link
Copy Markdown
Contributor Author

Live test (aws account, us-east-1, CLI built from this branch, spored v0.157.0 from spawn/current)

Setup: a no-NAT test VPC with one public subnet (route to an IGW) and one private subnet (no default route). Gateway endpoints for s3 and dynamodb; interface endpoints for ec2, ssm, ssmmessages and ec2messages.

# Check Result
1 No opt-in: --mpi --efa --no-public-ip is refused before anything is created, and the message names --bootstrap-egress proxy ✅
2 Proxy shape ✅ t4g.micro in the public subnet, public IP from EC2, 0 EIPs, IMDSv2 required, spored-instance-profile, only SG spawn-egress-proxy-<vpc>, shutdown behaviour = terminate. spawn:ttl=144h0m0s and deadline = launch + 144h exactly. spawn:version = this CLI's
3 SG rules ✅ The clients SG has 0 ingress and 0 egress rules. The proxy SG allows ingress only on tcp 3128 from the clients SG, and egress only on tcp 443 and 80 to 0.0.0.0/0
4 Drop-in, mode, readiness ✅ The drop-in is present; egress-proxy: idle period 72h0m0s, listening on <privip>:3128. The probe's CONNECT awscli.amazonaws.com:443 was allowed (252 ms). Ready in 128.6 s
5 Members ✅ They were launched only after the proxy was ready, each with its own MPI SG plus spawn-egress-clients-<vpc> and no public IP (CloudTrail RunInstances). They then failed at enrolment as expected, since phase 4 (proxy env) doesn't exist yet. The cohort drain terminated both
6 Readiness-failure teardown ✅ (observed on the first, t4g.nano run) …did not become ready within 6m0s…; terminated it. No member was launched and the SGs were kept
7 Reuse ✅ The second launch printed reusing i-02dd50c75d3651804 in 4.4 s. Not run live: a different-version CLI creating a new proxy. The unit tests cover it
8 Refusals with no AWS write ✅ --egress-proxy-idle 145h, the flag without --no-public-ip, and an explicit --bootstrap-egress on a sweep. Couldn't test: SPAWN_BOOTSTRAP_EGRESS on a param-file sweep, which stopped at the wizard guard first

Bugs the live run found

  1. The proxy was OOM-killed on t4g.nano. The bootstrap's dnf install acpid drove the 0.5 GiB instance out of memory. The OOM killer took spored, then systemd-resolved, so the first proxy never wrote a heartbeat. Fixed here (178353a1): the proxy is a t4g.micro, and the drop-in step turns off dnf-makecache.timer. Cost becomes about $6.1/month for the instance plus $3.65/month for the public IPv4, about $10/month per VPC. The underlying bootstrap bug (it retries with yum, which is dnf on AL2023, after dnf was OOM-killed) is filed as bootstrap: acpid install retries with yum after dnf is OOM-killed (AL2023 yum = dnf), which later kills spored and systemd-resolved #1521.
  2. The MPI SG went into the default VPC when --subnet-id was in a non-default VPC without --vpc, so RunInstances refused the members ("belong to different networks"). This is a pre-existing bug on main, fixed in fix(launch): security group goes in the --subnet-id's VPC, not the default VPC #1522. This run used --vpc as a workaround.
  3. --help showed the flag as --bootstrap-egress spawn defaults set bootstrap-egress proxy. Cobra takes text in backticks as the flag's placeholder. Fixed here (3389c13c). The same bug on --name and --fsx-lifecycle is launch --help: --name and --fsx-lifecycle show a backticked command as their placeholder #1520.

Also fixed here: the rebase onto v0.157.0 had landed this PR's CHANGELOG entries under the released [0.157.0] heading (751f820d).

Teardown

  • The proxy, the debug instance and all members are terminated.
  • The endpoints, the 5 test SGs, the subnets, route tables, IGW and VPC are deleted.
  • The 3 spawn-mpi-lp* SGs that bug 2 left in the default VPC are deleted.
  • Leak diff: compared with a baseline taken before the run, there are no new instances apart from an owner probe that isn't mine, and no new SGs, Spot requests or EIPs.

…tion

The rebase onto the v0.157.0 promotion landed them under [0.157.0]; the
released section is restored byte-identical to the tag.
… command

Cobra takes backtick-quoted text in a flag's usage as its placeholder name,
so the help read '--bootstrap-egress spawn defaults set bootstrap-egress proxy'.
Live (#1515): on a t4g.nano the bootstrap's dnf install of acpid drove the
proxy out of memory; the OOM killer took spored, then systemd-resolved (the
proxy's DNS), so the first launch's proxy never wrote a heartbeat within 6m.
The proxy never installs packages, so AL2023's dnf-makecache timer is off.
@scttfrdmn
scttfrdmn force-pushed the feat/1515-egress-proxy-find-or-create branch from 178353a to 3bd9130 Compare November 3, 2026 21:39
…(Windows)

TestLaunchFindsOrCreatesTheProxyBeforeAnyInstance writes audit records, and
spawn keeps ~/.spawn/audit.log open for the process; on Windows t.TempDir
then could not remove HOME. withLogDir redirects and closes it.
@scttfrdmn
scttfrdmn merged commit 167f2f9 into main Nov 3, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the feat/1515-egress-proxy-find-or-create branch November 3, 2026 22:28
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