Microsoft Hyper-V Shielded VM Windows Server 2025

  1. Home
  2. »
  3. Datacenter Management
  4. »
  5. Windows Server 2025
  6. »
  7. Microsoft Hyper-V Shielded VM Windows Server 2025

Danh mục bài viết:

Tại sao nên sử dụng (Shielded VMs) ?

Shielded VMs trong Windows Server 2025 giúp bảo vệ các máy ảo khỏi quản trị viên Hyper-V bằng công nghệ mã hóa. Việc gắn thiết bị vTPM vào các máy ảo Hyper-V cho phép người dùng tăng cường bảo mật và tính toàn vẹn hệ thống. Quản trị viên Hyper-V chỉ có thể bật hoặc tắt máy ảo.

Tổng quan, ngay cả khi quản trị viên (IT Administrator) trên Host chạy HyperV hoặc Hacker xâm nhập chiếm quyền truy cập lớp vật lý, tất cả dữ liệu VM vẫn an toàn.

Shielded VMs mang lại những lợi ích sau:

  • Ổ đĩa được mã hóa bằng BitLocker (khóa được bảo vệ bởi vTPM của nó)
  • Một tiến trình xử lý VM (VMWP) được tăng cường giúp ngăn chặn việc kiểm tra và can thiệp trái phép.
  • Tự động mã hóa lưu lượng di chuyển trực tiếp cũng như mã hóa tệp trạng thái thời gian chạy, trạng thái đã lưu, điểm kiểm tra và thậm chí cả các tệp Hyper-V Replica.
  • Không có quyền truy cập bảng điều khiển, đồng thời chặn PowerShell Direct, Guest File Copy Integration Components và các dịch vụ khác cung cấp các đường dẫn khả thi từ người dùng hoặc quy trình có quyền quản trị đến máy ảo.

Điều kiện cần có:

Không cần System Center VMM trong quá trình triển khai này.

  • Guarded Host: WS2016 TP5 Datacenter (Secure Boot enabled)
  • Host Guardian Service Host: WS2016 TP5 (Secure Boot enabled)
  • AD Domain Controller Host: WS2008R2/WS2012R2/WS2016 TP5
  • Tenant Host: Windows 10/WS2016 TP5

Windows Server 2025 đi kèm với tính năng (Host Guardian Service – HGS), cung cấp các dịch vụ xác thực và Key Protection để các Host được bảo vệ có thể chạy các VM được bảo vệ (Shielded VMs). Xác thực từ xa HGS kiểm tra trạng thái cấu hình Host và xem nó có được bảo vệ hay không. HGS Key Protection cho phép truy cập phân tán vào các khóa vận chuyển được mã hóa để cho phép Guarded Hosts và thực thi Shielded VMs..

Trong quá trình cài đặt HGS Server, việc triển khai một “Domain” là bắt buộc và được nâng cấp thành Domain Controller. HGS yêu cầu thiết lập mối quan hệ tin cậy “one-way cross” giữa các “forest” từ miền HGS đến bộ điều khiển AD domain controller với tất cả các node được liên kết an toàn. AD group đó sẽ được xác thực với HGS Server và bất kỳ thành viên nào cũng sẽ được coi là Guarded host, một Node an toàn và sẵn sàng chạy các máy ảo được che chắn (Shielded VMs).

AD Configuration

Tạo “AD group” chứa tất cả các Host được coi là an toàn và sẽ chạy các VMo được bảo vệ (Shielded VMs):

$GuardedGroupName=‘Guarded Hosts Group’
# hostname of a secure node which will run Shielded VMs
$guardedhost=‘guarded’
$guardedGroup = New-ADGroup -Name $GuardedGroupName -SamAccountName ‘GuardedHosts’ `
-GroupCategory Security -GroupScope Global
# $GroupMember should look similar to “CN=$cn, DC=$dc”
# ex: “CN=guarded,CN=Computers,DC=dev,DC=com”
Add-ADGroupMember -Identity $GuardedGroupName -Members $GroupMember
# $guardedGroup.sid.Value will be used as an Identifier when setting up the attestation for HGS
$guardedGroup.sid.Value

Host Guardian Service Configuration

Cài đặt Roles (Host Guardian Service) trên Windows Server 2025
Install-WindowsFeature -Name HostGuardianServiceRoleIncludeManagementTools -Restart
Cài đặt Host Guardian Service Server
# $HGSDomainName is the Host Guardian Service domain set up during HGS installation
# the node will be promoted to a domain controller for the specified domain
$AdminPass = ‘Password’
$HGSDomainName = ‘hgs.com’
$adminPassword = ConvertTo-SecureString -AsPlainText $AdminPassForce
Install-HgsServer -HgsDomainName $HGSDomainName `
-SafeModeAdministratorPassword $adminPassword -Restart
Thực hiện “Initialize the HGS Server”
$certificatePasswd = ‘Password’
$signingCertPath = ‘C:\signingCert.pfx’
$encryptionCertPath = ‘C:\encryptionCert.pfx’
$certStoreLocation = ‘Cert:\LocalMachine\My’
$certificatePassword = ConvertTo-SecureString -AsPlainText $certificatePasswdForce
$signingCert = New-SelfSignedCertificate -DnsName “signing.$env:userdnsdomain” `
-CertStoreLocation $certStoreLocation
Export-PfxCertificate -Cert $signingCert -Password $certificatePassword `
-FilePath $signingCertPath
$encryptionCert = New-SelfSignedCertificate -DnsName “encryption.$env:userdnsdomain” `
-CertStoreLocation $certStoreLocation
Export-PfxCertificate -Cert $encryptionCert -Password $certificatePassword `
-FilePath $encryptionCertPath
Initialize-HGSServer -HgsServiceName $HgsServiceName `
-SigningCertificatePath $signingCertPath `
-SigningCertificatePassword $certificatePassword `
-EncryptionCertificatePath $encryptionCertPath `
-EncryptionCertificatePassword $certificatePassword -TrustActiveDirectory -Force
Cấu hình địa chỉ IP vàoAD domain controller trên DNS server:
Add-DnsServerForwarderIPAddress $ADDnsIpAddress
Cấu hình liên kết tin cậy giữa HGS và AD
$HGSDomainName = ‘hgs.com’
$ADDomainName = ‘dev.com’
$ADDomainUser = ‘Administrator’
$ADAdminPasswd = ‘Password’
netdom trust $HGSDomainName /domain:$ADDomainName /userD:$ADDomainName\$ADDomainUse  /passwordD:$ADAdminPasswd /add
Thêm  AD Group với tên HgsAttestationHostGroup để tất cả các Host thành viên của nhóm được bảo vệ và được HGS coi là an toàn:
Add-HgsAttestationHostGroup -Name “Guarded Hosts” -Identifier “$GuardedGroupSID”

 

GuardedHost Configuration

Install the necessary roles:

 

Install-WindowsFeature -Name HostGuardian

Install-WindowsFeature -Name RSAT-Shielded-VM-Tools

Install-WindowsFeature -Name FabricShieldedTools -Restart

 

Để các Host được bảo vệ có thể phân giải tên máy chủ HGS, thực hiện thêm DNS forwarder để Host được bảo vệ có thể xác thực với HGS:

 

Add-DnsServerConditionalForwarderZone -Name $HgsDomainName -ReplicationScope “Forest” ` -MasterServers $HgsServerIP

 

Thực hiện cấu hình Hyper-V host xác thực với HGS server:

 

Set-HgsClientConfiguration -AttestationServerUrl “http://$HGSDomainName/Attestation” `
-KeyProtectionServerUrl “http://$HGSDomainName/KeyProtection” -confirm:$false
Kiểm tra trạng thái xác thực. Nếu Host được bảo vệ, nó đã sẵn sàng cho Shielded VMs
Get-HgsClientConfiguration

 

Booting a Shielded VMs

 

Các bước thực hiện bên dưới sẽ được áp dụng trên máy chủ Hyper-V không phải thực hiện trên Guarded Host.

 

Để tạo một VM được bảo vệ (shielded VM), cần có một “shielded VM template” và “pdk file” chứa dữ liệu về các Guarded Hosts, chứng chỉ và các thông tin khác liên quan đến Shielded VM

Install the following roles:

 

Install-WindowsFeature -Name RSAT-Shielded-VM-Tools

Install-WindowsFeature -Name FabricShieldedTools -Restart

 

Generate a shielded template

Hiện tại, Windows Server 2025  là hệ điều được hỗ trợ khi sử dụng các mẫu đĩa đã được ký. Hãy đảm bảo rằng đĩa đáp ứng các yêu cầu BitLocker sau:

  • Được định dạng bằng hệ thống tệp NTFS.
  • Không sử dụng tính năng Dynamic Volume.
  • Ổ cứng phải có ít nhất hai phân vùng. Một phân vùng phải chứa ổ đĩa cài đặt Windows. Đây là ổ đĩa mà BitLocker sẽ mã hóa. Phân vùng còn lại là phân vùng hoạt động, không được mã hóa để VM có thể khởi động.

Các thao tác được thực hiện trên giao diện Microsoft PowerShell

Generate a self-signed certificate to sign the disk:

 

$certificate = New-SelfSignedCertificate -DnsName publisher.signingcertificate.com `
-CertStoreLocation $certStoreLocation -KeyExportPolicy Exportable
Create a signed disk template: (Tạo mẫu đĩa)
# $certificate is used to sign the template disk
# Specify a disk name and version
# .VHDX image is modified by embedding the .VSC file in it so making a copy of the image is recommended
$TemplatePath = ‘C:\protected_template.vhdx’
$TemplateName = ‘MyTemplate’
$Version = ‘1.1.1.1’
Protect-ServerVHDX -Path $TemplatePath -TemplateName $TemplateName -Version $Version ` -Certificate $certificate
Ngoài ra, có thể sử dụng công cụ Template Disk Wizard để thực hiện với giao diện GUI
Truy cập theo đường dẫn: C:\Windows\System32\TemplateDiskWizard.exe
Tại giao diện Protected Template Disk Creation Wizard
Chọn > Next
Chọn Browse đến vị trí lưu trữ File VHDX
Khai báo thông tin Disk name và Version, sau đó chọn Next
Cuối cùng kiểm tra thông tin cấu hình và chọn Generate

 

Generate a PDK File

Các thao tác được thực hiện trên giao diện Microsoft PowerShell

Sau khi HGS được cấu hình, “Guardian Key Metadata” có thể được truy cập tại URL sau:
“http://$HGSDomain/KeyProtection/service/metadata/2014-07/metadata.xml”
Create a HGS guardian:
$url=“http://$HGSDomain/KeyProtection/service/metadata/2014-07/metadata.xml”
(New-Object System.Net.WebClient).DownloadFile($url, $GuardianMetadataPath)
New-HgsGuardianName $OwnerName -GenerateCertificates
Import-HgsGuardian -Path $GuardianMetadataPath -Name $GuardianName -AllowUntrustedRoot
Extract the VSC file from the signed disk template: (Tham chiếu file VSC từ disk template)
$TemplatePath = ‘C:\protected_template.vhdx’
$VSCPath = ‘c:\vsc.vsc’
# The VSC file describes the template that the .PDK file can be applied to
Save-VolumeSignatureCatalog -TemplateDiskPath $signedTemplate `
-VolumeSignatureCatalogPath $VSCPath
Khởi tạo “remote desktop certificate” đăng nhập từ xa vào các Shielded VMs theo thông tin file (.PFX)
# $rdpcertificate.thumbprint will be added in the unattended file
$rdpcertificate = New-SelfSignedCertificate -DnsName ts.examplerdpcertificate.com `
-CertStoreLocation $certStoreLocation -KeyExportPolicy Exportable
$rdpcertificatepassword = ConvertTo-SecureString -AsPlainText $rdpCertPasswd -Force Export-PfxCertificate -Cert
$rdpcertificate -Password $rdpcertificatepassword ` -FilePath $rdpPath
$rdpcertificate.thumbprint
Generate a pdk file:
$owner = Get-HgsGuardian -Name $OwnerName
$guardian = Get-HgsGuardian -Name $GuardianName
# Policy can be either EncryptionSupported or Shielded
Protect-ShieldingDataFile -ShieldingDataFilePath $PdkOutputPath -Owner $owner `
-VolumeIDQualifier (New-VolumeIdQualifier -VolumeSignatureCatalogFilePath $VscPath `
-VersionRule Equals) -WindowsUnattendFile $UnattendedPath -OtherFile $RdpCertPath `
-Guardian $guardian -Policy Shielded
Ngoài ra, có thể sử dụng công cụ Shielding Data File Wizard để thực hiện với giao diện GUI
Truy cập theo đường dẫn: C:\Windows\System32\ShieldingDataFileWizard.exe.
Tại giao diện File and Policy Selection, chọn Create a new shielding data file, Browse đến File pdk
Giao diện Owner and Guardians Chọn như nội dung hình bên dưới
Tại giao diện Volume ID Qualifiers > Chọn Add
Chọn Browse và trỏ về File VSC, cấu hình các thông số như hình
Chọn Next để tiếp tục triển khai
Giao diện Specialization Values, chọn Browse tìm đến File *.xml, tiếp theo chọn Add File RDP.pfx
Kiểm tra lại các thông tin và chọn Generate để khởi tạo

Boot a Shielded VM:

$vm = New-VM -Name $VMName -Generation 2 -VHDPath $TemplateVhdxPath -SwitchName “external”
$pdk = Invoke-CimMethod -ClassName Msps_ProvisioningFileProcessor -Namespace root\msps `
-MethodName PopulateFromFile -Arguments @{FilePath=$pdkFilePath }
# the Key Protector contains the data regarding guarded hosts
# it’s mandatory to pass a KeyProtector in order to enable the vtpm
$kp = $pdk.ProvisioningFile.KeyProtector
$vm | Set-VMKeyProtector -KeyProtector $kp
# If during generating the pdk, the Policy was set to Shielded then $isShielded is $True
$vm | Set-VMSecurityPolicy -Shielded $isShielded
$vm | Enable-VMTPM
# The unattended file can contain substitution strings for ComputerName, TimeZone, ProductKey.
# The corresponding values or SpecializationDataPairs must be specified and will be added to a .fsk file
New-ShieldedVMSpecializationDataFile -ShieldedVMSpecializationDataFilePath $fskFilePath `
-SpecializationDataPairs @{“@@ComputerName@@”=“MyNewComputer”; `
“@@TimeZone@@”=“Pacific Standard Time”}
Initialize-ShieldedVM -ShieldingDataFilePath $pdkFilePath `
-ShieldedVMSpecializationDataFilePath $fskFilePath `
-VirtualMachine $vm
Kiểm tra cài đặt của VM, thấy rằng VM được bảo vệ. VM có thể được di chuyển trên bất kỳ Host nào, nhưng chỉ những Guarded Host mới có quyền truy cập vào dữ liệu của VM.
Bài viết công nghệ: