Repository navigation
fix(secretsmanager): four operations accepted a secret scheduled for deletion (#956) - #959
Merged
Merged
Conversation
…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 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.
Four Secrets Manager operations accepted a secret whose deletion was already scheduled, although each of their pages publishes
InvalidRequestException/400with "The secret is scheduled for deletion." as the first of its three possible causes.PutSecretValueattached a new version and movedCurrentVersionIDonto it,UpdateSecretrewrote the description, the KMS key and the value, andTagResource/UntagResourceedited the tag list. So a consumer's "is this secret usable?" check got a200here and a400from AWS at four operations, and aRestoreSecretafterwards returned a secret carrying writes AWS would have refused.What ships
All four refuse through
smSecretScheduledForDeletion— the constructorGetSecretValueand the unforcedDeleteSecrethave used since #953 andRotateSecretsince #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 forsmSecretNotFound's nine callers. Each guard sits ahead of every write in its handler, so a refusal stores nothing.RestoreSecretis 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.
UntagResourceis 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, whereasInvalidRequestExceptionreports "a parameter value is not valid for the current state of the resource", which the stamp decides. So anUntagResourcenaming 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 indocs/services.mdand 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.goruns the whole refusal set as a table — seven rows rather than the six the issue names, because #952 addedRotateSecretbetween the filing and now — and asserts each row three ways:Description,Tags,DeletedDateand 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;ResourceNotFoundExceptionwould 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
DeleteSecretstill 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 aDeletionDateinto state directly could not show that the stampDeleteSecretwrites is the one these seven read.Coverage: 84.4% emulator / 83.9% total, unchanged.
Compatibility
Four operations that answered
200against a secret inside its recovery window now answerInvalidRequestException/400. A caller that scheduled a deletion and then wrote to the secret must callRestoreSecretfirst; the writes then land exactly as before.Closes #956.