Repository navigation
feat(secretsmanager): DeleteSecret opens a recovery window, and RestoreSecret (#953) - #957
Merged
Merged
Conversation
…reSecret (#953) AWS's DeleteSecret does not delete a secret: it attaches a DeletionDate stamp 7-to-30 days out, defaulting to 30, and only at the end of that window is the secret removed. Substrate removed the record, the version payload and the index entry on every call -- the behaviour AWS reserves for ForceDeleteWithoutRecovery: true -- and decoded neither parameter that chooses between them. So the destructive variant was the only variant, RestoreSecret had nothing to restore, and a scheduled secret and a secret that never existed were the same observation. DeleteSecret now reads both parameters, refuses a window outside 7-30 and refuses both parameters in one call (on their presence, which is substrate's reading of "use both"), stamps DeletionDate off the simulated clock, and answers 200 for a forced delete of an absent secret per AWS's explicit sentence. GetSecretValue refuses a scheduled secret with InvalidRequestException/400, distinguishable from ResourceNotFoundException. DescribeSecret reports DeletedDate while the window is open. RestoreSecret clears the stamp and answers ARN and Name only. The permanent deletion at the end of the window is deliberately not modeled: AWS publishes no guarantee to model.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
…ebuild paths Three cases codecov flagged as uncovered diff lines, each asserting something the twelve existing cases could not: - an identifier that resolves to no secret is refused before either handler reads state, including under ForceDeleteWithoutRecovery — AWS suspends ResourceNotFoundException for a nonexistent *secret*, not for an identifier that names none, so a typo is not swallowed into a 200; - a forced delete removes one index entry rather than the index, which a single-secret test cannot distinguish; - a body that is not an object is refused, recording the code every Secrets Manager handler answers today with #950's audit named. Patch coverage 86.67% -> 91.4%; the nine lines still uncovered are StateManager error returns MemoryStateManager never produces.
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.
AWS's
DeleteSecretdoes not delete a secret. It "attaches aDeletionDatestamp to the secret that specifies the end of the recovery window" — 7 to 30 days out, defaulting to 30 — and only "at the end of the recovery window" is the secret removed.Substrate removed the record, the current version payload and the index entry on every call, which is the one behaviour AWS reserves for
ForceDeleteWithoutRecovery: true, and decoded neither of the two parameters that choose between them. Three things followed:RestoreSecretwas not implemented, and would have had nothing to restore;ResourceNotFoundException, so a caller's error handling could not tell "restore this" from "this was never here".What now happens
DeleteSecret, neither parameter200,DeletionDate30 days out; still listed, still describedDeleteSecret,RecoveryWindowInDays7–30200,DeletionDatethat many days outDeleteSecret, window outside 7–30InvalidParameterException/400, nothing writtenDeleteSecret, both parameters presentInvalidParameterException/400, nothing writtenDeleteSecretunforced, already scheduledInvalidRequestException/400 naming the scheduled-for-deletion causeDeleteSecret,ForceDeleteWithoutRecovery: true200; record, version payload and index entry removedDeleteSecretforced, absent or already deleted200GetSecretValueon a scheduled secretInvalidRequestException/400 — distinguishable fromResourceNotFoundExceptionDescribeSecreton a scheduled secret200carryingDeletedDate; the member is absent otherwiseRestoreSecret200withARNandNameonly; stamp cleared, value readable againProvenance, per decision rather than blanket
AWS's, quoted from
API_DeleteSecret,API_RestoreSecretandAPI_GetSecretValue: the 7–30 range and the 30-day default;DeletionDate= "the date and time of the delete request plus the number of days inRecoveryWindowInDays"; the{ARN, DeletionDate, Name}and{ARN, Name}response shapes; "when a secret is scheduled for deletion, you cannot retrieve the secret value";InvalidRequestException's three published causes, of which the first is "the secret is scheduled for deletion"; the mutual exclusion of the two parameters; the200for a forced delete of an absent secret; and every status —ResourceNotFoundExceptionis400here, per #930.Substrate's reading, and each is stated as such in the code, in
docs/services.mdand inCHANGELOG.md:ForceDeleteWithoutRecovery: falsebeside a window is refused too. AWS states the rule over use — "you can't use both this parameter andForceDeleteWithoutRecoveryin the same call" — and the alternative makes an explicitfalsemean the same as an omission, silently opening a 30-day window for a caller who asked for an immediate delete. That is the more damaging direction to guess in.ResourceNotFoundExceptionwithout publishing what is answered instead, so substrate reports the ARN the identifier names, the name, and aDeletionDateat the request.DeletionDateat all. The member is published unconditionally and no separate forced-delete response is published; a zero window puts the same derivation at the request itself.API_RestoreSecret's cause list names only the three service-wide conditions, none of which is "not scheduled", so there is no published code to refuse with — and inventing one would make an idempotent restore fail here and succeed against AWS.The permanent deletion is deliberately not modelled
#953's last criterion asked for one of two things, stated. This takes the second: AWS publishes no guarantee to model. "There is no guarantee of a specific time after the recovery window for the permanent delete to occur." So a secret whose
DeletionDatehas passed is still listed, still stamped, still withholding its value and still restorable — asserted byTestSMDeletion_ASecretIsStillReportedAfterItsWindowHasPassed, which advances the simulated clock 30 days past a 7-day window and checks all four. A test asserting the secret had vanished at some simulated instant would assert something AWS explicitly declines to promise.The CloudFormation deleter was already correct and had no effect
cfn_delete.go'sAWS::SecretsManager::Secretarm has always sentForceDeleteWithoutRecovery: true, with the citation "the default behavior of CloudFormation is to delete the secret with theForceDeleteWithoutRecoveryflag — so a recreated stack does not collide with a secret still in its recovery window." Nothing decoded the parameter, so that comment described the tree's behaviour only by coincidence. It describes it truthfully as of this PR, and a stack teardown keeps removing its secrets.Tests
emulator/secretsmanager_deletion_test.go, twelve cases, every call over the wire and every secret created throughCreateSecret(#765's standing rule). Two assertion styles that no existing test could make:DeletedDate's presence and absence on the raw bytes, per fix(secretsmanager): ResourceNotFoundException is 400, not 404, and DescribeSecret emits members AWS omits #930's precedent — absent on a live secret, present when scheduled, absent again after a restore. A decoded struct collapses an absent member into a zero-valued one, which is the whole distinction.TestSMDeletion_AScheduledSecretIsRefusedDifferentlyFromAnAbsentOnechecksInvalidRequestExceptionandResourceNotFoundExceptionin one case, because either alone would have passed against the old handler.The simulated clock is pinned with
SetTimeimmediately before each delete, so aDeletionDateis compared against a known baseline. The five-second tolerance covers the wall-clock microsecondsTimeController.Nowadds at scale 1.0 — nothing depends on what the wall clock reads, and five seconds cannot mask a wrong day count.Two existing tests changed, both deliberately
TestSMPlugin_DeleteSecretandTestSMResolution_DeleteSecretRemovesTheOwningRegionsIndexEntry(#928) each asserted that a plainDeleteSecretremoved something. Both now passForceDeleteWithoutRecovery: true, which is the call whose behaviour they were actually about; #928's subject is which Region's index entry a removal takes out, and that assertion is unchanged. The comments say why.Compatibility
A
DeleteSecretthat removed the secret now schedules it. A caller who wants the old behaviour must passForceDeleteWithoutRecovery: true. After a plain delete,ListSecretsstill reports the secret,DescribeSecretstill answers200(now withDeletedDate), andGetSecretValueanswersInvalidRequestExceptionrather thanResourceNotFoundException.Filed, not fixed here
PutSecretValue,UpdateSecret,TagResourceandUntagResourcestill accept a scheduled secret although their pages publish the same cause — #956, filed with the helper this PR adds already in place. They were split out rather than bundled becauseGetSecretValue's refusal is stated in AWS's prose as well as its error list and is what makes the scheduled state observable at all, whereas those four rest on the published cause list alone.Closes #953.