Repository navigation
Merged
Conversation
scttfrdmn
force-pushed
the
fix/985
branch
2 times, most recently
from
October 17, 2026 02:23
6af2590 to
d882083
Compare
…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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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):CreateTagslimited to instances whose Spot request is spawn-tagged. Not expressible.CreateTagsandTerminateInstanceson an instance evaluate only theinstanceresource's keys:aws:/ec2:ResourceTag,ec2:InstanceID,ec2:InstanceProfile,ec2:InstanceMarketType,ec2:InstanceTypeand similar. None of them names the Spot request, andaws:ResourceTagthere means the instance's own tags. Thespot-instances-requestresource has only tag and region keys. There is noec2:SpotInstanceRequest…key. IAM evaluates each resource in a call on its own terms, so putting the request's ARN in the sameCreateTagscall cannot make the instance's authorisation depend on the request's tags.ec2:InstanceIDonly matches ids written into the policy in advance, so the only way to scope it would be editing IAM at runtime.ec2:InstanceProfileplusec2:InstanceMarketType=spot. IAM evaluates both keys, but nobody has shown EC2 populates them forTerminateInstances. 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.No
TerminateInstancesgrant changes. Every one stays conditioned onspawn:managed=true, and #991's gate holds both YAML copies to that.What changes
SPOT REPLACEMENT NOT TERMINATEDis still one log line, so the metric filter counts it once. It now gives:self);describe-instancescheck that must print the request id, then theterminate-instancescommand.continuebeforenotifySpot, soREAPER_NOTIFY_URLheard 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.pkg/reaperiam,failures.go, the README and the CHANGELOG.Evidence
Three new tests in
lambda/ttl-reaper/spotrequests_test.go:TestSpotSweep_StrandedReplacementMessageIsActionableTestSpotSweep_StrandedTransientFailureSaysItRetriesTestSpotSweep_StrandedReplacementIsNotifiedOnce(uses httptest)All pass. I watched them fail against each of these reverts, all of which compile:
spotrequests.go: all three fail;if true): the notify-once test fails with "re-notified (2 posts)";Other checks:
make check-nestedpasses, as dogo test ./pkg/reaperiam/ .andsam validate --lint.golangci-lintinlambda/ttl-reaperreports 3 errcheck findings infailures_test.go. They are identical without this change; that file is not touched here.Deploy (not done; no AWS touched)
make deployinlambda/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.