Repository navigation
feat(launch): --bootstrap-egress proxy, find-or-create of the per-VPC egress proxy (#1515 phase 3) - #1518
Conversation
Live-test notes (nothing here has been run against AWS)Prerequisite, or the proxy can never become ready. No published spored has In a VPC with no NAT, with the s3 gateway, ec2, ssm, ssmmessages and ec2messages endpoints, and with one subnet routed to an IGW:
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
d54751e to
979042e
Compare
…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.
Live test (aws account, us-east-1, CLI built from this branch, spored v0.157.0 from
|
| # | 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
- The proxy was OOM-killed on t4g.nano. The bootstrap's
dnf install acpiddrove 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 offdnf-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 withyum, 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. - The MPI SG went into the default VPC when
--subnet-idwas 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--vpcas a workaround. --helpshowed 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--nameand--fsx-lifecycleis 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.
…idle cap (#1515 phase 3)
…r-create wired before members launch (#1515)
…ess, readiness teardown, opt-in refusals (#1515)
…#1515); drop an unpaired progress Skip
…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.
178353a to
3bd9130
Compare
…(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.
Refs #1515 (phase 3 of the build plan: find-or-create plus the opt-in).
What this does
--bootstrap-egress none|proxy(defaultnone),--egress-proxy-idle(default72h, capped at the proxy's 6-day life). The precedence is flag >SPAWN_BOOTSTRAP_EGRESS>bootstrap_egressin~/.spawn/config.yaml(spawn defaults set bootstrap-egress proxy) > default.libs/sporeconfighas 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.--bootstrap-egress proxywithout--no-public-ipis refused. A default from the environment or the config file is ignored on a public launch.pkg/aws/private_network.go):egressproxy.Allowedis met "through the spawn egress proxy in vpc-…" and recorded inPrivateCheck.ViaEgressProxy. This is derived from the allowlist, not assumed.igw-: refused, saying so.--bootstrap-egress proxy.Client.Launchrefuses a check that counts on the proxy when the config has noEgressProxyAddr(SDK callers).egressproxy.MaxLife = ttl.DefaultReaperMaxAge - 24h(6 days). The deadline is launch + max life, written throughpkg/ttl.Tags.spored egress-proxy --idlenow defaults to72h, and spored refuses (does not serve, retires at the next tick) an idle longer than launch→deadline.pkg/egressproxy/deploy, behind anEC2/Proberseam). It is called inlaunchWithProgressright after the security-group step, so every single, job-array and--mpimember is cloned from a config that already has the proxy.spawn-egress-clients-<vpc>andspawn-egress-proxy-<vpc>, plus the deleterdeploy.DeleteGroups, which phase 5 wires.--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.Evaluateinstead requires things an instance can't give itself:ModifyInstanceAttribute/ModifyNetworkInterfaceAttribute);spored-instance-profile;spawn:ttl-deadlineis 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-heartbeattag (the same evidenceverifySporedReadyOnuses). Then an SSMRunShellScripton the proxy runscurl --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.confoverridesExecStarttospored egress-proxy --port 3128 --idle <idle>, followed bydaemon-reloadandrestart. 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 standardLaunchTaggerset plus the proxy's ttl/deadline,Name=spawn-egress-proxy-<vpc>andspawn:egress-proxy=<vpc>, on the instance and its volume.SG rules, exact, reconciled on every launch:
defaultSG plus the clients SG, so it keeps what EC2 would have given it.LifecycleTags(spawn:managed,spawn:created,spawn:purpose) andspawn:egress-proxy=<vpc>, so the reaper's managed-network sweep is already a deleter.DeleteGroupsrefuses while any non-terminated instance uses either group, and deletes the proxy group first.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.mdis regenerated.ec2:DeleteSecurityGroupis 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 proxywould be denied at the revoke, so that policy needs both actions gated onec2: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.txtupdated)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):
Checks
make checkpasses. The hermeticgo test ./...passes (AWS env stripped,/dev/nullconfig).semgrep scan --config=auto --error .finds nothing.make api-snapshot,make cli-iam-actionsandmake gen-docswere 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.