-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add support for vTPM for XenServer and XCP-ng 8.3/8.4 #12263
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8b1fc3a
cc8ea1e
bb56411
b12036b
6688842
c5c4ed7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -51,6 +51,7 @@ | |||||||||||
| import javax.naming.ConfigurationException; | ||||||||||||
| import javax.xml.parsers.ParserConfigurationException; | ||||||||||||
|
|
||||||||||||
| import com.xensource.xenapi.VTPM; | ||||||||||||
| import org.apache.cloudstack.api.ApiConstants; | ||||||||||||
| import org.apache.cloudstack.diagnostics.CopyToSecondaryStorageAnswer; | ||||||||||||
| import org.apache.cloudstack.diagnostics.CopyToSecondaryStorageCommand; | ||||||||||||
|
|
@@ -5826,4 +5827,82 @@ public void destroyVm(VM vm, Connection connection, boolean forced) throws XenAP | |||||||||||
| public void destroyVm(VM vm, Connection connection) throws XenAPIException, XmlRpcException { | ||||||||||||
| destroyVm(vm, connection, false); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| /** | ||||||||||||
| * Configure vTPM (Virtual Trusted Platform Module) support for a VM. | ||||||||||||
| * vTPM provides a virtual TPM 2.0 device for VMs, enabling features like Secure Boot and disk encryption. | ||||||||||||
| * | ||||||||||||
| * Requirements: | ||||||||||||
| * - XenServer/XCP-ng 8.3 (and above) | ||||||||||||
| * - UEFI Secure Boot enabled | ||||||||||||
| * - VM in halted state | ||||||||||||
| * | ||||||||||||
| * @param conn XenServer connection | ||||||||||||
| * @param vm The VM to configure | ||||||||||||
| * @param vmSpec VM specification containing vTPM settings | ||||||||||||
| */ | ||||||||||||
| public void configureVTPM(Connection conn, VM vm, VirtualMachineTO vmSpec) throws XenAPIException, XmlRpcException { | ||||||||||||
| if (vmSpec == null || vmSpec.getDetails() == null) { | ||||||||||||
| return; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| String vtpmEnabled = vmSpec.getDetails().getOrDefault(VmDetailConstants.VIRTUAL_TPM_ENABLED, null); | ||||||||||||
|
|
||||||||||||
| final Map<String, String> platform = vm.getPlatform(conn); | ||||||||||||
| if (platform != null) { | ||||||||||||
| final String guestRequiresVtpm = platform.get("vtpm"); | ||||||||||||
| if (guestRequiresVtpm != null && Boolean.parseBoolean(guestRequiresVtpm) && !Boolean.parseBoolean(vtpmEnabled)) { | ||||||||||||
| logger.warn("Guest OS requires vTPM by default, even if VM details doesn't have the setting: {}", vmSpec.getName()); | ||||||||||||
| return; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if (!Boolean.parseBoolean(vtpmEnabled)) { | ||||||||||||
| return; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| String bootMode = StringUtils.defaultIfEmpty(vmSpec.getDetails().get(ApiConstants.BootType.UEFI.toString()), null); | ||||||||||||
| String bootType = (bootMode == null) ? ApiConstants.BootType.BIOS.toString() : ApiConstants.BootType.UEFI.toString(); | ||||||||||||
|
|
||||||||||||
| if (!ApiConstants.BootType.UEFI.toString().equals(bootType)) { | ||||||||||||
|
Comment on lines
+5865
to
+5867
|
||||||||||||
| String bootType = (bootMode == null) ? ApiConstants.BootType.BIOS.toString() : ApiConstants.BootType.UEFI.toString(); | |
| if (!ApiConstants.BootType.UEFI.toString().equals(bootType)) { | |
| if (!ApiConstants.BootType.UEFI.toString().equalsIgnoreCase(bootMode)) { |
Copilot
AI
Jan 27, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The minimum version check is inconsistent with the PR description and documentation. The PR title and description state support for XenServer 8.4 / XCP-ng 8.3/8.4, and the documentation comment at line 5836 states "XenServer/XCP-ng 8.3 (and above)", but this code checks for version 8.2.0 or higher. This version mismatch could enable vTPM on versions that don't properly support it. The minimum version should be updated to "8.3.0" to match the stated requirements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a grammatical error in this log message. "doesn't" should be "don't" because "VM details" is plural (referring to the details map/collection). The correct phrasing should be: "Guest OS requires vTPM by default, even if VM details don't have the setting"