Repository navigation
feat(secretsmanager): RotateSecret's parameters, VersionId and refusals (#952) - #958
Merged
Merged
Conversation
…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 Report❌ Patch coverage is
📢 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.
RotateSecretread 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 setRotationEnabled = trueon any secret it could load, soDescribeSecretreported 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.
RotationLambdaARNandRotationRulesare stored on the secret and emitted byDescribeSecret, keeping #930's omit-versus-null tiers intact.RotationRulesis 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, andSecretState.RotationRulesis a pointer to keep never-configured distinguishable from empty.RotationLambdaARNcarries 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.VersionIdis derived, not minted. All four examples say the same sentence — "TheClientRequestTokenfield becomes theVersionIdof 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 needsOwningService, 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 anOwningServicesecret, and none can exist here. No refusal writes state — the half of the defect a status-only assertion misses.RotationRulesrefuses the mutual exclusion AWS states ("you can set the rotation schedule inRotationRuleswithAutomaticallyAfterDaysorScheduleExpression, but not both") and anAutomaticallyAfterDaysoutside 1–1000. The code for both is substrate's reading: AWS publishes none for the violation, andInvalidParameterExceptionis the one it publishes on this operation that fits.AWS::SecretsManager::RotationSchedulepasses the configuration through. Without it, every rotation-schedule resource would have failed under the refusal above —deploySecretRotationSchedulereports a routing refusal by settingDeployedResource.Error, so the failure is per-resource and takes the stack into rollback. That is why it ships here rather than after. TheClientRequestTokenis derived from the account, Region, stack name and logical ID, so a redeploy sends the same token. AHostedRotationLambda'sRotationLambdaNameis 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
ClientRequestTokenis refused withInvalidParameterException/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 aClientRequestTokenand 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 aVersionIdof""where AWS publishes a minimum length of 32.Recorded rather than enforced
The length constraints on
ClientRequestToken(32–64) andRotationLambdaARN(≤2048), and the patterns onDuration([0-9]+h) andScheduleExpression. 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.ExternalSecretRotationRoleArnandExternalSecretRotationMetadataare 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.RotateImmediatelyis 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 anAWS::SecretsManager::RotationScheduleover the wire and read the result back throughDescribeSecret, 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_RotateSecretandTestSMDescribeMembers_RotationEnabledIsNullUntilRotationIsRequestednow supply a token and a function ARN; thesmSecretIDOperationsRotateSecretrow supplies a token, since the token is validated before the identifier (which its own case pins); andTestCFN_SecretRotationSchedulegained aRotationLambdaARNplus an assertion that no deployed resource carries anError— without which it would have kept passing on a failed resource.RotationLambdaARNandRotationRulesleftTestSMDescribeMembers_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
StateManagererror returns (MemoryStateManager'sGetandPutnever error) and ajson.Marshalof a map of strings, bools and anint64.Coverage: 84.4% emulator / 83.9% total, both above the 84.3%/83.8% baseline.
Closes #952.