Skip to content

Termination protection is recorded and reported but TerminateInstances does not honour it #489

Closed

Description

@scttfrdmn

What

#473 added disableApiTermination to DescribeInstanceAttribute and made
ModifyInstanceAttribute write it, so termination protection is now recorded at launch
(RunInstances' DisableApiTermination), modifiable, and readable back.

It is not acted on. TerminateInstances terminates a protected instance and
reports success.

Real EC2 refuses:

OperationNotPermitted: The instance 'i-0123456789abcdef0' may not be terminated.
Modify its 'disableApiTermination' instance attribute and try again.

Why it matters

This is the tracker's recurring shape: substrate returns success where real AWS
refuses
, so a consumer's error branch is unreachable and their suite reports green
while verifying nothing.

It is worse than the usual instance of that, because the whole point of termination
protection is to be a guard rail. A test that asserts "my teardown script does not
destroy the protected instance" passes against substrate today and against a code
path that ignores protection entirely — the assertion cannot fail. Someone verifying
that guard rail before it protects real infrastructure gets no signal at all.

Scope

  • TerminateInstances refuses an instance with DisableAPITermination set, with
    OperationNotPermitted, HTTP 400.
  • Per-instance, not per-request. TerminateInstances takes InstanceId.N. Worth
    checking against the reference whether a request naming one protected and one
    unprotected instance terminates the unprotected one or refuses whole — the answer
    determines whether this is a pre-flight check or a per-item outcome, and getting it
    backwards is the same class of defect in the other direction.
  • DeleteFleets(TerminateInstances=true) and the instant-fleet teardown path reach
    the same code, so decide and document what happens to a protected fleet instance.
  • The message above needs its provenance checked before shipping — it is from memory of
    the console/CLI wording, not a verified capture. Per Error message text is substrate-shaped rather than AWS-shaped across ~650 AWSError literals #487, either find a capture or a
    parity-tested reimplementation, or ship substrate's own text and say so in the
    comment.

Acceptance criteria

  • TerminateInstances on a protected instance returns OperationNotPermitted, 400,
    and the instance stays running.
  • Clearing protection via ModifyInstanceAttribute(DisableApiTermination.Value=false)
    then terminating succeeds — the sequence a consumer's teardown actually performs.
  • The mixed-request behaviour matches the reference, whichever way it goes, with the
    citation in the code comment.
  • The fleet teardown path's behaviour is decided, tested, and documented in
    docs/services.md.
  • docs/services.md's instance-attributes section drops the "recorded and reported
    but not acted on" caveat.

Noted as tracked separately in emulator/ec2_types.go's DisableAPITermination comment
and in docs/services.md, both added by #473.

Activity

  1. added this to the v0.87.0 milestone on Aug 2, 2026
  2. scttfrdmn commented on Aug 2, 2026

    @scttfrdmn
    OwnerAuthor

    Fixed in b502c5f (#504), shipping in v0.87.0. Your framing was right about the defect and about the risk, and the mixed-request answer is neither of your two guesses.

    Partial failure is Availability-Zone-scoped. You asked whether a mixed request refuses whole or terminates the unprotected instance, and noted that getting it backwards is the same defect in the other direction. There were three answers, not two. From TerminateInstances:

    The specified instances that are in the same Availability Zone as the protected instance are not terminated. The specified instances that are in different Availability Zones, where no other specified instances are protected, are successfully terminated.

    The reference then works a four-instance example. So substrate now groups the requested instances by AZ; any AZ containing a protected instance terminates none of its instances, other AZs proceed, and the request reports OperationNotPermitted (400) naming the protected instance — after persisting the terminations in the unaffected zones. That ordering is the behaviour, not an implementation detail, and it is the natural thing to get wrong. The grouping is one testable function (ec2TerminationProtectionBlocked) rather than control flow inside the handler, and the AZ table in the test suite is modelled on the reference's own example. It fails under both of the behaviours you guessed at.

    Your existing observation that a single bad instance ID fails the whole request is also documented ("If you specify multiple instances and the request fails … none of the instances are terminated") and substrate already did that via ec2RequireResource; the protection scan runs as a second pre-flight pass so no state is written for a doomed zone.

    Your provenance caution was warranted, and in both directions. OperationNotPermitted turns out to have stronger backing than you expected — the EC2 client-error table names termination protection explicitly: "you might be trying to terminate an instance that has termination protection enabled." So the code is a doc citation. The message is not: you flagged your wording as from memory rather than a capture, nothing corroborates it, so substrate ships its own text interpolating the instance ID, labelled as substrate's in the comment per docs/fidelity.md's policy. Your remembered wording is not dressed up as observed.

    The fleet path is now decided rather than inherited. deleteFleets synthesizes a TerminateInstances request through the same handler, so protection applied for free — but "for free" is not the same as "correct," so it is asserted: a protected fleet instance survives DeleteFleets --terminate-instances exactly as it survives a direct terminate, an unprotected sibling in another zone does not, and DeleteFleets propagates the OperationNotPermitted rather than folding it into unsuccessfulFleetDeletionSet. That last part is a real choice: DeleteFleetError's documented codes are exactly fleetIdDoesNotExist, fleetIdMalformed, fleetNotInDeletableState and unexpectedError, none of which covers termination protection — folding it in would mean answering unexpectedError and losing the code the caller acts on.

    Both your acceptance criteria are covered, including the second one, which is the sequence a teardown actually performs: ModifyInstanceAttribute(DisableApiTermination.Value=false) then terminate → succeeds. Protection set at launch via RunInstances --disable-api-termination is honoured too, not just protection set by modify. And terminating an already-terminated instance still succeeds, since the reference calls the operation idempotent and the new check must not break that.

    Your point about the test that cannot fail is the sharpest instance of this defect shape in the tracker's history, and worth restating for anyone reading later: a consumer asserting "my teardown does not destroy the protected instance" passed against a code path that ignored protection entirely, so the assertion could not fail. That is worse than a missing feature.

    One divergence remains, deliberately out of scope here: substrate reported 48 terminated immediately where real EC2 reports 32 shutting-down first. Widening this PR into a lifecycle change would have put your gate at risk. It turns out to be broader than terminate — pending and stopping are equally unobservable — and is filed as #514 with the three candidate designs.

  3. added a commit that references this issue on Aug 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: ec2fidelitytype: feature

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions