Skip to content

feat: tag everything spawn creates spore-host:managed-by=spawn (#1652) - #1661

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/1652-tags
Nov 16, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/1652-tags

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #1652. Part of the Leave-no-trace epic spore-host/spore-host#752. Builds on #1660 (pkg/servicetags, libs v0.52.0).

What changes

Everything spawn creates carries the libs/tags set beside its spawn:* tags, which are unchanged (the reaper, spawn cleanup and spored key on them, and TTL enforcement still does). Helpers: pkg/sporetags (For, Fill = caller wins, Converge = add-only, Permanent, ScopeGlobal).

Resource Before After
Instance, its volumes, persistent Spot request (buildTags) spawn:* + managed-by=spawn, created (launch instant; re-anchored by AnchorLaunchTags for detached sweep members), schema
Security groups (MPI/EFA, Windows, DCV, web, egress proxy), placement groups (LifecycleTags) spawn:managed, spawn:created, Name, purpose + managed-by, created, schema, and scope=<region> + owner from Client methods
Launch Elastic IP lifecycle + owner tags + spore set; the instance's managed-by/scope/owner carry over
Imported key pair spawn:* + spore set, scope=<region>, owner
spawn-instance-* role + profile spawn:* + spore set, scope=global, owner; existing ones converged
spored-instance-role + profile spawn:managed only + spore set; converged
/spore-host/spored-*-v<N> managed policies untagged spore set; existing ones converged (TagPolicy)
spore-host/spawn-instance-boundary untagged spore set + spore-host:permanent=true; spawn setup-account converges an existing one (a launch never writes to it)
SpawnSweepCrossAccountRole spawn:managed + spore set; converged when adopted
SpawnBotCrossAccount, spore-portal-onboard roles spawn:* / Purpose + spore set (component=portal-onboard); onboard role converged
ISO import: role, profile untagged spore set + component=iso-import; converged
ISO import: Image Builder infra config, image untagged (infra config had ResourceTags only) Tags = spore set; build instances' ResourceTags too
Results / FSx buckets spawn:managed (+ purpose/FSx) + spore set, scope; existing spawn-results-*/spawn-staging-* converged
Staging bucket spawn:managed, purpose + spore set; re-configure keeps the first created
Schedules bucket (pkg/staging) service tags (params) / none (queue config) + spore set either way; params keeps #1660's service tags
Pool SQS queue spawn:managed, spawn:pool-run-id + spore set, scope=<region>
FSx filesystem, its DRA (CLI path) spawn:* / untagged DRA + spore set
AMI + snapshots (create-ami) caller + provenance + spore set (caller wins)
AMI copy source tags source's managed-by/owner; fresh created, scope=<target>
Snapshot-mount volume spawn:managed, from-snapshot + spore set
Self-hosted reaper (pkg/reaperdeploy): role, log group, bucket, function, both rules spawn:* / rules untagged + spore set, component=ttl-reaper; role converged; function re-tag keeps first created
Hybrid registry table Application/Purpose + spore set
Pipeline SNS topic spawn:pipeline-id + spore set with created = pipeline CreatedAt (SNS rejects a re-create with different tags; legacy topics fall back)

Nothing gets spore-host:role (#1660's keep-rules are untouched). spawn creates no launch templates. Not tagged: ENIs (deleted with the instance; tagging them would need ec2:CreateTags on network-interface, which the documented baseline does not grant), Capacity Block reservations (expire on their own; tagging would make a purchase depend on a new grant), the DRA spored creates on-instance (instance role has no fsx:TagResource).

Precedence (calque#233, lagotto#331)

Chosen: spawn writes each spore-host:* key only when the caller did not supply it. No new API field.

  • buildTags: the spore set is appended in a new Section 7b, after the caller's tags, with appendTagUnique (first wins). spawn:* keys stay spawn's.
  • buildIAMTags: sporetags.Fill over a copy of IAMRoleConfig.Tags; it no longer mutates the caller's map.
  • Converge is add-only (sporetags.Converge): it never changes created, owner, or a managed-by another tool set.
  • Tests: TestSporeTags_LaunchKeepsTheCallersManagedBy (Detector for calque; instance + volume specs), TestSporeTags_InstanceRoleKeepsTheCallersManagedBy (role + profile, then reuse), TestSporeTags_BuildTagsCallerWinsAndNoDuplicates (lagotto).

Tag budget

An instance gets three keys (managed-by, created, schema), not five: its region and spawn:iam-user already say scope and owner, and the documented maximal launch had exactly three slots to spare under AWS's 50 with spored's reserve (TestMonitoringSettingsFitOnAMaximalLaunch now 41 + 9 = 50). A caller can still set scope/owner. The budget fixtures in tags_limit_test.go / launch_config_object_test.go were adjusted, with the reasons in their comments.

IAM

New actions (docs/reference/cli-iam-actions.md regenerated):

  • iam:TagPolicy: every command that sets up an instance role, and spawn setup-account.
  • imagebuilder:TagResource: spawn image import.
  • events:TagResource: spawn reaper deploy.

A missing tag permission never fails a command: a tagged CreatePolicy, Image Builder create or PutRule refused as AccessDenied is retried untagged with one warning, and a denied converge changes nothing (silently, so baseline users don't get a warning on every launch). The documented user baseline (spore-host/spore-host docs/reference/iam-permissions.md) needs iam:TagPolicy on arn:aws:iam::*:policy/spore-host/spored-*; without it the spored policies stay untagged. spawn setup-account needs no change (it runs as an admin, and now converges the boundary's tags). The nested-spawn role does not get the IAM tag actions (listed in nestedSpawnNotGranted: only reached by the role-setup paths a nested spore skips).

Tests

internal/sdkanswer answers SDK calls in-process at the end of Initialize, so real clients run their own middleware, including the tagtest Detector. Wired into: launch (fake EC2 over HTTP), net resources and key pair, instance-role setup, spored role, boundary, ISO import, create-ami, buckets, FSx (pkg/aws); egress-proxy groups + instance; pool queue; schedules bucket; reaper deploy; pipeline topic stability. Allow-list entries, each with a reason: S3 CreateBucket (tagged by the PutBucketTagging that follows, which the Detector checks), S3 PutObject (reaper artifact zip in the tagged bucket), IAM CreatePolicy under the calque Detector (the spored policy is spawn's) and in the AccessDenied-fallback test.

Converge tests: an existing untagged spored policy, role and profile get the tags and keep a pre-existing created (TestSporeTags_SporedRoleAndConverge); untagged boundary → Tagged, re-run no-op; ISO-import role/profile; reaper role.

Revert checks (each a compiling revert, watched fail):

  • spored policy Tags: iamtags.FromMap(nil) → tagtest: IAM CreatePolicy would create a resource without spore-host:managed-by=spawn in TestSporeTags_InstanceRoleSetup.
  • ISO-import role Tags: iamtags.FromMap(nil) → tagtest: IAM CreateRole ... without spore-host:managed-by=spawn in TestSporeTags_ISOImport.
  • iamTagMap overwriting instead of Fill → IAM CreateRole ... has spore-host:managed-by=spawn, want calque (and CreateInstanceProfile).
  • spore set appended before the caller's tags in buildTags → EC2 RunInstances ... TagSpecifications[0] (instance) has spore-host:managed-by=spawn, want calque; TagSpecifications[1] (volume) ....
  • reaper rule Tags: nil → tagtest: EventBridge PutRule would create a resource without ....

Gates

  • make check, run from a space-free worktree (the clone lives under /Volumes/External HD/..., and make check's hermetic-exec path and lambda/dashboard-api's setup-all script test break on the space): fmt, vet, every-GOOS vet, staticcheck, golangci-lint 2.15.0 (0 issues, 10 modules), hermetic short tests, nested modules, tidy all pass. check-build-tags passed from a non-symlinked path (/private/tmp); from /tmp it fails identically on main, a symlink artefact of the script's path comparison.
  • make api-snapshot: one addition, BoundaryOutcome.Tagged.
  • make cli-iam-actions: regenerated (above).
  • lambda/ttl-reaper/testdata/egress_proxy_tags.json regenerated (TestReaperFixtureIsCurrent -update); the reaper's tests pass.
  • docs-gen: no change.
  • semgrep scan --config=auto --error on the 45 changed Go files: clean (one nosemgrep on the test answerer's MethodByName).

Not run against AWS; all tests are hermetic.

Every resource spawn creates now carries the libs/tags spore.host set
(managed-by=spawn, created, schema, and scope/owner where they apply)
beside the unchanged spawn:* tags: instances, volumes, Spot requests,
security and placement groups, key pairs, launch EIPs, instance roles
and profiles, the /spore-host/spored-* managed policies, the
spawn-instance boundary (plus spore-host:permanent=true), results/FSx/
staging/schedules buckets, pool queues, FSx and DRAs, AMIs and
snapshots, the self-hosted reaper, the egress proxy, the ISO-import
role/profile/Image Builder config, the portal-onboard and bot roles, the
hybrid registry table and pipeline topics. No spore-host:role.

A caller's spore-host:* keys win (LaunchConfig.Tags, IAMRoleConfig.Tags),
so calque's and lagotto's managed-by survive. Existing reusable resources
are converged add-only. A missing tag permission never fails a command.

The tagtest Detector runs on real SDK clients (internal/sdkanswer) for
every create path.

Fixes #1652
@scttfrdmn

Copy link
Copy Markdown
Contributor Author

LIVE check (dev 435415984226, us-east-1, 2026-11-16, CLI built from this branch)

Two t3.micro launches, both reached spored readiness: a default launch (spored-instance-role) and one with --iam-policy s3:ReadOnly (per-instance spawn-instance-d83504c4).

Resource spore-host:*
instance, root volume (both) managed-by=spawn, created, schema=1 (23 tags total, inside the budget)
spored-instance-role / profile, an existing role, converged full set, scope=global, owner
spawn-instance-d83504c4 role / profile, new full set
spored-policy-v3, spored-baseline-policy-v3 (/spore-host/), converged full set
boundary untagged, by design: only spawn setup-account converges it
workstation key spawn-key-scttfrdmn, reused untagged (not created by this launch)

Both terminated. Leak check: no a2-* instances, unattached EIPs or available volumes. The per-launch role is left for the reaper's 24 h instance-role sweep.

Follow-up filed: #1662 (deny the instance role rewriting its own spore-host:* tags).

@scttfrdmn
scttfrdmn marked this pull request as ready for review November 16, 2026 22:05
@codecov

codecov Bot commented Nov 16, 2026

Copy link
Copy Markdown

@scttfrdmn
scttfrdmn merged commit ead1f85 into main Nov 16, 2026
9 checks passed
@scttfrdmn
scttfrdmn deleted the feat/1652-tags branch November 16, 2026 22:17
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.

Tag everything spawn creates spore-host:managed-by=spawn (incl. the spored policies)

1 participant