Windows Server Summit 2024
Mar 26 2024 08:00 AM - Mar 28 2024 04:30 PM (PDT)
Microsoft Tech Community
LIVE
Migrating local VM owner certificates for VMs with vTPM
Published Mar 21 2019 05:14 PM 18K Views
Copper Contributor
First published on TECHNET on Dec 14, 2017
Whenever I want to replace or reinstall a system which is used to run virtual machines with a virtual trusted platform module (vTPM), I've been facing a challenge: For hosts that are not part of a guarded fabric , the new system does need to be authorized to run the VM.
Some time ago, I wrote a blog post focused on running VMs with a vTPM on additional hosts , but the approach highlighted there does not solve everything when the original host is decommissioned. The VMs can be started on the new host, but without the original owner certificates, you cannot change the list of allowed guardians anymore.

This blog post shows a way to export the information needed from the source host and import it on a destination host. Please note that this technique only works for local mode and not for a host that is part of a guarded fabric. You can check whether your host runs in local mode by running Get-HgsClientConfiguration . The property Mode should list Local as a value.

Exporting the default owner from the source host


The following script exports the necessary information of the default owner (" UntrustedGuardian ") on a host that is configured using local mode. When running the script on the source host, two certificates are exported: a signing certificate and an encryption certificate.


Importing the UntrustedGuardian on the new host


On the destination host, the following snippet creates a new guardian using the certificates that have been exported in the previous step.


Please note that importing the "UntrustedGuardian" on the new host has to be done before creating new VMs with a vTPM on this host -- otherwise a new guardian with the same name will already be present and the creation with the PowerShell snippet above will fail.

With these two steps, you should be able to migrate all the necessary bits to keep your VMs with vTPM running in your dev/test environment. This approach can also be used to back up your owner certificates, depending on how these certificates have been created.
12 Comments
Copper Contributor

This article would be great if the script and snippet Lars refers to were actually obtainable from the blog. It seems that these were removed when the page was migrated to this site from TechNet.

Copper Contributor

@Craig-Anderson-Icare  - I was able to dig up the Google Cache version from the original article with intact code snippets.

 

https://webcache.googleusercontent.com/search?q=cache:G_tK3wcq3eUJ:https://blogs.technet.microsoft.c...

Copper Contributor

@Ryan Sheldon - thanks for finding that!

Copper Contributor

Export-UntrustedGuardian.ps1 Contents:

 

$GuardianName = 'UntrustedGuardian'
$CertificatePassword = Read-Host -Prompt 'Please enter a password to secure the certificate files' -AsSecureString

$guardian = Get-HgsGuardian -Name $GuardianName

if (-not $guardian)
{
    throw "Guardian '$GuardianName' could not be found on the local system."
}

$encryptionCertificate = Get-Item -Path "Cert:\LocalMachine\Shielded VM Local Certificates\$($guardian.EncryptionCertificate.Thumbprint)"
$signingCertificate = Get-Item -Path "Cert:\LocalMachine\Shielded VM Local Certificates\$($guardian.SigningCertificate.Thumbprint)"

if (-not ($encryptionCertificate.HasPrivateKey -and $signingCertificate.HasPrivateKey))
{
    throw 'One or both of the certificates in the guardian do not have private keys. ' + `
          'Please ensure the private keys are available on the local system for this guardian.'
}

Export-PfxCertificate -Cert $encryptionCertificate -FilePath ".\$GuardianName-encryption.pfx" -Password $CertificatePassword
Export-PfxCertificate -Cert $signingCertificate -FilePath ".\$GuardianName-signing.pfx" -Password $CertificatePassword
Copper Contributor

Import-UntrustedGuardian.ps1 Contents:

 

teGuardianName = 'UntrustedGuardian'
$CertificatePassword = Read-Host -Prompt 'Please enter the password that was used to secure the certificate files' -AsSecureString
New-HgsGuardian -Name $NameOfGuardian -SigningCertificate ".\$NameOfGuardian-signing.pfx" -SigningCertificatePassword $CertificatePassword -EncryptionCertificate ".\$NameOfGuardian-encryption.pfx" -EncryptionCertificatePassword $CertificatePassword -AllowExpired -AllowUntrustedRoot
Copper Contributor

What if I no longer have access to the source device that originally ran the VMs (it was wiped and sent back to Microsoft)? How can I clear the vTPM info from the VM entirely and create a new vTPM since the guardian certs are gone forever?

Microsoft

That is my issue as well Ashley, source system is dead and gone.....

Copper Contributor

Were you able to figure this out, Chuck? Fortunately for us we could just throw away the VMs and recreate them, but it would've been a real nightmare if we couldn't.

Microsoft

Unfortunately no. At least I only lost 3 VMs but it is still a pain. I have since modified my procedures to backup the certs to a central repository using code based on the code Craig-Anderson-Icare supplied above. Minimizing impacts and futureproofing are the best I can do at this point. I may try automating backing up the bitlocker keys centrally as well.

 

Copper Contributor

@Craig-Anderson-Icare 

There is an error in your script. You use $NameOfGuardian but it is not defined. Instead you write

teGuardianName = 'UntrustedGuardian'

 

With this it works perfectly:

$NameOfGuardian = 'UntrustedGuardian'

Copper Contributor

@JuergenGeiss 

That is not my script. I found it for @Ryan Sheldon on a cached site and pasted the contents for him. Appreciate the heads up though :)

Copper Contributor

Sorry, I know this is not on topic, but in the process of transferring my certs, I stupidly deleted the shielded vm encryption certs on my local machine thinking that I had not imported them correctly.   Does anyone know how to repair the certificates to resolve the "Guardian "UntrustedGuardian" cannot be an owner because it does not have private keys" error on enabling TPM of the hyper-v?

Version history
Last update:
‎Mar 21 2019 05:14 PM
Updated by: