fix(kms): keep import parameters valid across concurrent identical imports (#9004)

* fix(kms): keep import parameters valid across concurrent identical imports
* fix(kms): ImportKeyMaterial no longer re-enables a Disabled key
This commit is contained in:
Allen Sanborn authored and GitHub committed 2026-11-20 07:11:09 -04:00
1 parent 42707716cd
commit 704b5f1c3b
3 files changed
+66 -12

No files matched your search

@@ -1074,7 +1074,9 @@ public class KmsService implements ResourceProvider {
/**
* Unwraps and installs key material, which takes the key from PendingImport to Enabled. The
* import token is spent by the call that uses it, as it is on real KMS.
* import token stays valid until it expires, so concurrent imports of the same material all
* succeed; a different material is refused by {@code requireSameMaterialAsFirstImport}, not by
* the token. Unlike AWS, a later GetParametersForImport still replaces the earlier token.
*/
public KmsKey importKeyMaterial(String keyId, String importToken, byte[] encryptedKeyMaterial,
String expirationModel, Long validTo, String importType, String region) {
@@ -1106,9 +1108,11 @@ public class KmsService implements ResourceProvider {
key.setKeyMaterialId(keyMaterialId);
key.setExpirationModel(effectiveExpirationModel);
key.setValidTo(KEY_MATERIAL_EXPIRES.equals(effectiveExpirationModel) ? validTo : 0L);
key.setKeyState("Enabled");
key.setEnabled(true);
key.setImportParameters(null);
// A key that already had material keeps its state: a re-import does not re-enable a disabled key.
if (PENDING_IMPORT.equals(key.getKeyState())) {
key.setKeyState("Enabled");
key.setEnabled(true);
}
keyStore.put(region + "::" + key.getKeyId(), key);
LOG.infov("Imported key material into KMS key {0} in {1} ({2})",