Skip to content

fix(secretsmanager): four operations accepted a secret scheduled for deletion (#956) - #959

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/scheduled-secret-refusals
Sep 17, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/scheduled-secret-refusals

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Four Secrets Manager operations accepted a secret whose deletion was already scheduled, although each of their pages publishes InvalidRequestException/400 with "The secret is scheduled for deletion." as the first of its three possible causes. PutSecretValue attached a new version and moved CurrentVersionID onto it, UpdateSecret rewrote the description, the KMS key and the value, and TagResource/UntagResource edited the tag list. So a consumer's "is this secret usable?" check got a 200 here and a 400 from AWS at four operations, and a RestoreSecret afterwards returned a secret carrying writes AWS would have refused.

What ships

All four refuse through smSecretScheduledForDeletion — the constructor GetSecretValue and the unforced DeleteSecret have used since #953 and RotateSecret since #952. Seven callers, one constructor: a per-handler refusal would let two operations disagree about a state a caller can observe no other way, which is the arrangement #930 established for smSecretNotFound's nine callers. Each guard sits ahead of every write in its handler, so a refusal stores nothing.

RestoreSecret is the one operation publishing the cause that does not refuse on it, and that is not an omission: it is what clears the stamp, so refusing on the stamp would leave a scheduled secret with no way back. Clearing the stamp lifts all seven refusals at once.

Substrate's reading, stated as such

One of the four reads two AWS sentences against each other. UntagResource is documented idempotent — "if a requested tag is not attached to the secret, no error is returned and the secret metadata is unchanged" — but that sentence is about which keys are present, whereas InvalidRequestException reports "a parameter value is not valid for the current state of the resource", which the stamp decides. So an UntagResource naming no attached key is still refused on a scheduled secret. That is the one place in #956 the sentences could be read the other way, so it is asserted as its own case and recorded in docs/services.md and the CHANGELOG.

Everything else here is AWS's: the code, the status and the cause come from the four operations' own API reference pages, verified for this PR.

Tests

emulator/secretsmanager_scheduled_test.go runs the whole refusal set as a table — seven rows rather than the six the issue names, because #952 added RotateSecret between the filing and now — and asserts each row three ways:

  1. the code and the status, plus that the message names which of the three causes applies;
  2. the state the refusal did not write — Description, Tags, DeletedDate and the secret value are all read back after all seven refusals fire against one secret, since a status-only assertion would pass against a handler that refused after storing;
  3. the answer an absent secret gets instead, without which a handler answering ResourceNotFoundException would pass — precisely the collapse secretsmanager: DeleteSecret always deletes immediately, so the recovery window, DeletionDate and RestoreSecret do not exist #953 exists to undo.

Two counterweights are pinned as well: a restored secret accepts all four operations again (so the guards turn on the stamp and nothing a restore leaves behind), and a forced DeleteSecret still succeeds on a scheduled secret (so the four new refusals did not make the scheduled state a dead end).

Every call goes over the wire and every secret is created with CreateSecret, per #765 — a helper writing a DeletionDate into state directly could not show that the stamp DeleteSecret writes is the one these seven read.

Coverage: 84.4% emulator / 83.9% total, unchanged.

Compatibility

Four operations that answered 200 against a secret inside its recovery window now answer InvalidRequestException/400. A caller that scheduled a deletion and then wrote to the secret must call RestoreSecret first; the writes then land exactly as before.

Closes #956.

…deletion (#956)

Each of PutSecretValue, UpdateSecret, TagResource and UntagResource publishes
InvalidRequestException/400 with "The secret is scheduled for deletion." as the
first of its three possible causes, and all four accepted such a secret.
PutSecretValue attached a new version and moved CurrentVersionID onto it,
UpdateSecret rewrote the description, the KMS key and the value, and the two tag
operations edited the tag list. So a consumer's "is this secret usable?" check
got a 200 here and a 400 from AWS at four operations, and a RestoreSecret
afterwards returned a secret carrying writes AWS would have refused.

All four now refuse through smSecretScheduledForDeletion, the constructor
GetSecretValue and the unforced DeleteSecret have used since #953 and
RotateSecret since #952. Seven callers, one constructor: a per-handler refusal
would let two operations disagree about a state a caller can observe no other
way, which is the arrangement #930 established for smSecretNotFound's nine
callers. Each guard sits ahead of every write in its handler, so a refusal
stores nothing. RestoreSecret is the one operation publishing the cause that
does not refuse on it, and that is not an omission: it is what clears the stamp,
so refusing on the stamp would leave a scheduled secret with no way back.

One of the four reads two AWS sentences against each other, and the resolution
is substrate's. UntagResource is documented idempotent — "if a requested tag is
not attached to the secret, no error is returned and the secret metadata is
unchanged" — but that sentence is about which keys are present, whereas
InvalidRequestException reports "a parameter value is not valid for the current
state of the resource", which the stamp decides. So an UntagResource naming no
attached key is still refused on a scheduled secret, asserted as its own case.

The tests run the whole refusal set as a table, seven rows rather than the six
the issue names because #952 added RotateSecret between the filing and now, and
each row is asserted three ways: the code and status, the state the refusal did
not write, and the answer an absent secret gets instead — without that last
comparison a handler answering ResourceNotFoundException would pass, which is
exactly the collapse #953 exists to undo. Two counterweights are pinned as well:
a restored secret accepts all four again, so the guards turn on the stamp and
nothing a restore leaves behind; and a forced DeleteSecret still succeeds on a
scheduled secret, so the four new refusals did not make the state a dead end.

Coverage: 84.4% emulator / 83.9% total, unchanged.

Closes #956.
@codecov

codecov Bot commented Sep 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 8bfae9a into main Sep 17, 2026
17 checks passed
@scttfrdmn
scttfrdmn deleted the fix/scheduled-secret-refusals branch September 17, 2026 01:09
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.

secretsmanager: PutSecretValue, UpdateSecret, TagResource and UntagResource accept a secret scheduled for deletion

1 participant