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

Microsoft.NetworkSecurityGroups/securityRules

言论

有关创建网络安全组的指导,请参阅 使用 Bicep创建虚拟网络资源。

Bicep 资源定义

可以使用目标操作部署 networkSecurityGroups/securityRules 资源类型:

有关每个 API 版本中已更改属性的列表,请参阅 更改日志

资源格式

若要创建 Microsoft.Network/networkSecurityGroups/securityRules 资源,请将以下 Bicep 添加到模板。

resource symbolicname 'Microsoft.Network/networkSecurityGroups/securityRules@2025-07-01' = {
  parent: resourceSymbolicName
  name: 'string'
  properties: {
    access: 'string'
    description: 'string'
    destinationAddressPrefix: 'string'
    destinationAddressPrefixes: [
      'string'
    ]
    destinationApplicationSecurityGroups: [
      {
        id: 'string'
        location: 'string'
        properties: {}
        tags: {
          {customized property}: 'string'
        }
      }
    ]
    destinationPortRange: 'string'
    destinationPortRanges: [
      'string'
    ]
    direction: 'string'
    priority: int
    protocol: 'string'
    sourceAddressPrefix: 'string'
    sourceAddressPrefixes: [
      'string'
    ]
    sourceApplicationSecurityGroups: [
      {
        id: 'string'
        location: 'string'
        properties: {}
        tags: {
          {customized property}: 'string'
        }
      }
    ]
    sourcePortRange: 'string'
    sourcePortRanges: [
      'string'
    ]
  }
}

属性值

Microsoft.Network/networkSecurityGroups/securityRules

名字 描述 价值
名字 资源名称 string (必需)
父级 在 Bicep 中,可以为子资源指定父资源。 仅当子资源在父资源外部声明时,才需要添加此属性。

有关详细信息,请参阅 父资源外部的子资源
类型资源的符号名称:networkSecurityGroups
性能 安全规则的属性。 CommonSecurityRuleProperties格式

CommonApplicationSecurityGroup

名字 描述 价值
身份证 资源 ID。 字符串
位置 资源位置。 字符串
性能 应用程序安全组的属性。 CommonApplicationSecurityGroupPropertiesFormat
标签 资源标记。 CommonResourceTags

CommonApplicationSecurityGroupPropertiesFormat

名字 描述 价值

CommonResourceTags

名字 描述 价值

CommonSecurityRuleProperties格式

名字 描述 价值
访问 允许或拒绝网络流量。 “允许”
“拒绝”(必需)
描述 此规则的说明。 限制为 140 个字符。 字符串
destinationAddressPrefix 的 目标地址前缀。 CIDR 或目标 IP 范围。 星号“*”还可用于匹配所有源 IP。 也可以使用默认标记,例如“VirtualNetwork”、“AzureLoadBalancer”和“Internet”。 字符串
destinationAddress前缀 目标地址前缀。 CIDR 或目标 IP 范围。 字符串[]
destinationApplicationSecurityGroups 指定为目标的应用程序安全组。 CommonApplicationSecurityGroup[]
destinationPortRange 目标端口或范围。 介于 0 和 65535 之间的整数或范围。 星号“*”也可用于匹配所有端口。 字符串
destinationPortRanges 目标端口范围。 字符串[]
方向 规则的方向。 该方向指定在传入或传出流量上是否评估规则。 “Inbound”
“出站”(必需)
优先权 规则的优先级。 该值可以介于 100 和 4096 之间。 对于集合中的每个规则,优先级编号必须是唯一的。 优先级编号越低,规则优先级越高。 int (必需)
协议 此规则适用于的网络协议。 '*'
“Ah”
“Esp”
“Icmp”
“Tcp”
“Udp”(必需)
sourceAddressPrefix 的 CIDR 或源 IP 范围。 星号“*”还可用于匹配所有源 IP。 也可以使用默认标记,例如“VirtualNetwork”、“AzureLoadBalancer”和“Internet”。 如果这是入口规则,则指定网络流量的来源。 字符串
sourceAddress前缀 CIDR 或源 IP 范围。 字符串[]
sourceApplicationSecurityGroups 指定为源的应用程序安全组。 CommonApplicationSecurityGroup[]
sourcePortRange 源端口或范围。 介于 0 和 65535 之间的整数或范围。 星号“*”也可用于匹配所有端口。 字符串
sourcePort范围 源端口范围。 字符串[]

用法示例

Bicep 示例

部署网络安全规则的基本示例。

param resourceName string = 'acctest0001'
param location string = 'westeurope'

resource networkSecurityGroup 'Microsoft.Network/networkSecurityGroups@2022-07-01' = {
  name: 'mi-security-group1-230630034008554952'
  location: location
  properties: {
    securityRules: []
  }
}

resource securityRule 'Microsoft.Network/networkSecurityGroups/securityRules@2022-09-01' = {
  name: 'allow_management_inbound'
  parent: networkSecurityGroup
  properties: {
    access: 'Allow'
    destinationAddressPrefix: '*'
    destinationPortRange: ''
    destinationPortRanges: [
      '9000'
      '1438'
      '1440'
      '9003'
      '1452'
    ]
    direction: 'Inbound'
    priority: 106
    protocol: 'Tcp'
    sourceAddressPrefix: '*'
    sourcePortRange: '*'
  }
}

ARM 模板资源定义

可以使用目标操作部署 networkSecurityGroups/securityRules 资源类型:

有关每个 API 版本中已更改属性的列表,请参阅 更改日志

资源格式

若要创建 Microsoft.Network/networkSecurityGroups/securityRules 资源,请将以下 JSON 添加到模板。

{
  "type": "Microsoft.Network/networkSecurityGroups/securityRules",
  "apiVersion": "2025-07-01",
  "name": "string",
  "properties": {
    "access": "string",
    "description": "string",
    "destinationAddressPrefix": "string",
    "destinationAddressPrefixes": [ "string" ],
    "destinationApplicationSecurityGroups": [
      {
        "id": "string",
        "location": "string",
        "properties": {
        },
        "tags": {
          "{customized property}": "string"
        }
      }
    ],
    "destinationPortRange": "string",
    "destinationPortRanges": [ "string" ],
    "direction": "string",
    "priority": "int",
    "protocol": "string",
    "sourceAddressPrefix": "string",
    "sourceAddressPrefixes": [ "string" ],
    "sourceApplicationSecurityGroups": [
      {
        "id": "string",
        "location": "string",
        "properties": {
        },
        "tags": {
          "{customized property}": "string"
        }
      }
    ],
    "sourcePortRange": "string",
    "sourcePortRanges": [ "string" ]
  }
}

属性值

Microsoft.Network/networkSecurityGroups/securityRules

名字 描述 价值
apiVersion API 版本 '2025-07-01'
名字 资源名称 string (必需)
性能 安全规则的属性。 CommonSecurityRuleProperties格式
类型 资源类型 “Microsoft.Network/networkSecurityGroups/securityRules”

CommonApplicationSecurityGroup

名字 描述 价值
身份证 资源 ID。 字符串
位置 资源位置。 字符串
性能 应用程序安全组的属性。 CommonApplicationSecurityGroupPropertiesFormat
标签 资源标记。 CommonResourceTags

CommonApplicationSecurityGroupPropertiesFormat

名字 描述 价值

CommonResourceTags

名字 描述 价值

CommonSecurityRuleProperties格式

名字 描述 价值
访问 允许或拒绝网络流量。 “允许”
“拒绝”(必需)
描述 此规则的说明。 限制为 140 个字符。 字符串
destinationAddressPrefix 的 目标地址前缀。 CIDR 或目标 IP 范围。 星号“*”还可用于匹配所有源 IP。 也可以使用默认标记,例如“VirtualNetwork”、“AzureLoadBalancer”和“Internet”。 字符串
destinationAddress前缀 目标地址前缀。 CIDR 或目标 IP 范围。 字符串[]
destinationApplicationSecurityGroups 指定为目标的应用程序安全组。 CommonApplicationSecurityGroup[]
destinationPortRange 目标端口或范围。 介于 0 和 65535 之间的整数或范围。 星号“*”也可用于匹配所有端口。 字符串
destinationPortRanges 目标端口范围。 字符串[]
方向 规则的方向。 该方向指定在传入或传出流量上是否评估规则。 “Inbound”
“出站”(必需)
优先权 规则的优先级。 该值可以介于 100 和 4096 之间。 对于集合中的每个规则,优先级编号必须是唯一的。 优先级编号越低,规则优先级越高。 int (必需)
协议 此规则适用于的网络协议。 '*'
“Ah”
“Esp”
“Icmp”
“Tcp”
“Udp”(必需)
sourceAddressPrefix 的 CIDR 或源 IP 范围。 星号“*”还可用于匹配所有源 IP。 也可以使用默认标记,例如“VirtualNetwork”、“AzureLoadBalancer”和“Internet”。 如果这是入口规则,则指定网络流量的来源。 字符串
sourceAddress前缀 CIDR 或源 IP 范围。 字符串[]
sourceApplicationSecurityGroups 指定为源的应用程序安全组。 CommonApplicationSecurityGroup[]
sourcePortRange 源端口或范围。 介于 0 和 65535 之间的整数或范围。 星号“*”也可用于匹配所有端口。 字符串
sourcePort范围 源端口范围。 字符串[]

用法示例

Azure 快速入门模板

以下 Azure 快速入门模板 部署此资源类型。

模板 描述
部署 Darktrace 自动缩放 vSensors

部署到 Azure
此模板允许你部署 Darktrace vSensors 的自动自动缩放部署

Terraform (AzAPI 提供程序)资源定义

可以使用目标操作部署 networkSecurityGroups/securityRules 资源类型:

  • 资源组

有关每个 API 版本中已更改属性的列表,请参阅 更改日志

资源格式

若要创建 Microsoft.Network/networkSecurityGroups/securityRules 资源,请将以下 Terraform 添加到模板。

resource "azapi_resource" "symbolicname" {
  type = "Microsoft.Network/networkSecurityGroups/securityRules@2025-07-01"
  name = "string"
  parent_id = "string"
  body = {
    properties = {
      access = "string"
      description = "string"
      destinationAddressPrefix = "string"
      destinationAddressPrefixes = [
        "string"
      ]
      destinationApplicationSecurityGroups = [
        {
          id = "string"
          location = "string"
          properties = {
          }
          tags = {
            {customized property} = "string"
          }
        }
      ]
      destinationPortRange = "string"
      destinationPortRanges = [
        "string"
      ]
      direction = "string"
      priority = int
      protocol = "string"
      sourceAddressPrefix = "string"
      sourceAddressPrefixes = [
        "string"
      ]
      sourceApplicationSecurityGroups = [
        {
          id = "string"
          location = "string"
          properties = {
          }
          tags = {
            {customized property} = "string"
          }
        }
      ]
      sourcePortRange = "string"
      sourcePortRanges = [
        "string"
      ]
    }
  }
}

属性值

Microsoft.Network/networkSecurityGroups/securityRules

名字 描述 价值
名字 资源名称 string (必需)
parent_id 此资源的父资源的 ID。 类型资源的 ID:networkSecurityGroups
性能 安全规则的属性。 CommonSecurityRuleProperties格式
类型 资源类型 “Microsoft。Network/networkSecurityGroups/securityRules@2025-07-01”

CommonApplicationSecurityGroup

名字 描述 价值
身份证 资源 ID。 字符串
位置 资源位置。 字符串
性能 应用程序安全组的属性。 CommonApplicationSecurityGroupPropertiesFormat
标签 资源标记。 CommonResourceTags

CommonApplicationSecurityGroupPropertiesFormat

名字 描述 价值

CommonResourceTags

名字 描述 价值

CommonSecurityRuleProperties格式

名字 描述 价值
访问 允许或拒绝网络流量。 “允许”
“拒绝”(必需)
描述 此规则的说明。 限制为 140 个字符。 字符串
destinationAddressPrefix 的 目标地址前缀。 CIDR 或目标 IP 范围。 星号“*”还可用于匹配所有源 IP。 也可以使用默认标记,例如“VirtualNetwork”、“AzureLoadBalancer”和“Internet”。 字符串
destinationAddress前缀 目标地址前缀。 CIDR 或目标 IP 范围。 字符串[]
destinationApplicationSecurityGroups 指定为目标的应用程序安全组。 CommonApplicationSecurityGroup[]
destinationPortRange 目标端口或范围。 介于 0 和 65535 之间的整数或范围。 星号“*”也可用于匹配所有端口。 字符串
destinationPortRanges 目标端口范围。 字符串[]
方向 规则的方向。 该方向指定在传入或传出流量上是否评估规则。 “Inbound”
“出站”(必需)
优先权 规则的优先级。 该值可以介于 100 和 4096 之间。 对于集合中的每个规则,优先级编号必须是唯一的。 优先级编号越低,规则优先级越高。 int (必需)
协议 此规则适用于的网络协议。 '*'
“Ah”
“Esp”
“Icmp”
“Tcp”
“Udp”(必需)
sourceAddressPrefix 的 CIDR 或源 IP 范围。 星号“*”还可用于匹配所有源 IP。 也可以使用默认标记,例如“VirtualNetwork”、“AzureLoadBalancer”和“Internet”。 如果这是入口规则,则指定网络流量的来源。 字符串
sourceAddress前缀 CIDR 或源 IP 范围。 字符串[]
sourceApplicationSecurityGroups 指定为源的应用程序安全组。 CommonApplicationSecurityGroup[]
sourcePortRange 源端口或范围。 介于 0 和 65535 之间的整数或范围。 星号“*”也可用于匹配所有端口。 字符串
sourcePort范围 源端口范围。 字符串[]

用法示例

Terraform 示例

部署网络安全规则的基本示例。

terraform {
  required_providers {
    azapi = {
      source = "Azure/azapi"
    }
  }
}

provider "azapi" {
  skip_provider_registration = false
}

variable "resource_name" {
  type    = string
  default = "acctest0001"
}

variable "location" {
  type    = string
  default = "westeurope"
}

resource "azapi_resource" "resourceGroup" {
  type     = "Microsoft.Resources/resourceGroups@2020-06-01"
  name     = var.resource_name
  location = var.location
}

resource "azapi_resource" "networkSecurityGroup" {
  type      = "Microsoft.Network/networkSecurityGroups@2022-07-01"
  parent_id = azapi_resource.resourceGroup.id
  name      = "mi-security-group1-230630034008554952"
  location  = var.location
  body = {
    properties = {
      securityRules = [
      ]
    }
  }
  schema_validation_enabled = false
  response_export_values    = ["*"]
  lifecycle {
    ignore_changes = [body.properties.securityRules]
  }
}

resource "azapi_resource" "securityRule" {
  type      = "Microsoft.Network/networkSecurityGroups/securityRules@2022-09-01"
  parent_id = azapi_resource.networkSecurityGroup.id
  name      = "allow_management_inbound"
  body = {
    properties = {
      access                   = "Allow"
      destinationAddressPrefix = "*"
      destinationPortRange     = ""
      destinationPortRanges = [
        "9000",
        "1438",
        "1440",
        "9003",
        "1452",
      ]
      direction           = "Inbound"
      priority            = 106
      protocol            = "Tcp"
      sourceAddressPrefix = "*"
      sourcePortRange     = "*"
    }
  }
  schema_validation_enabled = false
  response_export_values    = ["*"]
}