本文介绍如何使用 Azure CLI 在 Azure Virtual Network Manager 中创建跨租户连接。 跨租户支持使组织能够使用中心网络管理器跨租户和订阅管理虚拟网络。
首先,在中央网络管理器上创建范围连接。 然后,在连接租户上创建网络管理器连接并验证连接。 最后,添加来自不同租户的虚拟网络并验证。 完成所有任务后,你可以从网络管理器集中管理其他租户的资源。
先决条件
- 两个具有要通过 Azure Virtual Network Manager 管理的虚拟网络的 Azure 租户。 本文中,“租户”一词指的是以下内容:
- 中央管理租户:安装了Azure Virtual Network Manager实例的租户,以及从跨租户连接集中管理网络组的位置。
- 目标托管租户:包含要管理的虚拟网络的租户。 此租户连接到中央管理租户。
- 部署在中心管理租户中的 Azure 虚拟网络管理器
- 参见跨租户连接 所需的权限 。
在设置权限方面需要帮助? 了解如何 在 Azure 门户中将用户角色分配给资源。
在网络管理器中创建范围连接
范围连接的创建始于已部署网络管理器的中央管理租户。 这是你计划在其中跨租户管理所有资源的网络管理器。
在此任务中,你将设置范围连接,以添加来自目标租户的订阅。 使用目标网络管理器的订阅 ID 和租户 ID。 如果要使用管理组,请将 --resource-id 参数修改为类似于 /providers/Microsoft.Management/managementGroups/{mgId}。
# Create a scope connection in the network manager in the central management tenant
az network manager scope-connection create --resource-group "myRG" --network-manager-name "myAVNM" --name "ToTargetManagedTenant" --description "This is a connection to manage resources in the target managed tenant" --resource-id "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e" --tenant-id "aaaabbbb-0000-cccc-1111-dddd2222eeee"
在其他租户中的订阅上创建网络管理器连接
请在目标托管租户中运行本节中的命令,而不是在中央管理租户中运行。 这些命令会在托管租户中的某个订阅上创建一个网络管理器连接,使其指回中央管理租户中的网络管理器。 这个连接完成了你与示波器连接开始的配对。 还可以验证连接状态。
输入以下命令,使用你的管理帐户连接到目标托管租户:
# Log in to the target managed tenant # Change the --tenant value to the appropriate tenant ID az cloud set -n AzureChinaCloud az login --tenant "aaaabbbb-0000-cccc-1111-dddd2222eeee"根据你所在组织的策略完成身份验证。
输入以下命令以设置订阅,并创建回连到中央管理租户的连接。 订阅内容与前一步范围连接所提到的相同。
# Set the Azure subscription az account set --subscription aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e # Create a cross-tenant connection to the central management tenant az network manager connection subscription create --connection-name "toCentralManagementTenant" --description "This connection allows management of the tenant by a central management tenant" --network-manager-id "/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e/resourceGroups/myRG/providers/Microsoft.Network/networkManagers/myAVNM"
验证连接状态
输入以下命令以检查连接状态:
# Check connection status az network manager connection subscription show --name "toCentralManagementTenant"切换回中央管理租户。 对网络管理器使用
show命令,以显示通过该属性为跨租户范围添加的订阅:# View the subscription added to the network manager az network manager show --resource-group myAVNMResourceGroup --name myAVNM
将静态成员添加到网络组
在此任务中,你将通过静态成员资格把跨租户虚拟网络添加到网络组中。 在以下命令中,虚拟网络订阅与之前创建连接时引用的订阅相同。
# Create a network group with a static member from the target managed tenant
az network manager group static-member create --network-group-name "CrossTenantNetworkGroup" --network-manager-name "myAVNM" --resource-group "myAVNMResourceGroup" --static-member-name "targetVnet01" --resource-id="/subscriptions/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e
/resourceGroups/myScopeAVNM/providers/Microsoft.Network/virtualNetworks/targetVnet01"
删除网络管理器配置
将虚拟网络添加到网络组后,应用配置。 若要删除静态成员或跨租户资源,请使用相应的 delete 命令:
# Delete the static member group
az network manager group static-member delete --network-group-name "CrossTenantNetworkGroup" --network-manager-name " myAVNM" --resource-group "myRG" --static-member-name "targetVnet01”
# Delete scope connections
az network manager scope-connection delete --resource-group "myRG" --network-manager-name "myAVNM" --name "ToTargetManagedTenant"
# Switch to a managed tenant if needed
az network manager connection subscription delete --name "toCentralManagementTenant"