Skip to content

fix(task): grant spored self-management baseline on scoped task profiles (#406) - #407

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/406-task-spored-baseline
Jul 19, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/406-task-spored-baseline

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Summary

Fixes #406 — a spawn task run instance did not self-terminate on completion (and would not have enforced its TTL in-instance either). Root-caused by the increment-2 smoke test.

Root cause

SSM'd into a live task instance: spored v0.81.0 was running, /tmp/SPAWN_COMPLETE existed with the right JSON, but the spored log showed:

Config: TTL=0s, IdleTimeout=0s, Hibernate=false
Warning: Could not load config from tags: ... UnauthorizedOperation ... ec2:DescribeTags

The scoped IAM instance profile task run creates (via IAMRoleConfig.InlinePolicyJSON, added in #404 for per-task S3 staging access) replaced the default spored role entirely — and the InlinePolicyJSON path bypasses buildInlinePolicy, which is the only place that always prepends spored's EC2 self-management grants. With no ec2:DescribeTags, spored can't read spawn:ttl / spawn:on-complete, so:

  • on_complete=terminate never fires, and
  • TTL isn't enforced in-instance either — only the out-of-band reaper backstops it.

This was the "on-complete didn't fire" symptom from the first smoke test; the real scope is broader (TTL too), which is why it's worth fixing before release.

Fix

  • Extract the spored self-management statements into sporedSelfManagementStatements() + sporedBaselinePolicyDoc() (shared with buildInlinePolicy, so the two can't drift).
  • Whenever InlinePolicyJSON is set, attach that baseline as a second inline policy (spored-baseline-policy) on both the create and update paths.
  • task run also tags the completion file explicitly (CompletionFile/CompletionDelay), so on-complete doesn't depend on provider-side defaulting / tag-visibility timing.

Verification

Real AWS, end-to-end (spore-host-dev, t3a.small, TTL 15m): task launched → ran → wrote completion.json (exit 0) → self-terminated ~4 min after completion. Leak-check across all smoke task-ids: clean, zero orphans. (The pre-fix run stayed running until manually killed.)

Unit: TestSporedBaselinePolicyDoc (baseline carries DescribeTags/Terminate/CreateTags, valid JSON), TestBuildInlinePolicyIncludesBaseline (refactor didn't drop the baseline), TestTaskLaunchConfig (completion-file tagged). TestFlagConventions/TestTier0 pass; Semgrep clean.

Closes #406

…les (#406)

Root-caused by the increment-2 smoke test: a 'spawn task run' instance never
self-terminated on completion, and would not have enforced its TTL in-instance
either. SSM into the box showed spored v0.81.0 running but:

    Config: TTL=0s, IdleTimeout=0s
    Could not load config from tags: UnauthorizedOperation ec2:DescribeTags

The scoped IAM profile task run creates (via IAMRoleConfig.InlinePolicyJSON for
per-task S3 access) REPLACED the default spored role entirely — and the
InlinePolicyJSON path bypasses buildInlinePolicy, which is the only place that
always prepends spored's EC2 self-management grants. With no ec2:DescribeTags,
spored can't read spawn:ttl / spawn:on-complete, so on_complete never fires and
TTL isn't enforced in-instance (only the reaper backstops it).

Fix: extract the spored self-management statements into
sporedSelfManagementStatements() + sporedBaselinePolicyDoc(), and attach that
baseline as a second inline policy whenever InlinePolicyJSON is set (create +
update paths). Also tag the completion file explicitly in task run. Verified
end-to-end on real AWS: task instance self-terminated ~4min after completion,
leak-check clean.

Closes #406
@codecov

codecov Bot commented Jul 19, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 64.81481% with 19 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
pkg/aws/iam.go 56.81% 17 Missing and 2 partials ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit aaae47d into main Jul 19, 2026
7 checks passed
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.

task run: confirm on_complete=terminate fires (spored version + completion-file) — TTL is currently the only guaranteed teardown

1 participant