feat(secretsmanager): implement automatic secret rotation lifecycle (#1467)

* fix: return XML error for missing action and add volume action fallbacks

* fix(eventbridge): sync EventBridge tags to ResourceGroupsTaggingService

EventBridge stored tags on rules, buses, and archives in its own stores but never propagated them to the central ResourceGroupsTaggingService. This caused GetResources with --resource-type-filters events:rule to return an empty list.

Inject ResourceGroupsTaggingService into EventBridgeService (following the existing GlueService pattern) and sync tags during putRule, tagResource, untagResource, and deleteRule operations.

Closes #1343

* feat(secretsmanager): implement automatic secret rotation lifecycle

* fix(secretsmanager): correct RotationLambdaARN validation in tests and rotation rules parsing

* fix(secretsmanager): avoid implicit unboxing NPE when parsing rotation rules

* fix: remove debug print, drop camelCase rotation parameters fallback, and revert unrelated eventbridge changes

* fix: align PutSecretValue error code and resolve NPE in JSON handler tests

* fix(test): create Lambda function before rotateSecret to fix ResourceNotFoundException

rotateSecretStub failed because SecretsManagerService validates the
rotation Lambda exists synchronously. The test was passing an ARN for a
function that had never been created in the emulator.

Create a real Lambda function via LambdaClient before calling
rotateSecret, and clean it up afterwards. Uses
Runtime.fromValue(nodejs20.x) for SDK compatibility.

* fix: non-immediate rotation runs testSecret only

Per AWS RotateSecret docs, when RotateImmediately is false Secrets
Manager tests the rotation configuration by running only the testSecret
step. Remove the createSecret invocation from the non-immediate path.

* fix(test): align rotateSecretNotImmediate with non-immediate rotation path

The non-immediate rotation path only invokes testSecret (not createSecret),
so the test should expect 1 lambda invocation instead of 2.
This commit is contained in:
Konda Balaji Rao authored and GitHub committed 2026-06-22 23:18:16 -05:00
1 parent 2301db53c7
commit f725a38969
7 files changed
+723 -54

No files matched your search

@@ -1,6 +1,12 @@
package com.floci.test;
import org.junit.jupiter.api.*;
import software.amazon.awssdk.core.SdkBytes;
import software.amazon.awssdk.services.lambda.LambdaClient;
import software.amazon.awssdk.services.lambda.model.CreateFunctionRequest;
import software.amazon.awssdk.services.lambda.model.DeleteFunctionRequest;
import software.amazon.awssdk.services.lambda.model.FunctionCode;
import software.amazon.awssdk.services.lambda.model.Runtime;
import software.amazon.awssdk.services.secretsmanager.SecretsManagerClient;
import software.amazon.awssdk.services.secretsmanager.model.CreateSecretRequest;
import software.amazon.awssdk.services.secretsmanager.model.CreateSecretResponse;
@@ -214,19 +220,42 @@ class SecretsManagerTest {
@Test
@Order(12)
void rotateSecretStub() {
RotateSecretResponse rotateResponse = sm.rotateSecret(RotateSecretRequest.builder()
.secretId(secretName)
.rotationRules(RotationRulesType.builder().automaticallyAfterDays(30L).build())
.build());
void rotateSecretStub() throws Exception {
String lambdaName = "RotationLambda-" + System.currentTimeMillis();
try (LambdaClient lambda = TestFixtures.lambdaClient()) {
java.io.ByteArrayOutputStream baos = new java.io.ByteArrayOutputStream();
try (java.util.zip.ZipOutputStream zos = new java.util.zip.ZipOutputStream(baos)) {
zos.putNextEntry(new java.util.zip.ZipEntry("index.js"));
zos.write("exports.handler = async (event) => { return 'ok'; };".getBytes(java.nio.charset.StandardCharsets.UTF_8));
zos.closeEntry();
}
assertThat(rotateResponse.arn()).isEqualTo(secretArn);
lambda.createFunction(CreateFunctionRequest.builder()
.functionName(lambdaName)
.runtime(Runtime.fromValue("nodejs20.x"))
.role("arn:aws:iam::000000000000:role/dummy-role")
.handler("index.handler")
.code(FunctionCode.builder().zipFile(SdkBytes.fromByteArray(baos.toByteArray())).build())
.build());
DescribeSecretResponse describeResponse = sm.describeSecret(DescribeSecretRequest.builder()
.secretId(secretName)
.build());
RotateSecretResponse rotateResponse = sm.rotateSecret(RotateSecretRequest.builder()
.secretId(secretName)
.rotationLambdaARN("arn:aws:lambda:us-east-1:000000000000:function:" + lambdaName)
.rotationRules(RotationRulesType.builder().automaticallyAfterDays(30L).build())
.build());
assertThat(describeResponse.rotationEnabled()).isTrue();
assertThat(rotateResponse.arn()).isEqualTo(secretArn);
DescribeSecretResponse describeResponse = sm.describeSecret(DescribeSecretRequest.builder()
.secretId(secretName)
.build());
assertThat(describeResponse.rotationEnabled()).isTrue();
lambda.deleteFunction(DeleteFunctionRequest.builder()
.functionName(lambdaName)
.build());
}
}
@Test