Skip to content

Make the stranded Spot replacement alarm actionable; record why the reaper cannot end it (#984) - #996

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/984
Oct 17, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/984

Conversation

@scttfrdmn

Copy link
Copy Markdown
Contributor

Fixes #984

Stacked on #991, which is stacked on #981 → #961 → #951. Merge after those.

Decision: keep the alarm and make it actionable

None of the options lets the reaper safely end an untagged replacement without a person. I checked the IAM condition keys against the machine-readable Service Authorization Reference (servicereference.us-east-1.amazonaws.com/v1/ec2/ec2.json):

  • Have the reaper tag the replacement, with CreateTags limited to instances whose Spot request is spawn-tagged. Not expressible. CreateTags and TerminateInstances on an instance evaluate only the instance resource's keys: aws:/ec2:ResourceTag, ec2:InstanceID, ec2:InstanceProfile, ec2:InstanceMarketType, ec2:InstanceType and similar. None of them names the Spot request, and aws:ResourceTag there means the instance's own tags. The spot-instances-request resource has only tag and region keys. There is no ec2:SpotInstanceRequest… key. IAM evaluates each resource in a call on its own terms, so putting the request's ARN in the same CreateTags call cannot make the instance's authorisation depend on the request's tags.
  • Cancel the request, then terminate by the request's instance id under a narrow statement. Also not expressible. ec2:InstanceID only matches ids written into the policy in advance, so the only way to scope it would be editing IAM at runtime.
  • ec2:InstanceProfile plus ec2:InstanceMarketType=spot. IAM evaluates both keys, but nobody has shown EC2 populates them for TerminateInstances. The issue requires a simulator run and a live check first (REAPER_GRACEFUL cannot work cross-account: the spawn-ttl-reaper-ec2 role grants no ssm: actions #652/fix(reaper): ssm:SendCommand needs ssm:resourceTag, not ec2:ResourceTag #665), and the resulting rule, "any untagged Spot instance with a spawn instance profile", is broader than spawn's own instances. Not shipped.
  • spored in the replacement ends itself. This is plausible and needs no new IAM, but it depends on behaviour nobody has verified live (whether the replacement runs the user-data, gets the instance profile, and terminates rather than stops on an OS shutdown). Filed as Live-verify a way to end an untagged Spot replacement without a person (follow-up to #984) #995 together with the instance-profile option.

No TerminateInstances grant changes. Every one stays conditioned on spawn:managed=true, and #991's gate holds both YAML copies to that.

What changes

  • SPOT REPLACEMENT NOT TERMINATED is still one log line, so the metric filter counts it once. It now gives:
  • Notification bug fixed. The stranded path hit continue before notifySpot, so REAPER_NOTIFY_URL heard nothing of either the cancel or the instance. It now posts the line once, on the run that cancels the request. Later runs repeat only the log line and the alarm.
  • The alarm description says which log group to filter, for what, and what to run.
  • Comments and docs: the IAM finding is recorded in pkg/reaperiam, failures.go, the README and the CHANGELOG.

Evidence

Three new tests in lambda/ttl-reaper/spotrequests_test.go:

  • TestSpotSweep_StrandedReplacementMessageIsActionable
  • TestSpotSweep_StrandedTransientFailureSaysItRetries
  • TestSpotSweep_StrandedReplacementIsNotifiedOnce (uses httptest)

All pass. I watched them fail against each of these reverts, all of which compile:

  • the previous spotrequests.go: all three fail;
  • notifying on every run (if true): the notify-once test fails with "re-notified (2 posts)";
  • the transient-error branch removed: the retries test fails.

Other checks:

  • make check-nested passes, as do go test ./pkg/reaperiam/ . and sam validate --lint.
  • golangci-lint in lambda/ttl-reaper reports 3 errcheck findings in failures_test.go. They are identical without this change; that file is not touched here.

Deploy (not done; no AWS touched)

make deploy in lambda/ttl-reaper, which reads the live stack parameters first. That ships the new log line, the notification and the alarm description. No IAM changes, and the cross-account role stacks are untouched.

…eaper cannot end it (#984)

untagged replacement launched by a leaked persistent Spot request. Checked
against the IAM Service Authorization Reference (servicereference ec2.json):
TerminateInstances and CreateTags on an instance evaluate only the instance
resource's keys (aws:/ec2:ResourceTag, ec2:InstanceProfile,
ec2:InstanceMarketType, ...). None names the Spot request, and
aws:ResourceTag there is the instance's tags. The spot-instances-request
resource has only tag and region keys. So no grant can be limited to
"instances a spawn-tagged request launched". ec2:InstanceProfile +
ec2:InstanceMarketType is evaluable but unverified as populated, and it is
broader than spawn's instances. The issue requires a simulator and a live
check first, so it is not shipped. Nothing safe works without a person, so
the alarm stays and becomes actionable:

- SPOT REPLACEMENT NOT TERMINATED is one line that names the 12-digit account
  (not "self"), the instance's type/state/launch time and its original. It
  says why the reaper could not act, distinguishing a denial from a
  transient error. It gives a describe-instances check that must print the
  request id, then the terminate-instances command.
- It is posted to REAPER_NOTIFY_URL once, on the run that cancels the
  request. Before, the stranded path `continue`d past notifySpot, so the
  webhook heard nothing of the cancel or the instance.
- The alarm description says where to look and what to run. Comments in
  reaperiam, failures.go and the README record the IAM finding.

(#984)
@codecov

codecov Bot commented Oct 17, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit 3a51c77 into main Oct 17, 2026
8 checks passed
@scttfrdmn
scttfrdmn deleted the fix/984 branch October 17, 2026 02:57
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.

TTL reaper cannot terminate an untagged replacement launched by a leaked persistent Spot request

1 participant