Skip to content

feat(egress-proxy): spawn egress-proxy status|delete|upgrade, reaper coverage, nested-spawn grants (#1515 phase 5) - #1525

Merged
scttfrdmn merged 5 commits into
mainfrom
feat/1515-egress-proxy-cli
Nov 4, 2026
Merged

scttfrdmn merged 5 commits into
mainfrom
feat/1515-egress-proxy-cli

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Refs #1515 (phase 5).

Adds spawn egress-proxy status | delete | upgrade, verifies and tests reaper coverage of the proxy, and closes the nested-spawn policy gap. The AWS work is in pkg/egressproxy/deploy and reuses phase 3's Evaluate, DeleteGroups, FindOrCreate and Terminate. cmd/egress_proxy.go holds only flags, prompts and output.

Commands

The region is the root --region, else the configured region. No command defines its own --region, because the root flag already applies to every subcommand.

  • status (--all-regions, --vpc, -o json). For each instance tagged spawn:egress-proxy (any state but terminated) it shows:

    • VPC, state, private IP:3128 and public IP;
    • spawn:version, and whether it matches this CLI;
    • launch time, deadline and time left;
    • whether find-or-create would reuse it, using deploy.Evaluate's verdict and reason;
    • whether spawn can tell it launched it (deploy.Verify);
    • idle activity ("idle for X, expires in Y").

    For each VPC it also shows both groups and how many ENIs carry each. It is read-only.

  • delete (--vpc or --all, --yes, --dry-run).

    • It terminates only instances that pass the new deploy.Verify: Evaluate's structural half, with the version, remaining-life and state checks left out.
    • It refuses any other tagged instance, names it with the reason, and exits 1.
    • It waits up to 5 minutes for termination, then runs deploy.DeleteGroups (proxy group first), retrying DependencyViolation for up to 2 minutes.
    • A clients group that members still use is kept. Its users are named, and the output says the reaper's network sweep will delete it.
    • --dry-run prints the plan and makes no writes. A declined prompt exits 75.
  • upgrade (--vpc, --yes, --keep-old).

    • If the current proxy is at this version and reusable, it prints "already current" and changes nothing, with no prompt.
    • Otherwise it calls FindOrCreate, which launches a new proxy and waits for it to be ready. The new proxy goes in the old proxy's AZ, and its public subnets come from DescribePrivateNetwork on the old proxy's subnet. It keeps the old proxy's published idle period, or 72h if there is none.
    • Then it terminates the old proxies that pass Verify, unless --keep-old.
    • If the new proxy never becomes ready, the old one is not touched.
    • It warns that a member mid-bootstrap through the old proxy could fail its fetch.
    • A VPC with no proxy gets none.

Departures from the brief

  • --json became -o json. TestFlagConventions (spawn#40) fails any undeprecated local --json, so status uses the root -o json. The snake_case key set is pinned by TestEgressProxyStatusJSON.
  • ENIs are counted from DescribeInstances. The count comes from DescribeInstances NetworkInterfaces[].Groups, the same data DeleteGroups and the reaper use, rather than DescribeNetworkInterfaces, so no new IAM action is needed. An ENI that belongs to no instance is not counted.

spored change

spored egress-proxy now writes two tags:

  • spawn:egress-proxy-last-activity (RFC3339);
  • spawn:egress-proxy-idle (the idle period it enforces).

Details:

  • They go through spored's existing tag path. A new (*agent.Agent).PutInstanceTags wraps a.tagger.putTags, the path used by ready-* and dns-status.
  • egressproxy.ActivityPublisher throttles the writes: at most once per 10 minutes, and only when the value changed. A failed write is retried at the same pace, not every tick. The first write happens on the first persist tick.
  • They are a report only, and nothing decides anything on them.
  • Both keys were added to postLaunchInstanceTags, applied only to the proxy's launch config, because TestEveryPostLaunchTagIsListed requires it.
  • A proxy without the tags shows as unknown (proxy predates spawn v0.158.0).

Reaper: verified, no reaper code change

  • Instances. The proxy carries spawn:managed=true and spawn:ttl-deadline = launch + 144h. evaluate reaps it past that deadline (the ttl-deadline branch, after leaveToSpored's grace). That deadline is inside the 168h ceiling.
  • Groups. Both carry spawn:managed and spawn:created. reapSecurityGroups deletes each once no instance carries it and it is older than the 7-day grace.
    • The order is not guaranteed. If the clients group comes first, EC2 refuses it with DependencyViolation, because the proxy group's ingress rule references it, and the sweep counts it as skipped.
    • So the proxy group goes on one cycle and the clients group on the same cycle or the next.
  • Config caveat, not code. The group sweep deletes only with REAPER_NET_RESOURCES=reap, and the template default is report. Please check the live value. If it is report, egress-proxy delete is the only thing that actually deletes the groups.
  • Test fixture. The reaper module can't import deploy: trying it pulled roughly 20 extra modules, including hcsshim, into the Lambda's go.mod. So TestReaperFixtureIsCurrent (in deploy) runs the real producers (pkg/aws.BuildLaunchTags, deploy.Create's RunInstances input, and EnsureGroups' CreateSecurityGroup calls) against the fake. It writes lambda/ttl-reaper/testdata/egress_proxy_tags.json and fails when that file is stale. lambda/ttl-reaper/egress_proxy_test.go reads the file and covers both cases.
  • Unrelated bug found: ttl-reaper: logs "unparseable ttl-deadline" for every instance with a valid future deadline #1524. evaluate logs "unparseable ttl-deadline" for every instance whose deadline is valid and in the future. This is a misplaced log.Printf, log noise only. It is filed and not fixed here.

Nested-spawn policy (pkg/aws/nested_spawn.go)

The NestedSpawnManageManaged statement already used ec2:ResourceTag/spawn:managed, which is EC2's key and so correct for these EC2 actions.

  • Added ec2:RevokeSecurityGroupIngress, ec2:RevokeSecurityGroupEgress and ec2:DeleteSecurityGroup, all under that same condition.
  • Why DeleteSecurityGroup is granted rather than refused: delete needs it, and the nested role can already terminate any spawn-managed instance. EC2 refuses to delete a group that is in use.

The final statement:

{
  "Sid": "NestedSpawnManageManaged",
  "Effect": "Allow",
  "Action": [
    "ec2:StartInstances",
    "ec2:StopInstances",
    "ec2:TerminateInstances",
    "ec2:CancelSpotInstanceRequests",
    "ec2:GetPasswordData",
    "ec2:AuthorizeSecurityGroupIngress",
    "ec2:AuthorizeSecurityGroupEgress",
    "ec2:RevokeSecurityGroupIngress",
    "ec2:RevokeSecurityGroupEgress",
    "ec2:DeleteSecurityGroup",
    "ec2:DeletePlacementGroup"
  ],
  "Resource": "*",
  "Condition": { "StringEquals": { "ec2:ResourceTag/spawn:managed": "true" } }
}
  • Role name changes. It is a hash of the grant document: spawn-instance-nested-1b333002 becomes spawn-instance-nested-6210f6dc.
  • Related fix: no IAM writes on a nested spore. The proxy launch called SetupSporedIAMRole, which makes IAM writes a nested spore can't make. deploy.ProxyProfile now names spored-instance-profile without setup when the caller is a nested-spawn role. This affects both the launch path and upgrade.
  • Pinned by TestNestedSpawnGrantsTheEgressProxyGroupWritesOnManagedResources. It checks the action set, the exact condition and Resource: "*".
  • Discovery gap. TestNestedSpawnPolicyCoversTheChildLaunchCalls does not follow package-level seam vars, so it never saw these calls. That is why the targeted test above exists. I tried making discovery follow vars, but name-based resolution then flagged about 60 unrelated actions, so I reverted it.
  • Not done here: a live PutRolePolicy check. That is left to you.

New IAM actions per command (make cli-iam-actions)

Command Actions
spawn egress-proxy status ec2:DescribeInstances, ec2:DescribeRegions, ec2:DescribeSecurityGroups
spawn egress-proxy delete the above, plus ec2:TerminateInstances and ec2:DeleteSecurityGroup
spawn egress-proxy upgrade what an opted-in spawn launch needs to find or create a proxy: EC2 run, tag and SG create/authorize/revoke, DescribeRouteTables/Subnets/VpcEndpoints/Images, SSM SendCommand/GetCommandInvocation/GetParameter, the spored role-setup IAM actions, and pricing:GetProducts

Tests and revert evidence

All of these are hermetic. The checks run before pushing:

  • make check;
  • go test ./... with the AWS environment stripped;
  • lambda/ttl-reaper tests;
  • semgrep scan --config=auto --error;
  • TestPublicAPISurface, which shows no API change.

Each mutation below was applied, its test run, and the change reverted:

Mutation Failing test
Publisher drops the unchanged-value check TestActivityPublisherThrottles
Publisher drops the 10-minute throttle both publisher tests
PlanDelete ignores Verify TestPlanDeleteWritesNothing, TestDeleteRefusesAStructuralFailure
An in-use clients group becomes an error TestDeleteKeepsAClientsGroupInUse
cmd --dry-run falls through to the delete TestEgressProxyDeleteDryRunWritesNothing
cmd treats refusals as success TestEgressProxyDeleteRefusesAStructuralFailure
PlanUpgrade ignores the current proxy TestPlanUpgradeAlreadyCurrent
Upgrade ignores keepOld TestUpgradeKeepOld
spored never publishes TestEgressProxyPublishesActivityTags
Fixture spawn:managed=false TestReaperFixtureIsCurrent, plus the reaper's instance test
Reaper never reaps a passed deadline TestReaperTerminatesAnEgressProxyPastItsDeadline
Reaper sweep ignores occupancy TestReaperDeletesTheEgressProxyGroupsOnceUnused
Policy without Revoke/Delete the nested-policy test

Live-test checklist (owner)

  1. spawn egress-proxy status --region <r> with a phase-4 proxy running (v0.157.0). It should say "unknown (proxy predates spawn v0.158.0)" and "reuse no: launched by spawn 0.157.0". Repeat with -o json.
  2. spawn egress-proxy upgrade --vpc <vpc> --region <r>. Answer the prompt, wait for the new proxy to be ready, and check that the old one is terminated. Within about 1 minute of boot, status should show the new proxy's activity tags. After about 10 minutes of proxied traffic, last_activity should advance; with no traffic, it should not be rewritten (check CloudTrail CreateTags frequency).
  3. Run upgrade again. Expect "already current" and no prompt.
  4. Run upgrade --keep-old. With a current proxy, it does nothing; to exercise the flag, use a CLI built at another version.
  5. Run delete --vpc <vpc> --dry-run. It should print the plan and make no change (CloudTrail: no TerminateInstances or DeleteSecurityGroup).
  6. Run delete --vpc <vpc> while a member still carries the clients group. The proxy and the proxy group should go, and the clients group should be kept with the member named. Re-run after the member terminates; both groups should be gone.
  7. Refusal: tag a throwaway instance spawn:egress-proxy=<vpc>, run delete, and check that it is refused with the reason, untouched, and that the command exits 1.
  8. Nested: one real PutRolePolicy with the new document on a throwaway role. Then, from a --nested-spawn spore, run a --bootstrap-egress proxy launch in a no-NAT VPC: the Revoke calls should succeed and there should be no IAM writes. Optionally run egress-proxy delete there too. If the proxy group's ingress rule triggers a second authorization on the referenced clients group, it is covered: both groups are spawn-managed.
  9. Reaper: confirm the live REAPER_NET_RESOURCES value, which decides whether the sweep deletes the groups or only logs them.
  10. Clean up: spawn egress-proxy status --all-regions should show nothing left.

@scttfrdmn scttfrdmn added this to the v0.158.0 milestone Nov 4, 2026
@codecov

codecov Bot commented Nov 4, 2026

Copy link
Copy Markdown

@scttfrdmn

Copy link
Copy Markdown
Contributor Author

Live test (aws account, us-east-1, no-NAT VPC)

The "old" proxy and its members were launched with a CLI built from main (5e153b9c). The commands were run with a CLI built from this PR (a3a393bf). spored v0.157.0 was in use, which publishes no activity tags yet.

# Check Result
1 status, text and -o json, against the old proxy ✅ Shows the version mismatch, activity unknown (proxy predates spawn v0.158.0), and reuse no: it was launched by spawn …. Both groups are listed with their ENI users (clients: the 2 live members). The JSON keys are snake_case as pinned.
2 upgrade --vpc --yes ✅ Prints the plan and the mid-bootstrap warning, launches i-09e9231f… at this CLI's version, waits for it to be ready, then terminates only the verified old proxy.
3 upgrade again ✅ …is already current … Nothing to do. with no prompt.
5 delete --dry-run ✅ Prints the plan, including that the clients group is kept while in use, and says Dry run: nothing was terminated or deleted. CloudTrail's first write after it was the forged instance's RunInstances (my own aws CLI call).
6 delete while members hold the clients group ✅ Terminates the proxy and deletes spawn-egress-proxy-<vpc>. Keeps spawn-egress-clients-<vpc>, naming both members. After the members ended, a second delete removed the clients group.
7 A forged instance tagged spawn:egress-proxy=<vpc> (t4g.nano, default SG, no spored profile) ✅ status: reuse no: its security groups are …, not exactly the proxy group …. upgrade: left alone, with the reason. delete: REFUSE, not touched, exit 1. I terminated it myself afterwards.
8 Nested policy, one real PutRolePolicy on a throwaway role in spore-host-dev (435415984226, EC2-service trust only) ✅ Accepted. simulate-principal-policy: RevokeSecurityGroupEgress, RevokeSecurityGroupIngress and DeleteSecurityGroup are allowed with ec2:ResourceTag/spawn:managed=true, and implicitDeny with =false or untagged. The role is deleted and confirmed gone. Not run: a proxy launch from inside a nested spore.
9 Live REAPER_NET_RESOURCES on spawn-ttl-reaper-production reap, so the reaper's managed-network sweep does delete unused proxy groups.
10 status --all-regions after teardown ✅ No spawn egress proxy or proxy security group in 18 regions.

Not run live:

Teardown: All instances are terminated: the old proxy, the new proxy, the forged instance and both members. The VPC and everything in it is deleted. Leak diff against a pre-run baseline: no new instances, SGs, Spot requests, EIPs or test VPCs.

I also removed #1524 from the spawn-ts project board, which is the TypeScript port's board, not spawn's.

status (text and -o json) and delete --all --dry-run against a fresh
Substrate account; the TestTier0_CommandCoverageGate classification. A real
proxy's create/upgrade/delete needs a booted instance answering an SSM
readiness probe and was live-tested on #1525.
@scttfrdmn
scttfrdmn merged commit 393f49a into main Nov 4, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the feat/1515-egress-proxy-cli branch November 4, 2026 02: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