Skip to content

feat(secretsmanager): RotateSecret's parameters, VersionId and refusals (#952) - #958

Merged
scttfrdmn merged 1 commit into
mainfrom
feat/rotate-secret-parameters
Sep 17, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
feat/rotate-secret-parameters

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

RotateSecret read one of its seven request parameters, omitted the response member all four of AWS's samples return, and refused nothing. That was worse than a thin response: the handler set RotationEnabled = true on any secret it could load, so DescribeSecret reported rotation configured for a secret with no rotation function — the one state AWS refuses to create. A consumer's nominal path was substrate's nominal path and its error path was unreachable.

What ships

The configuration is recorded and reported. RotationLambdaARN and RotationRules are stored on the secret and emitted by DescribeSecret, keeping #930's omit-versus-null tiers intact. RotationRules is one of the four members AWS documents an omission for — "if the secret never had rotation turned on, this field is omitted" — so it is absent until a schedule is configured, and SecretState.RotationRules is a pointer to keep never-configured distinguishable from empty. RotationLambdaARN carries no per-member statement, so its omission rests on the blanket "Secrets Manager only returns fields that have a value in the response" and is substrate's reading. The two fall in different tiers, which is why they are emitted by different conditions.

VersionId is derived, not minted. All four examples say the same sentence — "The ClientRequestToken field becomes the VersionId of the new version created during the rotation" — and all four sample responses return the token. So the value is reproducible on replay by construction rather than by a determinism mechanism, and it is not a second entry in #856's inventory. No version payload is written for it: producing the new secret value is the rotation function's job, and none runs here.

Two of InvalidRequestException's three published causes are refused, with the message naming which applies, since one code covers three unrelated conditions. The first, "the secret is scheduled for deletion", became decidable when #953 modelled the recovery window. The second is decided from the record and the request together — "if you don't include the configuration parameters, the operation starts a rotation with the values already stored in the secret" — so a bare call is refused on a fresh secret and succeeds on one already configured. RotationLambdaARN's published length minimum is 0, so an explicit "" is not naming an ARN and is refused too. The third cause needs OwningService, which substrate models nothing of, so it is not refused — recorded rather than left silent, and that same absence is why the refusal is unconditional: a managed-rotation secret legitimately has no ARN ("for secrets that use managed rotation, omit this field") but is an OwningService secret, and none can exist here. No refusal writes state — the half of the defect a status-only assertion misses.

RotationRules refuses the mutual exclusion AWS states ("you can set the rotation schedule in RotationRules with AutomaticallyAfterDays or ScheduleExpression, but not both") and an AutomaticallyAfterDays outside 1–1000. The code for both is substrate's reading: AWS publishes none for the violation, and InvalidParameterException is the one it publishes on this operation that fits.

AWS::SecretsManager::RotationSchedule passes the configuration through. Without it, every rotation-schedule resource would have failed under the refusal above — deploySecretRotationSchedule reports a routing refusal by setting DeployedResource.Error, so the failure is per-resource and takes the stack into rollback. That is why it ships here rather than after. The ClientRequestToken is derived from the account, Region, stack name and logical ID, so a redeploy sends the same token. A HostedRotationLambda's RotationLambdaName is composed into a function ARN in the deploying account and Region — substrate's reading, and the narrowest available, since CloudFormation would create that function through a nested stack and nothing exists at that ARN here.

Substrate's reading, stated as such

An omitted ClientRequestToken is refused with InvalidParameterException/400. The parameter is "Required: No" because "the CLI or SDK generates a random UUID for you", but the page is explicit about the caller substrate actually is: "if you generate a raw HTTP request to the Secrets Manager service endpoint, then you must generate a ClientRequestToken and include it in the request." The two alternatives are worse — minting one puts a nondeterministic value in a response body, which is #856's whole defect class, and echoing an empty one answers a VersionId of "" where AWS publishes a minimum length of 32.

Recorded rather than enforced

The length constraints on ClientRequestToken (32–64) and RotationLambdaARN (≤2048), and the patterns on Duration ([0-9]+h) and ScheduleExpression. Substrate does not validate lengths or patterns as a rule, and enforcing them at this one operation would refuse a token every sibling operation accepts. ExternalSecretRotationRoleArn and ExternalSecretRotationMetadata are decoded by nothing, because they belong to the managed-external-secret integration substrate models no part of — recording them would put values in state no operation could report. RotateImmediately is recorded and reported by nothing, which is not an omission: no function runs, so the true/false difference has no observable API member, but the state snapshot is itself an observable under replay and time-travel inspection.

Tests

Thirteen new tests in emulator/secretsmanager_rotation_test.go, including two that deploy an AWS::SecretsManager::RotationSchedule over the wire and read the result back through DescribeSecret, one asserting the interval schedule is reported as a JSON number, and one asserting a refusal against the state it did not write.

Four existing tests changed and each says why: TestSMPlugin_RotateSecret and TestSMDescribeMembers_RotationEnabledIsNullUntilRotationIsRequested now supply a token and a function ARN; the smSecretIDOperations RotateSecret row supplies a token, since the token is validated before the identifier (which its own case pins); and TestCFN_SecretRotationSchedule gained a RotationLambdaARN plus an assertion that no deployed resource carries an Error — without which it would have kept passing on a failed resource. RotationLambdaARN and RotationRules left TestSMDescribeMembers_TheUnmodeledPublishedMembersStayAbsent's list, their conditional presence now being asserted where a test can rotate and re-describe.

