使用 专用链接 限制托管磁盘的导入和导出访问

适用于: ✔️ Linux 虚拟机 ✔️ Windows 虚拟机 ✔️ 灵活规模集

使用 专用终结点 限制托管磁盘导入和导出。 通过 Azure 虚拟网络中的客户端,使用 Azure 专用链接 安全地访问数据。 专用终结点为托管磁盘服务使用虚拟网络地址空间中的 IP 地址。 虚拟网络中的客户端与托管磁盘之间的流量会保留在虚拟网络以及 Microsoft 主干网络上的专用链路内,从而减少暴露于公共互联网的风险。

本文介绍如何使用Azure CLI或Azure PowerShell为托管磁盘导入和导出配置专用链接。 创建磁盘访问资源,并通过创建专用终结点将其链接到同一订阅中的虚拟网络。 然后将磁盘或快照与磁盘访问资源相关联。 最后,将磁盘或快照的网络访问策略设置为 AllowPrivate 限制对虚拟网络的访问。

将网络访问策略设置为 DenyAll,以防止任何人从磁盘或快照中导出数据。 默认网络访问策略为 AllowAll

先决条件

在开始之前,请安装最新的Azure CLIAzure PowerShell模块

局限性

  • 不能使用相同的磁盘访问资源同时导入或导出 100 多个磁盘或快照
  • 不能将数据上传到同时具有磁盘访问资源和磁盘加密集的磁盘
  • 除了应用于单个磁盘的缩放目标外,磁盘访问资源还具有更多的缩放目标,这些目标以数据入口/出口为中心。 这些限制累积应用于与磁盘访问资源关联的所有磁盘。 有关详细信息,请参阅 此处
  • 磁盘访问资源必须与其关联的磁盘所在的区域和订阅相同。

登录并设置变量

选择一个选项卡以使用Azure CLI或Azure PowerShell。 为订阅、资源组、区域、磁盘访问资源、虚拟网络、子网、专用终结点和专用 DNS 区域设置值。 其余过程重复使用这些变量。 若要创建受保护的快照,请提供现有源磁盘的名称和新快照的名称。

subscriptionId=yourSubscriptionId
resourceGroupName=yourResourceGroupName
region=chinanorth2
diskAccessName=yourDiskAccessForPrivateLink
vnetName=yourVnetForPrivateLink
subnetName=yourSubnetForPrivateLink
privateEndpointName=yourPrivateEndpointForSecureMDExportImport
privateEndpointConnectionName=yourPrivateEndpointConnection
privateDnsZoneName=privatelink.blob.core.chinacloudapi.cn
privateDnsZoneLinkName=yourDnsLink
privateDnsZoneGroupName=yourZoneGroup

# The name of an existing disk that is the source of the snapshot.
sourceDiskName=yourSourceDiskForSnapshot

# The name of the new snapshot secured with Private Link.
snapshotNameSecuredWithPrivateLink=yourSnapshotNameSecuredWithPrivateLink

az cloud set -n AzureChinaCloud
az login
az account set --subscription $subscriptionId

创建磁盘访问资源

使用前面定义的资源组、区域和磁盘访问资源名称。 az disk-access create 命令创建磁盘访问资源。 然后,az disk-access show 将其资源 ID 存储在 $diskAccessId 中,供后续步骤使用。

az disk-access create -n $diskAccessName -g $resourceGroupName -l $region

diskAccessId=$(az disk-access show -n $diskAccessName -g $resourceGroupName --query [id] -o tsv)

创建虚拟网络

专用终结点不支持网络安全组(NSG)等网络策略。 若要在子网上部署专用终结点,请在该子网上禁用专用终结点网络策略。

使用前面定义的资源组、虚拟网络和子网名称。 az network vnet create 命令创建虚拟网络和子网。 然后,az network vnet subnet update 会禁用该子网上的专用终结点网络策略。

az network vnet create --resource-group $resourceGroupName \
    --name $vnetName \
    --subnet-name $subnetName

az network vnet subnet update --resource-group $resourceGroupName \
    --name $subnetName \
    --vnet-name $vnetName \
    --private-endpoint-network-policies Disabled

为磁盘访问资源创建专用终结点

使用前面定义的资源组、专用终结点、虚拟网络、子网和连接名称。 此过程还使用磁盘访问资源过程中的 $diskAccessIdaz network private-endpoint create 命令为磁盘访问资源创建专用终结点。

az network private-endpoint create --resource-group $resourceGroupName \
    --name $privateEndpointName \
    --vnet-name $vnetName \
    --subnet $subnetName \
    --private-connection-resource-id $diskAccessId \
    --group-ids disks \
    --connection-name $privateEndpointConnectionName

配置专用 DNS 区域

为存储 Blob 域创建专用 DNS 区域,创建虚拟网络链接,然后创建将专用终结点与专用 DNS 区域关联的 DNS 区域组。

使用前面定义的资源组、专用 DNS 区域、虚拟网络链接、专用终结点和 DNS 区域组名称。 以下命令创建专用 DNS 区域,将其链接到虚拟网络,并将其与专用终结点相关联。

az network private-dns zone create --resource-group $resourceGroupName \
    --name $privateDnsZoneName

az network private-dns link vnet create --resource-group $resourceGroupName \
    --zone-name $privateDnsZoneName \
    --name $privateDnsZoneLinkName \
    --virtual-network $vnetName \
    --registration-enabled false

az network private-endpoint dns-zone-group create \
   --resource-group $resourceGroupName \
    --endpoint-name $privateEndpointName \
   --name $privateDnsZoneGroupName \
   --private-dns-zone $privateDnsZoneName \
   --zone-name disks

定义此过程的托管磁盘名称、存储 SKU 和大小。 此过程重复使用前面定义的资源组、区域和磁盘访问资源名称。 az disk create 命令创建一个空托管磁盘,将其与磁盘访问资源相关联,并将其网络访问策略设置为 AllowPrivate

# These variables are specific to this step.
diskName=yourDiskName
diskSkuName=Standard_LRS
diskSizeGB=128

diskAccessId=$(az resource show -n $diskAccessName -g $resourceGroupName --namespace Microsoft.Compute --resource-type diskAccesses --query [id] -o tsv)

az disk create -n $diskName \
    -g $resourceGroupName \
    -l $region \
    --size-gb $diskSizeGB \
    --sku $diskSkuName \
    --network-access-policy AllowPrivate \
    --disk-access $diskAccessId

使用前面定义的现有源磁盘、新快照、资源组、区域和磁盘访问资源名称。 az disk show 命令获取源磁盘 ID。 然后, az snapshot create 创建快照,将其与磁盘访问资源相关联,并将其网络访问策略设置为 AllowPrivate

# This step reuses variables defined in the first CLI sample.

diskId=$(az disk show -n $sourceDiskName -g $resourceGroupName --query [id] -o tsv)

diskAccessId=$(az resource show -n $diskAccessName -g $resourceGroupName --namespace Microsoft.Compute --resource-type diskAccesses --query [id] -o tsv)

az snapshot create -n $snapshotNameSecuredWithPrivateLink \
    -g $resourceGroupName \
    -l $region \
    --source $diskId \
    --network-access-policy AllowPrivate \
    --disk-access $diskAccessId

后续步骤