mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(secretsmanager): omit RotationEnabled until rotation is configured and return LastAccessedDate (#9546)
This commit is contained in:
1 parent
f6baa65498
commit
5864600420
8 files changed
+86
-7
No files matched your search
+1
-1
@@ -164,7 +164,7 @@ class SecretsManagerTest {
|
||||
|
||||
assertThat(response.tags()).isNotEmpty();
|
||||
assertThat(response.versionIdsToStages()).hasSize(2);
|
||||
assertThat(response.rotationEnabled()).isFalse();
|
||||
assertThat(response.rotationEnabled()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -97,7 +97,7 @@ class TestSecretsManagerSecret:
|
||||
try:
|
||||
response = secretsmanager_client.describe_secret(SecretId=secret_name)
|
||||
assert response.get("Tags")
|
||||
assert not response.get("RotationEnabled", True)
|
||||
assert "RotationEnabled" not in response
|
||||
finally:
|
||||
secretsmanager_client.delete_secret(
|
||||
SecretId=secret_name, ForceDeleteWithoutRecovery=True
|
||||
|
||||
@@ -362,7 +362,9 @@ public class SecretsManagerJsonHandler {
|
||||
if (secret.getKmsKeyId() != null) {
|
||||
response.put("KmsKeyId", secret.getKmsKeyId());
|
||||
}
|
||||
response.put("RotationEnabled", secret.isRotationEnabled());
|
||||
if (secret.isRotationConfigured()) {
|
||||
response.put("RotationEnabled", secret.isRotationEnabled());
|
||||
}
|
||||
if (secret.getRotationLambdaArn() != null) {
|
||||
response.put("RotationLambdaARN", secret.getRotationLambdaArn());
|
||||
}
|
||||
@@ -383,6 +385,9 @@ public class SecretsManagerJsonHandler {
|
||||
if (secret.getLastChangedDate() != null) {
|
||||
response.put("LastChangedDate", EpochSeconds.fromInstant(secret.getLastChangedDate()));
|
||||
}
|
||||
if (secret.getLastAccessedDate() != null) {
|
||||
response.put("LastAccessedDate", EpochSeconds.fromInstant(secret.getLastAccessedDate()));
|
||||
}
|
||||
if (secret.getDeletedDate() != null) {
|
||||
response.put("DeletedDate", EpochSeconds.fromInstant(secret.getDeletedDate()));
|
||||
}
|
||||
@@ -582,7 +587,9 @@ public class SecretsManagerJsonHandler {
|
||||
if (secret.getKmsKeyId() != null) {
|
||||
node.put("KmsKeyId", secret.getKmsKeyId());
|
||||
}
|
||||
node.put("RotationEnabled", secret.isRotationEnabled());
|
||||
if (secret.isRotationConfigured()) {
|
||||
node.put("RotationEnabled", secret.isRotationEnabled());
|
||||
}
|
||||
if (secret.getRotationLambdaArn() != null) {
|
||||
node.put("RotationLambdaARN", secret.getRotationLambdaArn());
|
||||
}
|
||||
|
||||
@@ -32,6 +32,7 @@ import org.jboss.logging.Logger;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
@@ -327,8 +328,10 @@ public class SecretsManagerService implements ResourceProvider, StoredResourceAr
|
||||
}
|
||||
}
|
||||
|
||||
version.setLastAccessedDate(Instant.now());
|
||||
secret.setLastAccessedDate(Instant.now());
|
||||
// AWS records the access as the UTC day, truncated to midnight.
|
||||
Instant accessedDay = Instant.now().truncatedTo(ChronoUnit.DAYS);
|
||||
version.setLastAccessedDate(accessedDay);
|
||||
secret.setLastAccessedDate(accessedDay);
|
||||
// Deliberately not persist(): reading a secret is not a change to replicate, and pushing
|
||||
// the primary out to every replica on each read would rebuild them constantly and
|
||||
// clobber each replica's own last-accessed bookkeeping.
|
||||
@@ -1251,6 +1254,7 @@ public class SecretsManagerService implements ResourceProvider, StoredResourceAr
|
||||
replica.setLastChangedDate(primary.getLastChangedDate());
|
||||
replica.setLastRotatedDate(primary.getLastRotatedDate());
|
||||
replica.setRotationEnabled(primary.isRotationEnabled());
|
||||
replica.setRotationConfigured(primary.isRotationConfigured());
|
||||
replica.setRotationLambdaArn(primary.getRotationLambdaArn());
|
||||
replica.setRotationRules(primary.getRotationRules());
|
||||
replica.setNextRotationDate(primary.getNextRotationDate());
|
||||
|
||||
@@ -19,6 +19,7 @@ public class Secret {
|
||||
private String description;
|
||||
private String kmsKeyId;
|
||||
private boolean rotationEnabled;
|
||||
private boolean rotationConfigured;
|
||||
private Instant createdDate;
|
||||
private Instant lastChangedDate;
|
||||
private Instant lastAccessedDate;
|
||||
@@ -108,6 +109,18 @@ public class Secret {
|
||||
|
||||
public void setRotationEnabled(boolean rotationEnabled) {
|
||||
this.rotationEnabled = rotationEnabled;
|
||||
if (rotationEnabled) {
|
||||
this.rotationConfigured = true;
|
||||
}
|
||||
}
|
||||
|
||||
/** True once rotation has been configured at least once, even if it was later cancelled. */
|
||||
public boolean isRotationConfigured() {
|
||||
return rotationConfigured;
|
||||
}
|
||||
|
||||
public void setRotationConfigured(boolean rotationConfigured) {
|
||||
this.rotationConfigured = rotationConfigured;
|
||||
}
|
||||
|
||||
public Instant getCreatedDate() {
|
||||
|
||||
@@ -12,6 +12,8 @@ import jakarta.ws.rs.core.Response;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.temporal.ChronoUnit;
|
||||
import java.util.List;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
@@ -153,6 +155,47 @@ class SecretsManagerJsonHandlerTest {
|
||||
assertThat(body.get("KmsKeyId").asText(), is("my-kms-key"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeSecretOmitsRotationEnabledAndLastAccessedDateForAFreshSecret() {
|
||||
createSecret("fresh-secret");
|
||||
|
||||
ObjectNode described = describe("fresh-secret");
|
||||
|
||||
assertThat(described.has("RotationEnabled"), is(false));
|
||||
assertThat(described.has("LastAccessedDate"), is(false));
|
||||
}
|
||||
|
||||
@Test
|
||||
void describeSecretReturnsLastAccessedDateAfterGetSecretValue() {
|
||||
createSecret("read-secret");
|
||||
ObjectNode getReq = MAPPER.createObjectNode();
|
||||
getReq.put("SecretId", "read-secret");
|
||||
long before = Instant.now().truncatedTo(ChronoUnit.DAYS).getEpochSecond();
|
||||
handler.handle("GetSecretValue", getReq, REGION);
|
||||
long after = Instant.now().truncatedTo(ChronoUnit.DAYS).getEpochSecond();
|
||||
|
||||
// AWS stamps the UTC day, truncated to midnight, not the read time.
|
||||
double accessed = describe("read-secret").get("LastAccessedDate").asDouble();
|
||||
assertThat(accessed == before || accessed == after, is(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listSecretsOmitsRotationEnabledForASecretNeverConfiguredForRotation() {
|
||||
createSecret("list-fresh");
|
||||
createSecret("list-rotating");
|
||||
enableRotation("list-rotating");
|
||||
|
||||
ObjectNode body = (ObjectNode) handler.handle("ListSecrets", MAPPER.createObjectNode(), REGION).getEntity();
|
||||
|
||||
for (JsonNode entry : body.get("SecretList")) {
|
||||
if ("list-fresh".equals(entry.get("Name").asText())) {
|
||||
assertThat(entry.has("RotationEnabled"), is(false));
|
||||
} else {
|
||||
assertThat(entry.get("RotationEnabled").asBoolean(), is(true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void targetAttachmentOwnershipIsNotExposedByPublicResponses() {
|
||||
ObjectNode createReq = MAPPER.createObjectNode();
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ class SecretsManagerRotationFunctionRegionIntegrationTest {
|
||||
secretsManager("DescribeSecret", "{\"SecretId\": \"" + secretName + "\"}")
|
||||
.then()
|
||||
.statusCode(200)
|
||||
.body("RotationEnabled", equalTo(false))
|
||||
.body("RotationEnabled", nullValue())
|
||||
.body("RotationLambdaARN", nullValue());
|
||||
}
|
||||
|
||||
|
||||
@@ -1298,6 +1298,18 @@ class SecretsManagerServiceTest {
|
||||
assertFalse(service.describeSecret("rotating", REGION).isRotationEnabled());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rotationConfiguredIsFalseUntilRotateSecretAndSurvivesCancel() {
|
||||
service.createSecret("rotating", "v1", null, null, null, null, REGION);
|
||||
assertFalse(service.describeSecret("rotating", REGION).isRotationConfigured());
|
||||
|
||||
enableRotation("rotating");
|
||||
assertTrue(service.describeSecret("rotating", REGION).isRotationConfigured());
|
||||
|
||||
service.cancelRotateSecret("rotating", REGION);
|
||||
assertTrue(service.describeSecret("rotating", REGION).isRotationConfigured());
|
||||
}
|
||||
|
||||
@Test
|
||||
void cancelRotateSecretReportsNoPendingVersionWhenNoneIsStaged() {
|
||||
service.createSecret("rotating", "v1", null, null, null, null, REGION);
|
||||
|
||||
Reference in new issue
Block a user