Skip to content

feat(cleanup,reaper): remove spawn's empty staging and results buckets (#1301) - #1322

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/1301-empty-bucket-cleanup
Oct 26, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/1301-empty-bucket-cleanup

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #1301

Leave no trace for spawn's two per-account, per-region buckets: spawn-staging-<account>-<region> (#1293) and spawn-results-<account>-<region>. No object is ever deleted; only a bucket that is already empty, for 7 days, is removed. Deleting results data stays opt-in (#1076).

What

  • pkg/bucketsweep (new, no pkg/aws dependency): the decision and the delete, shared by the CLI and the reaper. A bucket is deleted only if ALL hold:
    • exactly spawn's name for the account and region (only those two names are ever looked at; the reaper needs no ListAllMyBuckets);
    • ExpectedBucketOwner = the account on every call;
    • tagged spawn:managed=true, or an untagged results bucket on that exact name (creation tagging used to be best-effort and its failure ignored, so an untagged one on the exact name, owned by the account, is spawn's);
    • empty: results bucket via ListObjectVersions (versions + delete markers, so versioned buckets count) and ListMultipartUploads; the staging bucket is never listed (no spawn role may list it, User data: fetch the bootstrap from S3 behind a small verifying stub, removing the 16 KiB ceiling (follow-up to #1246) #1274, enforced by TestNoGeneratedPolicyReachesTheStagingBucket), so its emptiness check is S3's BucketNotEmpty refusal on DeleteBucket (its objects all expire after a day);
    • no spawn:fsx-stack-name tag; for results, no lifecycle rules (a re-created bucket would silently lose spawn results lifecycle --apply tiering);
    • spawn:empty-since stamp (written on the first empty sighting, removed when seen in use or by a launch that uses the bucket) at least 7 days old.
  • spawn cleanup --buckets: --dry-run writes nothing (not even the stamp); otherwise it stamps, then asks before deleting and re-checks each bucket just before the delete.
  • Reaper: REAPER_EMPTY_BUCKETS / EmptyBuckets / EMPTY_BUCKETS / spawn reaper deploy --empty-buckets: off|report|reap, default report (logs, writes nothing; arming reap starts the 7 days). DryRun wins. Runs per account per region. Summary: empty_buckets_scanned/stamped/deleted/would_delete/failed. Deployed value preserved on all three paths. DELETED added to the idleness action sentinels.
  • IAM (reaperiam, SAM ScanSelf, member role, held equal by the drift gates):
    • arn:aws:s3:::spawn-staging-*: s3:GetBucketTagging, s3:PutBucketTagging, s3:DeleteBucket
    • arn:aws:s3:::spawn-results-*: s3:ListBucket, s3:ListBucketVersions, s3:ListBucketMultipartUploads, s3:GetBucketTagging, s3:PutBucketTagging, s3:GetLifecycleConfiguration, s3:DeleteBucket
    • The drift test now maps SDK methods to IAM action names for S3 (HeadBucket→ListBucket etc.).
  • Launch paths clear a stale spawn:empty-since stamp (best effort): EnsureStagingBucket and CreateS3BucketIfNotExists (only for spawn-staging-/spawn-results- names).
  • Re-creation: the results bucket is now tagged spawn:managed=true + spawn:purpose=task-results rather than spawn:fsx-backing-bucket=true (Fixed). S3 defaults supply BPA/SSE-S3/BucketOwnerEnforced, as before; staging is re-created fully configured by EnsureStagingBucket. Tests cover both.
  • spawn footprint shows the stamp and the date the bucket becomes deletable.
  • spawn cleanup (plain) no longer offers a spawn:managed bucket as removable and then fails with "don't know how to remove" (Fixed); parseARN names an S3 bucket correctly.

Before deploying

Redeploy the spawn-ttl-reaper-ec2 member stacks (and the reaper stack for ScanSelf) before arming reap. Without that, the sweep logs each bucket it could not read and what to redeploy, and counts it in empty_buckets_failed. It does not count it as an operational error.

Not verified against AWS (no AWS calls were made): run PutRolePolicy plus allow/deny simulation on the statements above, and check that HeadBucket/GetBucketTagging on a missing bucket returns 404 under these grants.

#1301)

spawn cleanup --buckets and the reaper's REAPER_EMPTY_BUCKETS sweep
(off|report|reap, default report) delete spawn-staging-<acct>-<region> and
spawn-results-<acct>-<region> once empty for 7 days, tracked with a
spawn:empty-since tag. No object is ever deleted. The staging bucket is
never listed (#1274); S3's BucketNotEmpty is its emptiness check.
IAM scoped to arn:aws:s3:::spawn-staging-* and spawn-results-* in all
three policy copies; setting threaded through make deploy, the SAM
template and spawn reaper deploy with preservation.

Fixes #1301
@codecov

codecov Bot commented Oct 26, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 78.89273% with 61 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/bucketsweep/bucketsweep.go 84.17% 22 Missing ⚠️
cmd/cleanup.go 69.11% 21 Missing ⚠️
pkg/aws/footprint.go 21.73% 18 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 121e3d5 into main Oct 26, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the feat/1301-empty-bucket-cleanup branch October 26, 2026 21:22
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.

Leave no trace: remove empty spawn-staging-* and spawn-results-* buckets

1 participant