Add KMS key state and description operations (#1251)

* feat(kms): support disabling keys

* feat(kms): support key description updates

* fix(kms): tighten key description update coverage
This commit is contained in:
Jason van Zyl authored and GitHub committed 2026-06-11 01:19:09 -05:00
1 parent 22cff99830
commit 6e4087b0f4
6 files changed
+165 -1

No files matched your search

@@ -65,9 +65,11 @@ public class KmsJsonHandler {
case "ListResourceTags" -> handleListResourceTags(request, region);
case "GetKeyPolicy" -> handleGetKeyPolicy(request, region);
case "PutKeyPolicy" -> handlePutKeyPolicy(request, region);
case "UpdateKeyDescription" -> handleUpdateKeyDescription(request, region);
case "GetKeyRotationStatus" -> handleGetKeyRotationStatus(request, region);
case "EnableKeyRotation" -> handleEnableKeyRotation(request, region);
case "DisableKeyRotation" -> handleDisableKeyRotation(request, region);
case "DisableKey" -> handleDisableKey(request, region);
case "RotateKeyOnDemand" -> handleRotateKeyOnDemand(request, region);
default -> Response.status(400)
.entity(new AwsErrorResponse("UnsupportedOperation", "Operation " + action + " is not supported."))
@@ -475,6 +477,22 @@ public class KmsJsonHandler {
return Response.ok(objectMapper.createObjectNode()).build();
}
private Response handleUpdateKeyDescription(JsonNode request, String region) {
service.updateKeyDescription(
request.path("KeyId").asText(),
requiredText(request, "Description"),
region);
return Response.ok(objectMapper.createObjectNode()).build();
}
private String requiredText(JsonNode request, String field) {
JsonNode value = request.path(field);
if (value.isMissingNode() || value.isNull()) {
throw new AwsException("ValidationException", field + " is required", 400);
}
return value.asText();
}
private Response handleGetKeyRotationStatus(JsonNode request, String region) {
String keyId = request.path("KeyId").asText();
boolean enabled = service.getKeyRotationStatus(keyId, region);
@@ -493,6 +511,11 @@ public class KmsJsonHandler {
return Response.ok(objectMapper.createObjectNode()).build();
}
private Response handleDisableKey(JsonNode request, String region) {
service.disableKey(request.path("KeyId").asText(), region);
return Response.ok(objectMapper.createObjectNode()).build();
}
private Response handleRotateKeyOnDemand(JsonNode request, String region) {
String keyId = service.rotateKeyOnDemand(request.path("KeyId").asText(), region);
ObjectNode response = objectMapper.createObjectNode();
@@ -489,6 +489,13 @@ public class KmsService {
LOG.infov("Updated key policy for KMS key: {0} in {1}", key.getKeyId(), region);
}
public void updateKeyDescription(String keyId, String description, String region) {
KmsKey key = resolveKey(keyId, region);
key.setDescription(description);
keyStore.put(region + "::" + key.getKeyId(), key);
LOG.infov("Updated description for KMS key: {0} in {1}", key.getKeyId(), region);
}
// ──────────────────────────── Key Rotation ────────────────────────────
public boolean getKeyRotationStatus(String keyId, String region) {
@@ -516,6 +523,14 @@ public class KmsService {
LOG.infov("Disabled key rotation for KMS key: {0} in {1}", key.getKeyId(), region);
}
public void disableKey(String keyId, String region) {
KmsKey key = resolveKey(keyId, region);
key.setEnabled(false);
key.setKeyState("Disabled");
keyStore.put(region + "::" + key.getKeyId(), key);
LOG.infov("Disabled KMS key: {0} in {1}", key.getKeyId(), region);
}
private static final int ON_DEMAND_ROTATION_LIMIT = 25;
public String rotateKeyOnDemand(String keyId, String region) {
KmsKey key = resolveKey(keyId, region);