快速开始 - 创建网络安全边界 - Bicep

使用 Bicep 为 Azure Key Vault 创建网络安全边界,开始设置网络安全边界。 网络安全外围允许 Azure 平台即服务(PaaS)资源在显式受信任的边界内通信。 在网络安全外围配置文件中创建和更新 PaaS 资源的关联。 然后,创建和更新网络安全外围访问规则。 完成后,请删除在本快速入门中创建的所有资源。

Bicep 是一种特定于域的语言 (DSL),使用声明性语法来部署 Azure 资源。 它提供简明的语法、可靠的类型安全性以及对代码重用的支持。 Bicep 会针对你的 Azure 基础结构即代码解决方案提供最佳创作体验。

还可以使用 Azure 门户Azure PowerShellAzure CLI 创建网络安全外围。

重要

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

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

先决条件

查阅 Bicep 文件

此 Bicep 文件为 Azure Key Vault 实例创建网络安全外围。

本快速入门使用的 Bicep 文件来自 Azure 快速入门模板

param location string = resourceGroup().location
param keyVaultName string = 'kv-${uniqueString(resourceGroup().id)}'
param nspName string = 'networkSecurityPerimeter'
param profileName string = 'profile1'
param inboundIpv4AccessRuleName string = 'inboundRule'
param outboundFqdnAccessRuleName string = 'outboundRule'
param associationName string = 'networkSecurityPerimeterAssociation'

resource keyVault 'Microsoft.KeyVault/vaults@2022-07-01' = {
    name: keyVaultName
    location: location
    properties: {
        sku: {
            family: 'A'
            name: 'standard'
        }
        tenantId: subscription().tenantId
        accessPolicies: []
        enabledForDeployment: false
        enabledForDiskEncryption: false
        enabledForTemplateDeployment: false
        enableSoftDelete: true
        softDeleteRetentionInDays: 90
        enableRbacAuthorization: false
    }
}

resource networkSecurityPerimeter 'Microsoft.Network/networkSecurityPerimeters@2023-07-01-preview' = {
    name: nspName
    location: location
    properties: {}
}

resource profile 'Microsoft.Network/networkSecurityPerimeters/profiles@2023-07-01-preview' = {
    parent: networkSecurityPerimeter
    name: profileName
    location: location
    properties: {}
}

resource inboundAccessRule 'Microsoft.Network/networkSecurityPerimeters/profiles/accessRules@2023-07-01-preview' = {
    parent: profile
    name: inboundIpv4AccessRuleName
    location: location
    properties: {
        direction: 'Inbound'
        addressPrefixes: [
            '100.10.0.0/16'
        ]
        fullyQualifiedDomainNames: []
        subscriptions: []
        emailAddresses: []
        phoneNumbers: []
    }
}

resource outboundAccessRule 'Microsoft.Network/networkSecurityPerimeters/profiles/accessRules@2023-07-01-preview' = {
    parent: profile
    name: outboundFqdnAccessRuleName
    location: location
    properties: {
        direction: 'Outbound'
        addressPrefixes: []
        fullyQualifiedDomainNames: [
            'contoso.com'
        ]
        subscriptions: []
        emailAddresses: []
        phoneNumbers: []
    }
}

resource resourceAssociation 'Microsoft.Network/networkSecurityPerimeters/resourceAssociations@2023-07-01-preview' = {
    parent: networkSecurityPerimeter
    name: associationName
    location: location
    properties: {
        privateLinkResource: {
            id: keyVault.id
        }
        profile: {
            id: profile.id
        }
        accessMode: 'Enforced'
    }
}

Bicep 文件定义多个 Azure 资源:

部署 Bicep 文件

  1. 将该 Bicep 文件另存为本地计算机上的 main.bicep。

  2. 使用 Azure CLI 或 Azure PowerShell 来部署该 Bicep 文件。

    az group create --name resource-group --location chinaeast2
    az deployment group create --resource-group resource-group --template-file main.bicep --parameters
    networkSecurityPerimeterName=<network-security-perimeter-name>
    

验证部署

  1. 登录到 Azure 门户。

  2. 在门户顶部的搜索框中输入 网络安全外围 。 在搜索结果中选择 网络安全外围

  3. 从网络安全外围列表中选择 networkPerimeter 资源。

  4. 验证是否已成功创建 networkPerimeter 资源。 “ 概述 ”页显示网络安全外围的详细信息,包括配置文件和关联的资源。

清理资源

如果不再需要使用网络安全外围服务创建的资源,请删除资源组。 这会删除网络安全外围服务和所有相关资源。

az group delete --name resource-group

注释

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

后续步骤