如何簽署電腦設定套件
機器設定使用 SHA256 雜湊自訂原則,驗證原則套件並未變更。 客戶也可選擇性地使用憑證來簽署套件,並強制機器設定延伸模組只允許已簽署的內容。
若要啟用此案例,您需要完成兩個步驟。 執行 Cmdlet 來簽署內容套件,並將標籤附加至需要簽署程式碼的電腦上。
使用程式碼簽署憑證進行簽章驗證
若要使用簽章驗證功能,請執行 Protect-GuestConfigurationPackage
Cmdlet,以在套件發佈之前進行簽署。 此 Cmdlet 需要「程式碼簽署」憑證。 如果您沒有「程式碼簽署」憑證,請使用下列指令碼建立自我簽署憑證以供測試之用,並遵循此範例。
Windows 簽章驗證
# How to create a self sign cert and use it to sign Machine Configuration
# custom policy package
# Create Code signing cert
$codeSigningParams = @{
Type = 'CodeSigningCert'
DnsName = 'GCEncryptionCertificate'
HashAlgorithm = 'SHA256'
}
$mycert = New-SelfSignedCertificate @codeSigningParams
# Export the certificates
$mypwd = ConvertTo-SecureString -String "Password1234" -Force -AsPlainText
$mycert | Export-PfxCertificate -FilePath C:\demo\GCPrivateKey.pfx -Password $mypwd
$mycert | Export-Certificate -FilePath "C:\demo\GCPublicKey.cer" -Force
# Import the certificate
$importParams = @{
FilePath = 'C:\demo\GCPrivateKey.pfx'
Password = $mypwd
CertStoreLocation = 'Cert:\LocalMachine\My'
}
Import-PfxCertificate @importParams
# Sign the policy package
$certToSignThePackage = Get-ChildItem -Path cert:\LocalMachine\My |
Where-Object { $_.Subject-eq "CN=GCEncryptionCertificate" }
$protectParams = @{
Path = 'C:\demo\AuditWindowsService.zip'
Certificate = $certToSignThePackage
Verbose = $true
}
Protect-GuestConfigurationPackage @protectParams
Linux 簽章驗證
# generate gpg key
gpg --gen-key
# export public key
gpg --output public.gpg --export <email-id-used-to-generate-gpg-key>
# export private key
gpg --output private.gpg --export-secret-key <email-id-used-to-generate-gpg-key>
# Sign linux policy package
Import-Module GuestConfiguration
$protectParams = @{
Path = './not_installed_application_linux.zip'
PrivateGpgKeyPath = './private.gpg'
PublicGpgKeyPath = './public.gpg'
Verbose = $true
}
Protect-GuestConfigurationPackage
Protect-GuestConfigurationPackage
Cmdlet 的參數:
- 路徑:機器設定套件的完整路徑。
- 憑證:用來簽署套件的程式碼簽署憑證。 只有在簽署 Windows 的內容時,才支援此參數。
憑證需求
機器設定代理程式預期憑證公開金鑰會出現在 Windows 電腦上以及 Linux 電腦路徑 /usr/local/share/ca-certificates/gc
的「受信任的發行者」中。 若要讓節點驗證已簽署的內容,請先在電腦上安裝憑證公開金鑰,再套用自訂原則。 此流程可使用 VM 內的任何技術、或使用 Azure 原則來完成。 範例範本可用來部署具有憑證的機器 (英文)。 Key Vault 存取原則必須允許計算資源提供者在部署期間存取憑證。 如需詳細步驟,請參閱在 Azure Resource Manager 中設定虛擬機器的 Key Vault。
下列是從簽署憑證匯出公開金鑰,以匯入到電腦的範例。
$Cert = Get-ChildItem -Path cert:\LocalMachine\My |
Where-Object { $_.Subject-eq "CN=mycert3" } |
Select-Object -First 1
$Cert | Export-Certificate -FilePath "$env:temp\DscPublicKey.cer" -Force
標籤需求
發佈內容之後,請將標籤 (名稱為 GuestConfigPolicyCertificateValidation
且值為 enabled
) 附加至需要程式碼簽署的所有虛擬機器。 如需如何使用 Azure 原則大規模傳遞標籤的詳細說明,請參閱標籤範例。 備妥此標籤後,使用 New-GuestConfigurationPolicy
Cmdlet 產生的原則定義就會透過機器設定延伸模組來啟用需求。
相關內容
- 使用
GuestConfiguration
模組來為您的環境建立大規模管理的 Azure 原則定義。 - 使用 Azure 入口網站指派您的自訂原則定義。
- 了解如何檢視機器設定的合規性詳細資料原則指派。
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應