Skip to content

fix(pool): give an undrained pool's IAM role a deleter (#1319) - #1350

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/1319-pool-worker-roles
Oct 27, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/1319-pool-worker-roles

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #1319

What

spawn pool drain was the only deleter of a pool's spawn-pool-worker-<hash> role and instance profile, so an undrained pool (crashed caller, a forgotten drain, an nf-spawn run-end hook that never fired) left them in the account indefinitely.

Chosen fix: rename pool roles into the per-task family instead of widening the reaper's grants.

  • spawn pool create now names the role/profile spawn-instance-pool-<16 hex of sha256(run id)> (instancerole.PoolWorkerRoleName; cmd/pool.go calls it, so the created name and the deleted name can't drift). It is inside spawn-instance-*, so the TTL reaper's existing REAPER_INSTANCE_ROLES sweep and spawn cleanup --instance-roles remove it under Leave no trace: reap per-task spawn-instance-<hash> IAM roles and instance profiles once no instance uses them #1300's rule: tagged spawn:managed=true, no instance in any enabled region (pending through stopped) holding the profile, role and profile at least 24h old, role unused for 24h. A pool with a live worker always keeps its role.
  • The predicate stays exact. A spawn-instance-pool-* role is also kept unless its spawn:pool-run-id tag hashes to its name (KeepPoolUnmatched).
  • No IAM change is needed. The reaper's grants (role/spawn-instance-*, instance-profile/spawn-instance-*, plus the spawn:managed tag conditions) already cover the new name. Neither template is touched.
  • Legacy spawn-pool-worker-<hash> roles (pools created before this release) are outside the reaper's grants. They are swept only by spawn cleanup --instance-roles (instancerole.SweepWith(..., Options{LegacyPoolWorkers: true})), under the same rule, and only for the exact spawn-pool-worker-<16 lowercase hex> shape whose run-id tag hashes to the name. ProfilesInUse now also records legacy pool profiles, so an in-use legacy role is kept. The default Sweep/Decide, which the reaper uses, never reads them.
  • spawn pool drain removes both names. A failure on the legacy name is printed as a note, not as a failed drain.

Why not a queue-gone check: the reaper has no SQS grants. Also, "no instance holds the profile for 24h" already means the pool has no consumer, and pool create re-creates the role if a pool is ever reused.

Gates (each watched failing against a compiling revert)

Revert Fails
poolWorkerRoleName returns the legacy name TestAbandonedPoolRoleHasADeleter, TestPoolWorkerRoleNameFitsIAM
cleanup passes Options{} TestCleanupInstanceRolesRemovesLegacyPoolRoles
pool tag/name match removed (pool && false) TestDecidePoolWorkerRoles, TestDecideLegacyPoolWorkerRoles, TestCleanupInstanceRolesRemovesLegacyPoolRoles
ProfilesInUse ignores legacy profiles TestSweepPoolWorkerRoles
IsLegacyPoolWorker drops the length check TestDecideLegacyPoolWorkerRoles
SweepWith doesn't list legacy roles TestSweepPoolWorkerRoles
drain skips the legacy delete (_ = legacy) TestDrainAlsoRemovesThePrePoolRenameRole

Checks

make check passes every step except check-build-tags, which fails identically on unmodified main in a /private/tmp worktree. make lint reports 0 issues in all 10 modules. make gen-docs + check-docs and semgrep are clean. No AWS calls.

@codecov

codecov Bot commented Oct 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.11765% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
cmd/cleanup.go 83.33% 1 Missing ⚠️
cmd/pool.go 85.71% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

spawn pool create now names a pool's worker role and instance profile
spawn-instance-pool-<hash of the run id>, inside the per-task family
pkg/instancerole (the TTL reaper and spawn cleanup --instance-roles)
already deletes, so a pool nobody drains loses its role once no worker
holds it and it has been unused for 24h. A pool role must also carry a
spawn:pool-run-id tag that hashes to its name. Pre-rename
spawn-pool-worker-<hash> roles are outside the reaper's grants; spawn
cleanup --instance-roles sweeps those (exact shape and tag match only),
and spawn pool drain removes both names.
@scttfrdmn
scttfrdmn force-pushed the fix/1319-pool-worker-roles branch from 7327e42 to 9353e9a Compare October 27, 2026 02:05
@scttfrdmn
scttfrdmn merged commit b365f96 into main Oct 27, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the fix/1319-pool-worker-roles branch October 27, 2026 02:21
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.

spawn-pool-worker-<hash> roles of a pool that is never drained are never deleted

1 participant