Skip to content

Windows launches: delete the per-instance security group with its instance (#1623) - #1636

Merged
scttfrdmn merged 3 commits into
mainfrom
hardening/1623-windows-sg-deleter
Nov 15, 2026
Merged

scttfrdmn merged 3 commits into
mainfrom
hardening/1623-windows-sg-deleter

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #1623

What changes

spawn terminate deletes the per-instance Windows group. For an instance tagged spawn:os=windows, terminate reads its spawn:managed=true, spawn:purpose=windows groups before terminating (a terminated instance soon stops reporting them). After the terminate request it waits up to 10 min for terminated, then deletes each group, retrying DependencyViolation while the ENI detaches. A group another live instance still uses (two launches with one --name share spawn-windows-<name>) is left and named. It is best-effort: the instance is already terminating, so a failure prints the reason and the manual command and never fails terminate. The deleter is pkg/aws InstanceWindowsSecurityGroups + DeleteSecurityGroupsAfterTerminate, the same wait-then-delete shape as egress-proxy delete. WindowsSecurityGroupPurpose replaces the "windows" literal at creation.

spored's self-terminate path cannot do this. The instance is what dies, and its ENI detaches only after spored is gone. So that path, and the reaper's own terminate and a console terminate, rely on the TTL reaper. Its network-resource sweep already reclaimed spawn-managed groups with no instance (this confirms spawn-windows-* is covered), but only after 7 days, a grace meant for the MPI group that later runs reuse by name. A spawn:purpose=windows group now gets 1 hour (perInstanceGroupGrace). An occupied one is never touched.

Tests

  • pkg/aws/windows_sg_test.go: only the Windows group is selected (not MPI, not a user's group). Deletion happens after termination, with two DependencyViolation retries. A group shared with i-twin is left, with the error naming it. Nothing is deleted while the instance never reaches terminated. The reaper's literal must equal WindowsSecurityGroupPurpose.
  • lambda/ttl-reaper/netresources_test.go: of four groups, only the 2-hour-old unused Windows group is deleted. A 20-minute-old one, an occupied one, and an MPI group (still 7 days) are kept.
  • Regenerated api/public-surface.txt (3 additions) and docs/reference/cli-iam-actions.md: spawn terminate now needs ec2:DescribeSecurityGroups and ec2:DeleteSecurityGroup.
  • make check is clean apart from the known space-in-path failures. Semgrep is clean.

Deploy steps

  • CLI: ships with the release.
  • spawn-ttl-reaper: code-only (the reaper role already has ec2:DeleteSecurityGroup, tag-gated on spawn:managed=true). No IAM change. The sweep follows REAPER_NET_RESOURCES: report logs WOULD reap security group ... spawn-windows-... and deletes only under reap.

Live checks for the owner

  1. spawn launch --os windows --name sgtest --ttl 30m, then spawn terminate sgtest --yes. It prints Deleted security group sg-..., and aws ec2 describe-security-groups --filters Name=group-name,Values=spawn-windows-sgtest is empty.
  2. Launch a second one, terminate it with aws ec2 terminate-instances (not spawn), wait more than an hour, and confirm the reaper's next run logs REAPED security group ... (spawn-windows-...) under reap, or WOULD reap under report. Then confirm the group is gone or delete it.
  3. Verify both instances are terminated and nothing is left (spawn orphans).

@codecov

codecov Bot commented Nov 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 67.46988% with 27 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/terminate.go 0.00% 14 Missing ⚠️
pkg/aws/windows_sg.go 82.35% 12 Missing ⚠️
pkg/aws/securitygroup.go 0.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn force-pushed the hardening/1623-windows-sg-deleter branch from a33bf41 to f668b34 Compare November 14, 2026 20:17
scttfrdmn and others added 3 commits November 14, 2026 15:14
…tance (#1623)

spawn terminate now reads a Windows instance's spawn:purpose=windows
groups before terminating it, waits for terminated, and deletes them
(retrying DependencyViolation while the ENI detaches; a group another live
instance uses is left). Every other way an instance ends is covered by the
TTL reaper, whose network-resource sweep now reclaims an unused
per-instance Windows group after an hour instead of seven days.
@scttfrdmn
scttfrdmn marked this pull request as ready for review November 14, 2026 23:15
@scttfrdmn
scttfrdmn force-pushed the hardening/1623-windows-sg-deleter branch from f668b34 to d8fa6e6 Compare November 14, 2026 23:15
@scttfrdmn
scttfrdmn merged commit e0b4d8d into main Nov 15, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the hardening/1623-windows-sg-deleter branch November 15, 2026 01:57
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.

Windows launches leave their per-instance spawn-windows-<name> security group behind after termination

1 participant