Repository navigation
fix(egress-proxy): delete leaves no security group behind (#1651) - #1659
Merged
Merged
Conversation
`spawn egress-proxy delete` stopped at the first group it could not delete, so the clients group was never tried; it checked instances but never network interfaces; a kept group exited 0; and it gave up on a DependencyViolation after two minutes. Seen in a real account with both groups left and no ENIs (#749). Delete now terminates and waits (5m), still trying the groups on a timeout; waits up to 5m for interfaces to release either group; revokes the rules where one group names the other; and deletes both, each whatever happened to the other, retrying DependencyViolation with backoff for up to 10m. Every failure is joined into the error, kept groups included, so the command exits non-zero when anything is left. The TTL reaper's net sweep paginates DescribeSecurityGroups and logs a DependencyViolation instead of skipping it silently.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Contributor
Author
LIVE check (dev 435415984226, us-east-1, 2026-11-16, CLI built from this branch)
The fallback for a nested-spawn head ( |
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.
Fixes #1651. Part of the Leave-no-trace epic spore-host/spore-host#752.
Root causes (confirmed in code)
In
pkg/egressproxy/deploy:DeleteGroupsdeleted the proxy group first and returned on the first failure, so the clients group was never attempted.Deleteturned aGroupInUseErrorintoKeptwith a nil error, so the command exited 0 with groups left.groupUserschecks instances only (instance.group-id) and never network interfaces. A terminated proxy's ENI outlives it, so the group delete then meetsDependencyViolation.DependencyViolation), even if it had been tried.DependencyViolationretry was fixed 10 s polling for 2 minutes.In
lambda/ttl-reaper/netresources.go:DescribeSecurityGroupsread only the first page, and aDependencyViolationon delete was counted as skipped without a log line.Fix
Deletenow:ENIReleaseTimeout) until no ENI references either group (DescribeNetworkInterfaces,group-idfilter), re-checking instances on each poll;DependencyViolationwith doubling backoff (5 s up to 1 min) for up to 10 min (GroupDeleteTimeout);[]*GroupInUseErrorwithUsers/NetworkInterfaces/ReferencedBy) are in the error, so the command exits non-zero whenever anything is left.The timeouts are configurable through
DeleteOptions, and zero means the default.DeleteGroupsis the same pass with no waiting. IfDescribeNetworkInterfacesis denied, the ENI wait is skipped and theDependencyViolationretry covers it (see the IAM note below). Incmd, the delete failure keeps%w, soErrGroupsInUsestays matchable, and every kept group is printed with its reason.Reaper:
DescribeSecurityGroupsis paginated, and aDependencyViolationis logged with the group and the error. It is still not recorded as a failure, so it does not alarm.IAM
spawn egress-proxy deletenow also callsec2:DescribeNetworkInterfaces,ec2:RevokeSecurityGroupIngressandec2:RevokeSecurityGroupEgress.docs/reference/cli-iam-actions.mdis regenerated.I did not add
ec2:DescribeNetworkInterfacesto the nested-spawn role. Doing so put its inline fallback over IAM's 10240-byte cap (TestSporedRolesFitTheInlineLimitWhenMixed: 10256 bytes). Instead, a caller that is denied the ENI read relies on the retry. Owner's call whether to make room for it.Tests
TestDeleteRemovesBothGroups(table): happy path; proxy-group delete fails and clients is still deleted; ENI lingers across polls, is released, then delete succeeds; ENI never released, so the group is kept with the ENI named after a bounded wait; cross-reference revoked before any delete;DependencyViolationretried with backoff and succeeds; window expires and the error is returned; window is configurable; ENI read denied, so retry; in-use group kept, reported, error. Also updated:TestDeleteGroups,TestDeleteRefusesAStructuralFailure,TestDeleteKeepsAClientsGroupInUse,TestDeleteWaitIsBounded, and cmdTestEgressProxyDeleteKeepsAClientsGroupInUse, which had codified the exit-0 bug. Reaper:TestNetSweepReadsEveryPageOfGroups;TestNetSweepToleratesDependencyViolationnow asserts the log line.Checked against a revert that compiles (the original logic behind the new signatures): the ENI-wait, clients-still-attempted, revoke-ordering, window, in-use-error and terminate-timeout cases all fail on it. Both new reaper assertions fail on the original
netresources.go.Gates
make check: fmt, vet (all GOOS) and golangci-lint (10 modules) clean. Thehermetic-execstep fails spuriously because the clone path contains a space, sogo vet ./...andgo test ./...were run from the module root, pluslambda/ttl-reaperandlambda/sweep-orchestrator, all passing with no AWS env.semgrep scan --config=auto --erroron the changed Go files: 0 findings.Needs a LIVE check
Create an egress proxy in the dev account, run
spawn egress-proxy delete, and confirm bothspawn-egress-proxy-<vpc>andspawn-egress-clients-<vpc>are gone and the command exits 0. The ENI andDependencyViolationtiming is only modelled by fakes. Also check the error-code match for anUnauthorizedOperationfromDescribeNetworkInterfaces.