Skip to content

spawn orphans and spawn cleanup report nothing by default: --mine filters on a tag spawn never writes to shared infrastructure #708

Closed

Description

@scttfrdmn

Found while doing #685's reaping half. It is a separate bug, and a worse one than what I was looking for.

The symptom

Same account, same region, one flag apart:

$ spawn orphans --region us-east-1
No orphaned spawn-managed resources in us-east-1.

$ spawn orphans --region us-east-1 --all
us-east-1  ec2  security-group    sg-0b5e633f5d59e68d2     -  -
us-east-1  ec2  security-group    sg-0d071badb4fdc3c14     -  -
us-east-1  iam  instance-profile  spawn-instance-01eb1b3b  -  2026-07-20T03:18:21Z
... (21 total: 9 security groups, 12 IAM instance profiles)

21 resource(s).

The oldest is from 2026-07-19. Both commands default to the narrow scope, so the default answer has been "nothing to clean" for as long as these have existed.

Why

DiscoverManagedResources applies OnlyMine as a tag equality check (pkg/aws/cleanup.go:93):

if opts.OnlyMine && tags["spawn:iam-user"] != callerARN {
    continue
}

spawn:iam-user is written by pkg/aws/tags.go — the instance tag builder. Shared infrastructure is created elsewhere and does not get it. Verified against every managed security group in the account:

$ aws ec2 describe-security-groups --filters Name=tag:spawn:managed,Values=true \
    --query 'SecurityGroups[].[GroupName,Tags[?Key==`spawn:iam-user`].Value|[0]]' --output text
spawn-windows-warm-payoff	None
spawn-windows-win95-verify	None
spawn-dcv	None
...   # None, for all nine

A missing tag reads as "", which never equals a caller ARN — so the filter does not narrow the result for these classes, it empties them. --mine is not "my resources"; for every resource class except instances and volumes it is "no resources".

This is a silent failure in the direction that costs money. orphans says "nothing here" and is believed.

Scope

  • spawn orphans, spawn cleanup, spawn resources — all three default to OnlyMine and all three go through DiscoverManagedResources.
  • Affected classes are everything spawn creates outside the instance tag path: security groups, IAM roles and instance profiles, key pairs, log groups, DynamoDB tables.
  • Instances and volumes are fine — they are tagged by pkg/aws/tags.go.
  • Elastic IPs happen to be unaffected because scanAddresses ignores OnlyMine entirely, and the placement-group sweep added in fix(mpi): stop leaking security groups and placement groups on a rejected or failed cohort (#685) #706 does the same for the same reason. That inconsistency is worth settling as part of this.

Two possible fixes, and I do not think they are equivalent

(a) Stamp spawn:iam-user on shared infrastructure at creation. Makes --mine mean what it says. But it does nothing for the resources already out there — the 21 above stay invisible to the default command forever, which is the population that actually matters. And "mine" is a questionable notion for a security group that is deliberately shared and reused by name across runs and principals (#685's MPI group is exactly that).

(b) Make the absence of the tag not disqualify. Treat spawn:iam-user == "" as "unattributable shared infrastructure" and include it in the narrow scope, filtering out only resources tagged for a different principal. Fixes the existing population, and matches what the two separately-scanned classes already do.

I lean (b), with (a) as a follow-up for new resources so the data improves over time — but the shared-by-design case means (a) alone would leave the bug in place.

Either way orphans should probably say how many resources it excluded by scope, so "nothing here" is never the whole story when it is not true.

Not in #706

#706 fixes the placement-group half of #685 and sidesteps this by not applying the filter. I did not want to widen that PR into a change in what --mine means across every command.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions