Repository navigation
feat(reaper): delete unused per-task spawn-instance-* IAM roles; repair empty reused profiles (#1300, #1318) - #1321
Merged
Conversation
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
scttfrdmn
force-pushed
the
feat/1300-reap-instance-roles
branch
from
October 26, 2026 21:29
753a269 to
fb19441
Compare
…rofiles; repair empty reused profiles (#1300, #1318) pkg/instancerole holds the one rule (Decide) and the delete, shared by the TTL reaper (REAPER_INSTANCE_ROLES / InstanceRoles / INSTANCE_ROLES / spawn reaper deploy --instance-roles, default report) and spawn cleanup --instance-roles. A role and its profile go only when both are tagged spawn:managed=true and 24h old, no instance in any enabled region (DescribeRegions; pending through stopped) has the profile, and the role is unused for 24h; an unreadable region or region list means nothing is deleted. spored-instance-role is never touched. IAM grants in pkg/reaperiam, the SAM ScanSelf branch and the member role allow the deletes only on spawn-instance-* tagged spawn:managed=true. CreateOrGetInstanceProfile re-attaches the role to an existing empty profile. Refs #1300 Refs #1318
scttfrdmn
force-pushed
the
feat/1300-reap-instance-roles
branch
from
October 26, 2026 21:45
fb19441 to
1570b98
Compare
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 #1300
Fixes #1318
Per-task
spawn-instance-<hash>IAM roles and instance profiles (one per distinct policy config, minted bypkg/aws.CreateOrGetInstanceProfile) now have a deleter, per spore-host/spore-host#610: the TTL reaper (newREAPER_INSTANCE_ROLES, default report) andspawn cleanup --instance-roles, both through one predicate in the newpkg/instancerole.The rule (
instancerole.Decide)A role and its same-name profile are deleted only when ALL hold:
spawn-instance-and is notspored-instance-role/spored-instance-profile(refused by name too);spawn:managed=true, and the profile (if it still exists) too;ec2:DescribeRegions,AllRegions=false, merged withREAPER_REGIONS), in state pending/running/stopping/stopped/shutting-down, has the profile attached (read fromIamInstanceProfile.Arnin the DescribeInstances response, not an ARN filter, so a filter that silently matched nothing cannot read as "unused"); if the region list or any region cannot be read, nothing is deleted;CreateDateare at least 24 h ago (a young profile is a launch recreating it after a partial delete);RoleLastUsedis absent or at least 24 h ago.Delete order: RemoveRoleFromInstanceProfile, DeleteRolePolicy (each inline), DetachRolePolicy (each managed), DeleteInstanceProfile, DeleteRole; stops at the first failure; NoSuchEntity counts as done.
Untagged legacy roles: none exist from spawn.
buildIAMTagshas writtenspawn:managed=trueon these roles and profiles since the commit that introduced thespawn-instance-%sname (spore-host 52ae503, 2026-01-14), so an untaggedspawn-instance-*role is not spawn's and is kept. No name-prefix adoption rule was added.Reaper
regionsForon each account), not justREAPER_REGIONS.REAPER_INSTANCE_ROLES/InstanceRoles/INSTANCE_ROLES/spawn reaper deploy --instance-roles:off|report|reap, default and typo =report(new deletion behaviour). DryRun wins. Preserved across deploys on all three paths (PARAM_MAP + merge, reaperconfig.Settable census, template default).WOULD delete role …/DELETED role …(DELETEDadded toActionSentinelsso idleness counts it). Summary:instance_roles_scanned,_deleted,_would_delete,_skipped,_accounts_denied(AccessDenied on ListRoles = member role not redeployed; not counted as Errors).IAM (pkg/reaperiam, SAM ScanSelf branch, cross-account member role — held equal by the existing drift gates)
(In both CFN templates the account is
${AWS::AccountId}via!Sub.) No mutating IAM action on*. New gateTestIAMMutationsAreScopedToPerTaskRoleschecks all three copies: every discovered mutatingiam:action is on exactly those two ARNs, carries the tag condition, matches none of spored-instance-role/-profile, spawn-ttl-reaper-ec2, spawn-ttl-reaper-selfscan-role, spawn-pool-worker-*, a user role; and does match a real spawn-instance role and profile.Not verified against AWS (no AWS calls in this work): IAM simulation of allow + deny, and one real PutRolePolicy of the scan-self document, are still needed before release (memory:
${aws:PrincipalAccount}passed every static check and broke every launch in #1069).#1318: empty reused profile
CreateOrGetInstanceProfile, when it finds an existing profile, now checks itsRoles: re-attaches the role if the profile is empty (LimitExceeded from a concurrent re-add is fine), and errors if it holds a different role. GateTestCreateOrGetInstanceProfile_RepairsAnEmptyProfile(substrate) fails against a compiling revert (0 roles). The reaper side keeps a pair whose profile is under 24 h old.CLI
spawn cleanup --instance-roles [--dry-run] [--yes]: previews with the sameSweep(reap=false), confirms, then re-sweeps with reap (each role re-decided at delete time). Always checks every enabled region via the sameinstancerole.EnabledRegions, account-wide.spawn footprintnames the deleters under the Global section.Gates, each watched failing against a compiling revert
in-use / young / recently-used / untagged / shared-role checks each dropped from Decide; shared role made a candidate; profile deleted before role removed; report mode deleting; dry run not winning; unreadable region skipped;
stoppeddropped from live states; unset parsing to reap; template default reap; InstanceRoles dropped from PARAM_MAP; dropped from Settable; flag removed; env not read; delete grant widened torole/*; condition removed; cross-account grant widened tospawn-*; SAM grant on*; sweep not called from run(); footprint counting all roles. All 23 caught. Second round (enabled regions, #1318, after rebase onto #1322): reaper using REAPER_REGIONS only (an instance in ap-south-1, outside REAPER_REGIONS, holds the profile), region-list error ignored, AllRegions=true, empty region list accepted, profile age dropped, DescribeRegions dropped from each of the 3 policy copies, the #1318 re-attach disabled, plus census/PARAM_MAP/DELETED sentinel/in-use/IAM-scope re-checked on the merged lists. All caught.Checks
make check: all tests pass incl. nested modules;check-build-tagsfails on /private/tmp paths, and fails the same on unmodified origin/main.make lint0 issues;make check-docsclean;semgrep scan --config=auto --error .0 findings. No pkg/aws exported symbol changed (comment only), so no api-snapshot.Follow-up filed: #1319 (spawn-pool-worker roles of an undrained pool are never deleted).
Rebased onto #1322 (empty buckets): list conflicts resolved keeping both sides (Settable, flags, PARAM_MAP/echo/census, Summary, account struct, knownAWSServices + iamActionFor); one
DELETEDsentinel shared by both sweeps.