Three lines in the diff are uncovered and structurally unreachable through the test server: two StateManager error returns (MemoryStateManager's Get and Put never error) and a json.Marshal of a map of strings, bools and an int64.

Coverage: 84.4% emulator / 83.9% total, both above the 84.3%/83.8% baseline.

Closes #952.

…ls (#952)

RotateSecret read one of its seven request parameters, omitted the response
member all four of AWS's samples return, and refused nothing. That was worse
than a thin response: the handler set RotationEnabled = true on any secret it
could load, so DescribeSecret reported rotation configured for a secret with no
rotation function — the one state AWS refuses to create. A consumer's nominal
path was substrate's nominal path and its error path was unreachable.

RotationLambdaARN and RotationRules are recorded on the secret and reported by
DescribeSecret, keeping #930's omit-versus-null tiers intact: RotationRules is
one of the four members AWS documents an omission for ("if the secret never had
rotation turned on, this field is omitted"), so it is absent until a schedule is
configured and SecretState.RotationRules is a pointer to keep never-configured
distinguishable from empty; RotationLambdaARN carries no per-member statement,
so its omission rests on the blanket sentence and is substrate's reading.

The response carries VersionId, echoing the request's ClientRequestToken — "the
ClientRequestToken field becomes the VersionId of the new version created during
the rotation", stated in all four examples and returned by all four sample
responses. The value is therefore reproducible on replay by construction rather
than by a determinism mechanism. No version payload is written for it: producing
the new secret value is the rotation function's job, and none runs here.

Two of InvalidRequestException's three published causes are refused, with the
message naming which applies. The first, "the secret is scheduled for deletion",
became decidable when #953 modelled the recovery window. The second is decided
from the record and the request together, so a bare call is refused on a fresh
secret and succeeds on one already configured. RotationLambdaARN's published
length minimum is 0, so an explicit "" is not naming an ARN and is refused too.
The third cause needs OwningService, which substrate models nothing of, so it is
not refused — recorded rather than left silent, and that same absence is why the
refusal is unconditional: a managed-rotation secret legitimately has no ARN but
is an OwningService secret, and none can exist here. No refusal writes state.

An omitted ClientRequestToken is refused with InvalidParameterException/400,
which is substrate's reading. The parameter is "Required: No" because the CLI or
SDK generates a UUID, but the page is explicit about the caller substrate is:
"if you generate a raw HTTP request to the Secrets Manager service endpoint,
then you must generate a ClientRequestToken and include it in the request."
Minting one would put a nondeterministic value in a response body (#856) and
echoing an empty one would answer a VersionId of "" where AWS publishes a
minimum length of 32.

AWS::SecretsManager::RotationSchedule passes RotationLambdaARN, RotationRules
and RotateImmediatelyOnUpdate through, with a ClientRequestToken derived from
the account, Region, stack name and logical ID so a redeploy sends the same
token. A HostedRotationLambda's RotationLambdaName is composed into a function
ARN in the deploying account and Region — substrate's reading, and the narrowest
available, since CloudFormation would create that function through a nested
stack. Without the pass-through every rotation-schedule resource would have
failed under the refusal above, which is why it ships here rather than after.

Recorded rather than enforced: the length constraints on ClientRequestToken
(32-64) and RotationLambdaARN (<=2048), and the patterns on Duration and
ScheduleExpression. Substrate does not validate lengths or patterns as a rule,
and enforcing them at this one operation would refuse a token every sibling
accepts. RotateImmediately is recorded and reported by nothing, which is not an
omission — no function runs, so the true/false difference has no observable API
member — but the state snapshot is itself an observable under replay and
time-travel inspection, so the intent survives the request.

Four existing tests changed and each says why: TestSMPlugin_RotateSecret and
TestSMDescribeMembers_RotationEnabledIsNullUntilRotationIsRequested now supply a
token and a function ARN, the smSecretIDOperations RotateSecret row supplies a
token (it validates the token before the identifier, which its own case pins),
and TestCFN_SecretRotationSchedule gained a RotationLambdaARN plus the assertion
that no deployed resource carries an Error — without which it would have kept
passing on a failed resource. RotationLambdaARN and RotationRules left
TestSMDescribeMembers_TheUnmodeledPublishedMembersStayAbsent's list, their
conditional presence now being asserted where a test can rotate and re-describe.

Three lines in the diff are uncovered and structurally unreachable through the
test server: two StateManager error returns (MemoryStateManager's Get and Put
never error) and a json.Marshal of a map of strings, bools and an int64.

Closes #952.
@codecov

codecov Bot commented Sep 17, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.01980% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/secretsmanager_rotation.go 97.22% 2 Missing ⚠️

📢 Thoughts on this report? Let us know!

@scttfrdmn
scttfrdmn merged commit e24ac93 into main Sep 17, 2026
17 checks passed
@scttfrdmn
scttfrdmn deleted the feat/rotate-secret-parameters branch September 17, 2026 00:57
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: RotateSecret omits VersionId, discards six parameters, and answers 200 where AWS publishes InvalidRequestException

1 participant