mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
feat(kms): handle RotateKeyOnDemand rotation limit (#1042)
Signed-off-by: KyounghoonJang <matkimchi_@naver.com>
This commit is contained in:
1 parent
5d3f6e9c8c
commit
650cc2280c
3 files changed
+27
No files matched your search
@@ -495,6 +495,7 @@ public class KmsService {
|
||||
LOG.infov("Disabled key rotation for 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);
|
||||
if (!key.isEnabled()) {
|
||||
@@ -502,6 +503,12 @@ public class KmsService {
|
||||
"KMS key " + key.getKeyId() + " is disabled.", 400);
|
||||
}
|
||||
validateRotationSupported(key);
|
||||
if (key.getOnDemandRotationCount() >= ON_DEMAND_ROTATION_LIMIT) {
|
||||
throw new AwsException("LimitExceededException",
|
||||
"On-demand rotation quota for KMS key " + key.getKeyId() + " is exceeded.", 400);
|
||||
}
|
||||
key.setOnDemandRotationCount(key.getOnDemandRotationCount() + 1);
|
||||
keyStore.put(region + "::" + key.getKeyId(), key);
|
||||
return key.getKeyId();
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ public class KmsKey {
|
||||
private Map<String, String> tags = new HashMap<>();
|
||||
private String privateKeyEncoded;
|
||||
private String publicKeyEncoded;
|
||||
private int onDemandRotationCount;
|
||||
|
||||
public KmsKey() {
|
||||
this.creationDate = Instant.now().getEpochSecond();
|
||||
@@ -70,4 +71,7 @@ public class KmsKey {
|
||||
|
||||
public String getPublicKeyEncoded() { return publicKeyEncoded; }
|
||||
public void setPublicKeyEncoded(String publicKeyEncoded) { this.publicKeyEncoded = publicKeyEncoded; }
|
||||
|
||||
public int getOnDemandRotationCount() { return onDemandRotationCount; }
|
||||
public void setOnDemandRotationCount(int onDemandRotationCount) { this.onDemandRotationCount = onDemandRotationCount; }
|
||||
}
|
||||
Reference in new issue
Block a user