Repository navigation
feat(egress-proxy): spawn egress-proxy status|delete|upgrade, reaper coverage, nested-spawn grants (#1515 phase 5) - #1525
Merged
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
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 (
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 |
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.
This was referenced Nov 4, 2026
Merged
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.
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 inpkg/egressproxy/deployand reuses phase 3'sEvaluate,DeleteGroups,FindOrCreateandTerminate.cmd/egress_proxy.goholds 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 taggedspawn:egress-proxy(any state but terminated) it shows:IP:3128and public IP;spawn:version, and whether it matches this CLI;deploy.Evaluate's verdict and reason;deploy.Verify);For each VPC it also shows both groups and how many ENIs carry each. It is read-only.
delete(--vpcor--all,--yes,--dry-run).deploy.Verify:Evaluate's structural half, with the version, remaining-life and state checks left out.deploy.DeleteGroups(proxy group first), retryingDependencyViolationfor up to 2 minutes.--dry-runprints the plan and makes no writes. A declined prompt exits 75.upgrade(--vpc,--yes,--keep-old).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 fromDescribePrivateNetworkon the old proxy's subnet. It keeps the old proxy's published idle period, or 72h if there is none.Verify, unless--keep-old.Departures from the brief
--jsonbecame-o json.TestFlagConventions(spawn#40) fails any undeprecated local--json, so status uses the root-o json. The snake_case key set is pinned byTestEgressProxyStatusJSON.DescribeInstances. The count comes fromDescribeInstancesNetworkInterfaces[].Groups, the same dataDeleteGroupsand the reaper use, rather thanDescribeNetworkInterfaces, so no new IAM action is needed. An ENI that belongs to no instance is not counted.spored change
spored egress-proxynow writes two tags:spawn:egress-proxy-last-activity(RFC3339);spawn:egress-proxy-idle(the idle period it enforces).Details:
(*agent.Agent).PutInstanceTagswrapsa.tagger.putTags, the path used byready-*anddns-status.egressproxy.ActivityPublisherthrottles 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.postLaunchInstanceTags, applied only to the proxy's launch config, becauseTestEveryPostLaunchTagIsListedrequires it.unknown (proxy predates spawn v0.158.0).Reaper: verified, no reaper code change
spawn:managed=trueandspawn:ttl-deadline= launch + 144h.evaluatereaps it past that deadline (the ttl-deadline branch, afterleaveToSpored's grace). That deadline is inside the 168h ceiling.spawn:managedandspawn:created.reapSecurityGroupsdeletes each once no instance carries it and it is older than the 7-day grace.DependencyViolation, because the proxy group's ingress rule references it, and the sweep counts it as skipped.REAPER_NET_RESOURCES=reap, and the template default isreport. Please check the live value. If it isreport,egress-proxy deleteis the only thing that actually deletes the groups.deploy: trying it pulled roughly 20 extra modules, includinghcsshim, into the Lambda'sgo.mod. SoTestReaperFixtureIsCurrent(indeploy) runs the real producers (pkg/aws.BuildLaunchTags,deploy.Create's RunInstances input, andEnsureGroups' CreateSecurityGroup calls) against the fake. It writeslambda/ttl-reaper/testdata/egress_proxy_tags.jsonand fails when that file is stale.lambda/ttl-reaper/egress_proxy_test.goreads the file and covers both cases.evaluatelogs "unparseable ttl-deadline" for every instance whose deadline is valid and in the future. This is a misplacedlog.Printf, log noise only. It is filed and not fixed here.Nested-spawn policy (
pkg/aws/nested_spawn.go)The
NestedSpawnManageManagedstatement already usedec2:ResourceTag/spawn:managed, which is EC2's key and so correct for these EC2 actions.ec2:RevokeSecurityGroupIngress,ec2:RevokeSecurityGroupEgressandec2:DeleteSecurityGroup, all under that same condition.DeleteSecurityGroupis granted rather than refused:deleteneeds 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" } } }spawn-instance-nested-1b333002becomesspawn-instance-nested-6210f6dc.SetupSporedIAMRole, which makes IAM writes a nested spore can't make.deploy.ProxyProfilenow namesspored-instance-profilewithout setup when the caller is a nested-spawn role. This affects both the launch path andupgrade.TestNestedSpawnGrantsTheEgressProxyGroupWritesOnManagedResources. It checks the action set, the exact condition andResource: "*".TestNestedSpawnPolicyCoversTheChildLaunchCallsdoes 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.PutRolePolicycheck. That is left to you.New IAM actions per command (
make cli-iam-actions)spawn egress-proxy statusec2:DescribeInstances,ec2:DescribeRegions,ec2:DescribeSecurityGroupsspawn egress-proxy deleteec2:TerminateInstancesandec2:DeleteSecurityGroupspawn egress-proxy upgradespawn launchneeds to find or create a proxy: EC2 run, tag and SG create/authorize/revoke,DescribeRouteTables/Subnets/VpcEndpoints/Images, SSMSendCommand/GetCommandInvocation/GetParameter, the spored role-setup IAM actions, andpricing:GetProductsTests and revert evidence
All of these are hermetic. The checks run before pushing:
make check;go test ./...with the AWS environment stripped;lambda/ttl-reapertests;semgrep scan --config=auto --error;TestPublicAPISurface, which shows no API change.Each mutation below was applied, its test run, and the change reverted:
TestActivityPublisherThrottlesPlanDeleteignoresVerifyTestPlanDeleteWritesNothing,TestDeleteRefusesAStructuralFailureTestDeleteKeepsAClientsGroupInUse--dry-runfalls through to the deleteTestEgressProxyDeleteDryRunWritesNothingTestEgressProxyDeleteRefusesAStructuralFailurePlanUpgradeignores the current proxyTestPlanUpgradeAlreadyCurrentUpgradeignoreskeepOldTestUpgradeKeepOldTestEgressProxyPublishesActivityTagsspawn:managed=falseTestReaperFixtureIsCurrent, plus the reaper's instance testTestReaperTerminatesAnEgressProxyPastItsDeadlineTestReaperDeletesTheEgressProxyGroupsOnceUnusedLive-test checklist (owner)
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.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,statusshould show the new proxy's activity tags. After about 10 minutes of proxied traffic,last_activityshould advance; with no traffic, it should not be rewritten (check CloudTrailCreateTagsfrequency).upgradeagain. Expect "already current" and no prompt.upgrade --keep-old. With a current proxy, it does nothing; to exercise the flag, use a CLI built at another version.delete --vpc <vpc> --dry-run. It should print the plan and make no change (CloudTrail: noTerminateInstancesorDeleteSecurityGroup).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.spawn:egress-proxy=<vpc>, rundelete, and check that it is refused with the reason, untouched, and that the command exits 1.PutRolePolicywith the new document on a throwaway role. Then, from a--nested-spawnspore, run a--bootstrap-egress proxylaunch in a no-NAT VPC: the Revoke calls should succeed and there should be no IAM writes. Optionally runegress-proxy deletethere 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.REAPER_NET_RESOURCESvalue, which decides whether the sweep deletes the groups or only logs them.spawn egress-proxy status --all-regionsshould show nothing left.