你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

Set-AzDiskSecurityProfile

在托管磁盘上设置 SecurityProfile

语法

Set-AzDiskSecurityProfile
   [-Disk] <PSDisk>
   -SecurityType <String>
   [-SecureVMDiskEncryptionSet <String>]
   [-DefaultProfile <IAzureContextContainer>]
   [-WhatIf]
   [-Confirm]
   [<CommonParameters>]

说明

在托管磁盘上设置 SecurityProfile。

示例

示例 1

$diskconfig = New-AzDiskConfig -DiskSizeGB 10 -AccountType PremiumLRS -OsType Windows -CreateOption FromImage;
$image = '/subscriptions/0000000-0000-0000-0000-000000000000/resourceGroups/ResourceGroup01/providers/Microsoft.Compute/images/TestImage123';
$diskconfig = Set-AzDiskImageReference -Disk $diskconfig -Id $image -Lun 0;
$diskconfig = Set-AzDiskSecurityProfile -Disk $diskconfig -SecurityType "TrustedLaunch";
$disk = New-AzDisk -ResourceGroupName 'ResourceGroup01' -DiskName 'Disk01' -Disk $diskconfig;
# $disk.Properties.SecurityProfile.SecurityType == "TrustedLaunch";

客户可以设置托管磁盘的 SecurityType。

示例 2:使用加密类型的磁盘枚举集创建磁盘ConfidentialVM_DiskEncryptedWithCustomerKey

$Location = "northeurope";
$KeyVaultName = "val" + $rgname;
$KeyName = "key" + $rgname;
$DesName= "des" + $rgname;
$KeySize = 3072;

$SecurePassword = "Password" | ConvertTo-SecureString -AsPlainText -Force;
$User = "Username";
$Cred = New-Object System.Management.Automation.PSCredential ($User, $SecurePassword);

New-AzKeyVault -Name $KeyVaultName -Location $Location -ResourceGroupName $ResourceGroupName -Sku Premium -EnablePurgeProtection -EnabledForDiskEncryption;

# Add Key vault Key
Add-AzKeyVaultKey -VaultName $KeyVaultName -Name $KeyName -Size $KeySize -KeyOps wrapKey,unwrapKey -KeyType RSA -Destination HSM -Exportable -UseDefaultCVMPolicy;

# Capture Keyvault and key details
$KeyVaultId = (Get-AzKeyVault -VaultName $KeyVaultName -ResourceGroupName $ResourceGroupName).ResourceId;
$KeyUrl = (Get-AzKeyVaultKey -VaultName $KeyVaultName -KeyName $KeyName).Key.Kid;

# Create new DES Config and DES
$diskEncryptionType = "ConfidentialVmEncryptedWithCustomerKey";
$desConfig = New-AzDiskEncryptionSetConfig -Location $Location -SourceVaultId $keyvaultId -KeyUrl $keyUrl -IdentityType SystemAssigned -EncryptionType $diskEncryptionType;
New-AzDiskEncryptionSet -ResourceGroupName $ResourceGroupName -Name $DesName -DiskEncryptionSet $desConfig;
$diskencset = Get-AzDiskEncryptionSet -ResourceGroupName $ResourceGroupName -Name $desName;

# Assign DES Access Policy to key vault
$desIdentity = (Get-AzDiskEncryptionSet -Name $DesName -ResourceGroupName $ResourceGroupName).Identity.PrincipalId;
Set-AzKeyVaultAccessPolicy -VaultName $KeyVaultName -ResourceGroupName $ResourceGroupName -ObjectId $desIdentity -PermissionsToKeys wrapKey,unwrapKey,get -BypassObjectIdValidation;

$diskSecurityType = "ConfidentialVM_DiskEncryptedWithCustomerKey";
$diskName = "diskname";
$diskconfig = New-AzDiskConfig -AccountType Premium_LRS -OsType Windows -CreateOption FromImage -Location $Location;
$diskconfig = Set-AzDiskImageReference -Disk $diskconfig -Id "/Subscriptions/e37510d7-33b6-4676-886f-ee75bcc01871/Providers/Microsoft.Compute/Locations/northeurope/Publishers/MicrosoftWindowsServer/ArtifactTypes/VMImage/Offers/windows-cvm/Skus/2019-datacenter-cvm/Versions/latest";
$diskconfig = Set-AzDiskSecurityProfile -Disk $diskconfig -SecurityType $diskSecurityType -SecureVMDiskEncryptionSet $diskencset.id;
New-AzDisk -ResourceGroupName $ResourceGroupName -DiskName $diskName -Disk $diskconfig;
$disk = Get-AzDisk -ResourceGroupName $ResourceGroupName -DiskName $diskName;
# Verify the SecurityType value.
# $disk.Properties.SecurityProfile.SecurityType returns "ConfidentialVM";

示例 3:将 SecurityType 设置为标准,以避免 TrustedLaunch 默认值。

$rgname = <Resource Group Name>;
$loc = <Azure Region>;
New-AzResourceGroup -Name $rgname -Location $loc -Force;
$securityTypeStnd = "Standard";

# Standard SecurityType
$diskconfig = New-AzDiskConfig -Location $loc -DiskSizeGB 1 -AccountType "Premium_LRS" -OsType "Windows" -CreateOption "Empty" -HyperVGeneration "V1";
$diskname = "diskstnd" + $rgname;
$diskconfig = Set-AzDiskSecurityProfile -Disk $diskconfig -SecurityType $securityTypeStnd;
$diskPr = New-AzDisk -ResourceGroupName $rgname -DiskName $diskname -Disk $diskconfig;
$disk = Get-AzDisk -ResourceGroupName $rgname -DiskName $diskname;
# Verify $disk.SecurityProfile is null;

参数

-Confirm

提示你在运行 cmdlet 之前进行确认。

类型:SwitchParameter
别名:cf
Position:Named
默认值:None
必需:False
接受管道输入:False
接受通配符:False

-DefaultProfile

用于与 Azure 通信的凭据、帐户、租户和订阅。

类型:IAzureContextContainer
别名:AzContext, AzureRmContext, AzureCredential
Position:Named
默认值:None
必需:False
接受管道输入:False
接受通配符:False

-Disk

磁盘安全配置文件

类型:PSDisk
别名:DiskSecurityProfile
Position:0
默认值:None
必需:True
接受管道输入:True
接受通配符:False

-SecureVMDiskEncryptionSet

用于启用静态加密的磁盘加密集的 ResourceId。

类型:String
Position:Named
默认值:None
必需:False
接受管道输入:True
接受通配符:False

-SecurityType

磁盘的安全类型

类型:String
Position:Named
默认值:None
必需:True
接受管道输入:True
接受通配符:False

-WhatIf

显示运行该 cmdlet 时会发生什么情况。 cmdlet 未运行。

类型:SwitchParameter
别名:wi
Position:Named
默认值:None
必需:False
接受管道输入:False
接受通配符:False

输入

PSDisk

String

输出

PSDisk