快速入门:创建网络安全外围 - Azure PowerShell

使用 Azure PowerShell 为 Azure 密钥保管库创建网络安全外围以启动网络安全防护。 网络安全外围允许 Azure 平台即服务(PaaS)资源在显式受信任的边界内通信。 在网络安全外围配置文件中创建和更新 PaaS 资源的关联。 然后,创建和更新网络安全外围访问规则。 完成后,请删除在本快速入门中创建的所有资源。

重要

网络安全边界已在世纪互联运营的以下 Azure 区域全面上线。 有关受支持的服务的信息,请参阅支持的 PaaS 服务的 载入专用链接资源

  • 中国东部 2
  • 中国北部 2
  • 中国北部 3

先决条件

  • 拥有有效订阅的 Azure 帐户。 创建试用版订阅

  • 安装 Az.Tools.Installer 模块:

    # Install the Az.Tools.Installer module    
    Install-Module -Name Az.Tools.Installer -Repository PSGallery
    
  • 安装Az.Network的预览构建版本。

    # Install the preview build of the Az.Network module 
    Install-Module -Name Az.Network -AllowPrerelease -Force -RequiredVersion 7.13.0-preview
    
  • 可以选择在本地使用 Azure PowerShell

  • 若要获取有关 PowerShell cmdlet 的帮助,请使用 Get-Help 以下命令:

    # Get help for a specific command
    Get-Help -Name <powershell-command> - full
    
    # Example
    Get-Help -Name New-AzNetworkSecurityPerimeter - full
    

登录到 Azure 帐户并选择订阅

若要开始配置,请登录到 Azure 帐户:

# Sign in to your Azure account
Connect-AzAccount -Environment AzureChinaCloud

然后,连接到您的订阅服务。

# List all subscriptions
Set-AzContext -Subscription <subscriptionId>

# Register the Microsoft.Network resource provider
Register-AzResourceProvider -ProviderNamespace Microsoft.Network

创建资源组和密钥保管库

必须先创建资源组和密钥保管库资源,然后才能创建网络安全外围。
此示例创建一个名为test-rg的资源组,位于chinaeast2位置,并在该资源组中创建一个名为demo-keyvault-<RandomValue>的密钥保管库,使用以下命令:

# Create a resource group
$rgParams = @{
    Name = "test-rg"
    Location = "chinaeast2"
}
New-AzResourceGroup @rgParams

# Create a key vault
$keyVaultName = "demo-keyvault-$(Get-Random)"
$keyVaultParams = @{
    Name = $keyVaultName
    ResourceGroupName = $rgParams.Name
    Location = $rgParams.Location
}
$keyVault = New-AzKeyVault @keyVaultParams

创建网络安全外围

在此步骤中,使用以下命令 New-AzNetworkSecurityPerimeter 创建网络安全外围:

注释

请勿将任何个人身份或敏感数据放入网络安全外围规则或其他网络安全外围配置中。


# Create a network security perimeter
$nsp = @{ 
        Name = 'demo-nsp' 
        location = 'chinaeast2' 
        ResourceGroupName = $rgParams.name  
        } 

$demoNSP=New-AzNetworkSecurityPerimeter @nsp
$nspId = $demoNSP.Id

创建和更新 PaaS 资源与新配置文件的关联

在此步骤中,你将创建新的配置文件,并使用命令New-AzNetworkSecurityPerimeterProfile将 PaaS 资源、Azure Key Vault 与配置文件New-AzNetworkSecurityPerimeterAssociation相关联。

  1. 使用以下命令为网络安全边界创建新的概况:

    # Create a new profile
    
    $nspProfile = @{ 
        Name = 'nsp-profile' 
        ResourceGroupName = $rgParams.name 
        SecurityPerimeterName = $nsp.name 
        }
    
    $demoProfileNSP=New-AzNetworkSecurityPerimeterProfile @nspprofile
    
  2. 使用以下命令将 Azure Key Vault (PaaS 资源)与网络安全外围配置文件相关联:

    # Associate the PaaS resource with the above created profile
    
    $nspAssociation = @{ 
        AssociationName = 'nsp-association' 
        ResourceGroupName = $rgParams.name 
        SecurityPerimeterName = $nsp.name 
        AccessMode = 'Learning'  
        ProfileId = $demoProfileNSP.Id 
        PrivateLinkResourceId = $keyVault.ResourceID
        }
    
    New-AzNetworkSecurityPerimeterAssociation @nspassociation | format-list
    
  3. 通过使用命令 Update-AzNetworkSecurityPerimeterAssociation 将访问模式更改为 enforced 来更新关联,如下所示:

    # Update the association to enforce the access mode
    $updateAssociation = @{ 
        AssociationName = $nspassociation.AssociationName 
        ResourceGroupName = $rgParams.name 
        SecurityPerimeterName = $nsp.name 
        AccessMode = 'Enforced'
        }
    Update-AzNetworkSecurityPerimeterAssociation @updateAssociation | format-list
    

管理网络安全外围访问规则

在此步骤中,将创建、更新和删除具有公共 IP 前缀的网络安全外围访问规则。

# Create an inbound access rule for a Public IP prefix
$inboundRule = @{ 
    Name = 'nsp-inboundRule' 
    ProfileName = $nspprofile.Name  
    ResourceGroupName = $rgParams.Name  
    SecurityPerimeterName = $nsp.Name  
    Direction = 'Inbound'  
    AddressPrefix = '192.0.2.0/24' 
    } 

New-AzNetworkSecurityPerimeterAccessRule @inboundrule | format-list

# Update the inbound access rule to add more Public IP prefixes
$updateInboundRule = @{ 
    Name = $inboundrule.Name 
    ProfileName = $nspprofile.Name  
    ResourceGroupName = $rgParams.Name  
    SecurityPerimeterName = $nsp.Name  
    AddressPrefix = @('192.0.2.0/24','198.51.100.0/24')
    }
Update-AzNetworkSecurityPerimeterAccessRule @updateInboundRule | format-list

注释

如果未将托管标识分配给支持托管标识的资源,则会拒绝对同一外围中的其他资源的出站访问。 用于允许从此资源访问的基于订阅的入站规则不会生效。

删除所有资源

如果不再需要网络安全外围,请删除与网络安全外围关联的所有资源,删除外围,然后删除资源组。

# Retrieve the network security perimeter and place it in a variable
$nsp= Get-AzNetworkSecurityPerimeter -Name demo-nsp -ResourceGroupName $rg.Params.Name

# Delete the network security perimeter and all associated resources
$removeNsp = @{ 
    Name = 'nsp-association'
    ResourceGroupName = $rgParams.Name
    SecurityPerimeterName = $nsp.Name
    }
Remove-AzNetworkSecurityPerimeterAssociation @removeNsp

Remove-AzNetworkSecurityPerimeter -Name $nsp.Name -ResourceGroupName $rgParams.Name

# Remove the resource group
Remove-AzResourceGroup -Name $rgParams.Name -Force

注释

从网络安全边界删除资源关联会导致访问控制回退到现有的资源防火墙配置。 这可能会导致根据资源防火墙配置允许/拒绝访问。 如果 PublicNetworkAccess 设置为 SecuredByPerimeter 并已删除关联,则资源将进入锁定状态。 有关详细信息,请参阅 过渡到 Azure 中的网络安全边界

后续步骤