Skip to content

feat(secretsmanager): DeleteSecret opens a recovery window, and RestoreSecret (#953) - #957

Merged
scttfrdmn merged 2 commits into
mainfrom
feat/secret-recovery-window
Sep 17, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
feat/secret-recovery-window

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

AWS's DeleteSecret does not delete a secret. It "attaches a DeletionDate stamp 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:

  • the destructive variant was the only variant, so a consumer could not test the default path at all;
  • RestoreSecret was not implemented, and would have had nothing to restore;
  • a secret scheduled for deletion and a secret that never existed were the same observation. Both answered ResourceNotFoundException, so a caller's error handling could not tell "restore this" from "this was never here".

What now happens

Call Answer
DeleteSecret, neither parameter 200, DeletionDate 30 days out; still listed, still described
DeleteSecret, RecoveryWindowInDays 7–30 200, DeletionDate that many days out
DeleteSecret, window outside 7–30 InvalidParameterException/400, nothing written
DeleteSecret, both parameters present InvalidParameterException/400, nothing written
DeleteSecret unforced, already scheduled InvalidRequestException/400 naming the scheduled-for-deletion cause
DeleteSecret, ForceDeleteWithoutRecovery: true 200; record, version payload and index entry removed
DeleteSecret forced, absent or already deleted 200
GetSecretValue on a scheduled secret InvalidRequestException/400 — distinguishable from ResourceNotFoundException
DescribeSecret on a scheduled secret 200 carrying DeletedDate; the member is absent otherwise
RestoreSecret 200 with ARN and Name only; stamp cleared, value readable again

Provenance, per decision rather than blanket

AWS's, quoted from API_DeleteSecret, API_RestoreSecret and API_GetSecretValue: the 7–30 range and the 30-day default; DeletionDate = "the date and time of the delete request plus the number of days in RecoveryWindowInDays"; 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; the 200 for a forced delete of an absent secret; and every status — ResourceNotFoundException is 400 here, per #930.

Substrate's reading, and each is stated as such in the code, in docs/services.md and in CHANGELOG.md:

  1. The mutual exclusion is refused on the parameters' presence, so ForceDeleteWithoutRecovery: false beside a window is refused too. AWS states the rule over use — "you can't use both this parameter and ForceDeleteWithoutRecovery in the same call" — and the alternative makes an explicit false mean 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.
  2. The body of a forced delete of an absent secret. AWS publishes the suspension of ResourceNotFoundException without publishing what is answered instead, so substrate reports the ARN the identifier names, the name, and a DeletionDate at the request.
  3. A forced delete reports a DeletionDate at 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.
  4. Restoring a secret that is not scheduled succeeds. 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 DeletionDate has passed is still listed, still stamped, still withholding its value and still restorable — asserted by TestSMDeletion_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's AWS::SecretsManager::Secret arm has always sent ForceDeleteWithoutRecovery: true, with the citation "the default behavior of CloudFormation is to delete the secret with the ForceDeleteWithoutRecovery flag — 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 through CreateSecret (#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.
  • The two refusals asserted side by side. TestSMDeletion_AScheduledSecretIsRefusedDifferentlyFromAnAbsentOne checks InvalidRequestException and ResourceNotFoundException in one case, because either alone would have passed against the old handler.

The simulated clock is pinned with SetTime immediately before each delete, so a DeletionDate is compared against a known baseline. The five-second tolerance covers the wall-clock microseconds TimeController.Now adds 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_DeleteSecret and TestSMResolution_DeleteSecretRemovesTheOwningRegionsIndexEntry (#928) each asserted that a plain DeleteSecret removed something. Both now pass ForceDeleteWithoutRecovery: 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 DeleteSecret that removed the secret now schedules it. A caller who wants the old behaviour must pass ForceDeleteWithoutRecovery: true. After a plain delete, ListSecrets still reports the secret, DescribeSecret still answers 200 (now with DeletedDate), and GetSecretValue answers InvalidRequestException rather than ResourceNotFoundException.

Filed, not fixed here

PutSecretValue, UpdateSecret, TagResource and UntagResource still 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 because GetSecretValue'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.

…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

codecov Bot commented Sep 17, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 91.42857% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/secretsmanager_deletion.go 90.90% 9 Missing ⚠️

📢 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.
@scttfrdmn
scttfrdmn merged commit 32c93ee into main Sep 17, 2026
17 checks passed
@scttfrdmn
scttfrdmn deleted the feat/secret-recovery-window branch September 17, 2026 00:28
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: DeleteSecret always deletes immediately, so the recovery window, DeletionDate and RestoreSecret do not exist

1 participant