Skip to content

Commit 866fc0f

Browse files
author
Zhang Wenhao
committed
<feature>[kvm]: support TPM revert without KMS
Support TPM snapshot group revert when ALLOWED_TPM_VM_WITHOUT_KMS config is enabled. Skip key provider resolution to allow TPM recovery without KMS dependency. Changes: - Add ALLOWED_TPM_VM_WITHOUT_KMS config check - Skip key provider resolution when config is true Resolves: ZSV-11489 Related: ZSV-11310 Change-Id: I6470766e66656f6464767a7776696a7a6979706b
1 parent 912b02f commit 866fc0f

1 file changed

Lines changed: 19 additions & 15 deletions

File tree

plugin/kvm/src/main/java/org/zstack/kvm/tpm/SnapshotGroupRevertTpmHelper.java

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323

2424
import java.util.List;
2525

26+
import static org.zstack.compute.vm.VmGlobalConfig.ALLOWED_TPM_VM_WITHOUT_KMS;
27+
2628
@Configurable(preConstruction = true, autowire = Autowire.BY_TYPE)
2729
public class SnapshotGroupRevertTpmHelper {
2830
private static final CLogger logger = Utils.getLogger(SnapshotGroupRevertTpmHelper.class);
@@ -98,23 +100,25 @@ public void setupFromApi(APICreateVmInstanceFromVolumeSnapshotGroupMsg apiMsg, C
98100
tpmSpec.setBackupFileUuid(tpmBackupFile.getUuid());
99101
}
100102

101-
String keyProviderName = KVMSystemTags.TPM_KEY_PROVIDER_NAME
102-
.getTokenByResourceUuid(tpmBackupFile.getUuid(), KVMSystemTags.TPM_KEY_PROVIDER_NAME_TOKEN);
103-
if (keyProviderName == null) {
104-
logger.warn(String.format(
105-
"failed to find keyProvider from snapshotGroup[uuid:%s] by tpmBackupFile[uuid:%s]",
106-
snapshotGroupUuid, tpmBackupFile.getUuid()));
107-
if (tpmSpec.getKeyProviderUuid() == null) {
108-
tpmSpec.setKeyProviderUuid(tpmKeyBackend.defaultKeyProviderUuid()); // maybe null
109-
}
110-
} else {
111-
String keyProviderUuid = tpmKeyBackend.findKeyProviderUuidByName(keyProviderName);
112-
if (keyProviderUuid == null) {
103+
if (ALLOWED_TPM_VM_WITHOUT_KMS.value(Boolean.class) != Boolean.TRUE) {
104+
String keyProviderName = KVMSystemTags.TPM_KEY_PROVIDER_NAME
105+
.getTokenByResourceUuid(tpmBackupFile.getUuid(), KVMSystemTags.TPM_KEY_PROVIDER_NAME_TOKEN);
106+
if (keyProviderName == null) {
113107
logger.warn(String.format(
114-
"failed to resolve keyProvider[name:%s] from snapshotGroup[uuid:%s] by tpmBackupFile[uuid:%s], keep keyProviderUuid unset",
115-
keyProviderName, snapshotGroupUuid, tpmBackupFile.getUuid()));
108+
"failed to find keyProvider from snapshotGroup[uuid:%s] by tpmBackupFile[uuid:%s]",
109+
snapshotGroupUuid, tpmBackupFile.getUuid()));
110+
if (tpmSpec.getKeyProviderUuid() == null) {
111+
tpmSpec.setKeyProviderUuid(tpmKeyBackend.defaultKeyProviderUuid()); // maybe null
112+
}
116113
} else {
117-
tpmSpec.setKeyProviderUuid(keyProviderUuid);
114+
String keyProviderUuid = tpmKeyBackend.findKeyProviderUuidByName(keyProviderName);
115+
if (keyProviderUuid == null) {
116+
logger.warn(String.format(
117+
"failed to resolve keyProvider[name:%s] from snapshotGroup[uuid:%s] by tpmBackupFile[uuid:%s], keep keyProviderUuid unset",
118+
keyProviderName, snapshotGroupUuid, tpmBackupFile.getUuid()));
119+
} else {
120+
tpmSpec.setKeyProviderUuid(keyProviderUuid);
121+
}
118122
}
119123
}
120124
}

0 commit comments

Comments
 (0)