Repository navigation
fix(reaper): keep spawn-instance-* roles an enabled schedule still names (#1378) - #1386
Merged
Merged
Conversation
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
…mes (#1378) The per-task role sweep (pkg/instancerole) deleted a role once no instance held its profile and it was unused for 24h. A schedule stores a spawn-instance-* profile name in its params and launches with it at every firing without re-creating it, so an armed reaper or spawn cleanup --instance-roles would delete a rarely-firing schedule's role and fail its next firing. Both callers now collect References from a shared ScheduleSource (the spawn-schedules table in us-east-1 plus each params object) before the sweep, and Decide keeps any profile an active, not-run-out schedule names in defaults.iam_role or a row's iam_role. Whether a schedule counts is scheduler-handler's own check (ScheduleRecord.FiringAt, now shared). Any incomplete read fails closed: no role is deleted, the reaper counts the account in instance_roles_references_unreadable, the CLI refuses. Sweep refuses References that were not collected. IAM: dynamodb:Scan on spawn-schedules (us-east-1) and s3:GetObject on spawn-schedules-*/schedules/* on the reaper's own role (SAM template and spawn reaper deploy), from pkg/reaperiam.ScheduleReferenceStatements, with drift gates; the member role is unchanged.
scttfrdmn
force-pushed
the
fix/1378-schedule-referenced-roles
branch
from
October 28, 2026 18:43
9092aee to
8bbb317
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 #1378
The per-task role sweep (
pkg/instancerole, used by the TTL reaper'sREAPER_INSTANCE_ROLESand byspawn cleanup --instance-roles) now keeps aspawn-instance-*role while an enabled schedule still names it. If the schedules can't be read completely, it deletes nothing.Deferred launchers, and which ones need a reference source
spawn schedule create)S3ParamsBucket/S3ParamsKey, in the infra account'sspawn-schedules-*bucket) holdsdefaults.iam_roleand each row'siam_role. That's the only key the sweep orchestrator passes to RunInstances (spored.go), and nothing re-creates the role at a firing.instancerole.ScheduleSourcespawn-sweep-orchestration+spawn-sweeps-*params)RoleLastUsed. The role can't sit unused for the 24h grace while the sweep still has members to launch.references.go)PipelineState.InstanceProfile)CreateOrGetInstanceProfileat match time, so a deleted role is re-created.stopped, whichProfilesInUsealready counts. A replacement launch is unwanted (spored retires it).spawn sweep resume(local~/.spawn/sweeps/<id>.json)Behaviour
ScheduleRecord.FiringAt, is now inpkg/scheduler, and the handler uses it too, so the two can't drift. It means statusactive, undermax_executions, beforeend_after.SweepreturnsErrReferencesNotCollectedfor aReferencesvalue thatCollectReferencesdidn't produce, before it reads a single role.instance-roles: <acct>: role <name> kept: referenced by schedule <id>in report and reap mode;instance_roles_referencedandinstance_roles_references_unreadable, the latter also counted inerrorsunless the cause is AccessDenied.referenced by schedule <id>;no IAM role was deleted: ...;instancerole.NewScheduleSource(cfg)reads the tablespawn-schedulesin us-east-1 (scheduler.TableName/TableRegion, where the CLI writes it) and each params object in its schedule's region. The reaper builds it with its own base credentials (the infra account); the CLI builds it withLoadInfraAWSConfig, the configspawn scheduleuses.IAM
New grants, read-only, scoped to exactly the schedule data. They're on the reaper's own role only. The member-account role is unchanged and is gated never to get them.
dynamodb:Scanonarn:aws:dynamodb:us-east-1:${AWS::AccountId}:table/spawn-schedules. Scan rather than Query, because the GSI is sparse.s3:GetObjectonarn:aws:s3:::spawn-schedules-*/schedules/*, the resources scheduler-handler's role already reads.Where the grants live:
pkg/reaperiam.ScheduleReferenceStatements.spawn reaper deploy:ScanSelfPolicyDocumentnow renders ScanSelf + schedule statements, because that single role is both base and target.grantedElsewhere:s3:GetObjectadded, and thedynamodb:Scanreason updated.internal/iamcoverage: the reaper's function-role context claimss3:GetObject(new support for exact-action context entries).For users:
spawn cleanupnow also callsdynamodb:Scanands3:GetObject, with the infra profile (docs/reference/cli-iam-actions.mdregenerated).Gates (each watched failing against a compiling revert)
SaveSchedule+UploadScheduleParams+NewScheduleSource)_ = pf.Defaults)TestScheduleReferencedRolesAreKept,TestDisablingAScheduleReleasesItsRole, reaper + CLI scenario tests_ = rowTestScheduleReferencedRolesAreKept, reaper + CLI scenario testsif false && rec.FiringAt(...)TestDisablingAScheduleReleasesItsRole/paused,TestScheduleReferencedRolesAreKept, scenario testscase len(f.ReferencedBy) > 0 && falseTestDecideKeepsAReferencedRole,TestSweepKeepsReferencedRoles, Substrate, reaper and CLI testsbreakTestScheduleReferencesFailClosedOnScanErrors/*,.../no_schedules_table, reaperTestInstanceRoleSweepFailsClosedOnUnreadableSchedules/{access_denied,throttled}, CLI.../access_denied&& false)missing_params_object, reaper + CLImissing_params_objectFailsClosedOnUnreadableSchedules/*,WithoutReferenceSourcesDeletesNothing&& falseTestSweepRefusesUncollectedReferencesConsistentRead: falseTestScheduleReferencesFailClosedOnScanErrorsinstanceroletestscenario (#1351poolqueuetestpattern)TestInstanceRoleSweepAgreesWithTheCLI,TestCleanupInstanceRolesAgreesWithTheReaperpkg/schedulertable/*TestScheduleReadIsScopedToTheSchedules,TestSAMTemplateGrantsTheScheduleRead!IfTestSAMTemplateGrantsTheScheduleRead(+TestGrantedElsewhereIsInTheSAMTemplate, iamcoverageTestEveryPrincipalCallIsGrantedon removal)TestScheduleReadIsOnTheReapersOwnRoleOnly(+ both scan-self drift tests)Deploy steps
lambda/ttl-reaper:make deploy/sam deploy). This carries the code and the two new grants together. Snapshot the stack parameters first and diff them for zero drift after;InstanceRolesstaysreport.dynamodb:Scanonspawn-schedules, deny on another table; allows3:GetObjectonspawn-schedules-us-east-1/schedules/x, deny outsideschedules/.role ... kept: referenced by schedule ...for any schedule-held roles, andinstance_roles_references_unreadable == 0.reap.ttl-reaper-cross-account-role.yaml): no change, no redeploy.spawn reaper deploy.Follow-ups filed
spawn schedule create --regionother than us-east-1 targets a scheduler-handler that is never deployed there.sweep resumereuses aspawn-instance-*name without re-creating it.Checks
make check,make lint(0 issues, all 10 modules) andsemgrep scan --config=auto --error .(0 findings) pass from/private/tmp/spawn-1378.make cli-iam-actionswas regenerated, andmake gen-docsregenerateddocs-gen/cleanup.md.