azure 应用网关V2的NSG部署失败

44u64gxh  于 2023-04-07  发布在  其他
关注(0)|答案(2)|浏览(146)

我在为一个放置了应用网关(AG)的子网部署网络安全组(NSG)时遇到了一些麻烦。
在部署过程中,我得到以下错误(为了可读性,我删除了资源路径):
网络安全组nsg-acc-waf阻止端口65200 - 65535上的传入Internet流量到子网snet-acc-waf(与应用网关agw-acc关联)。对于具有V2 Sku的应用网关,不允许这样做。
根据www.example.com上的配置说明,一切看起来都很好https://learn.microsoft.com/en-us/azure/application-gateway/configuration-infrastructure#allow-access-to-a-few-source-ips
这是我用上面的说明创建的二头肌,我的问题是关于nsgRule110

resource wafNsg 'Microsoft.Network/networkSecurityGroups@2021-03-01' = {
  name: 'nsg-${environmentName}-waf'
  location: location

  resource nsgRule100 'securityRules' = {
    name: 'AllowPublicIPAddress'
    properties: {
      access: 'Allow'
      description: 'Allow traffic from Public IP Address.'
      destinationAddressPrefix: '*'
      destinationPortRange: '443'
      direction: 'Inbound'
      priority: 100
      protocol: 'Tcp'
      sourceAddressPrefix: publicIpAddress
      sourcePortRange: '*'
    }
  }

  resource nsgRule101 'securityRules' = {
    name: 'AllowInternetAccess'
    properties: {
      access: 'Allow'
      description: 'Allow traffic from Internet on port 443.'
      destinationAddressPrefix: '*'
      destinationPortRange: '443'
      direction: 'Inbound'
      priority: 101
      protocol: 'Tcp'
      sourceAddressPrefix: 'Internet'
      sourcePortRange: '*'
    }
  }

  resource nsgRule110 'securityRules' = {
    name: 'AllowGatewayManager'
    properties: {
      access: 'Allow'
      description: 'Allow traffic from GatewayManager. This port range is required for Azure infrastructure communication.'
      destinationAddressPrefix: '*'
      destinationPortRange: '65200-65535'
      direction: 'Inbound'
      priority: 110
      protocol: '*'
      sourceAddressPrefix: 'GatewayManager'
      sourcePortRange: '*'
    }
  }

  resource nsgRule120 'securityRules' = {
    name: 'AllowAzureLoadBalancer'
    properties: {
      access: 'Allow'
      description: 'Allow traffic from AzureLoadBalancer.'
      destinationAddressPrefix: '*'
      destinationPortRange: '*'
      direction: 'Inbound'
      priority: 120
      protocol: '*'
      sourceAddressPrefix: 'AzureLoadBalancer'
      sourcePortRange: '*'
    }
  }

  resource nsgRule4096 'securityRules' = {
    name: 'DenyAllInboundInternet'
    properties: {
      access: 'Deny'
      description: 'Deny all traffic from Internet.'
      destinationAddressPrefix: '*'
      destinationPortRange: '*'
      direction: 'Inbound'
      priority: 4096
      protocol: '*'
      sourceAddressPrefix: 'Internet'
      sourcePortRange: '*'
    }
  }
}

我也试过设置sourceAddressPrefix: 'Internet'sourceAddressPrefix: '*'(其中星号是任何).回答:Azure App Gateway V2无法使用NSG进行配置并将NSG添加到应用程序网关子网
我不知道它有什么问题。看起来只有在部署过程中才会触发这个验证规则。
我尝试过手动添加规则,当绑定到子网时,这是可行的。此外,添加NSG而不直接通过部署将其绑定到子网,但最终手动绑定似乎是可行的。唯一不起作用的情况是,NSG已经绑定到子网(由AG使用),然后(重新)部署。
有人能帮我吗?

uqzxnwby

uqzxnwby1#

如错误消息所示,NSG正在阻止端口65200 - 65535到子网snet-acc-waf的传入Internet流量,该子网与应用程序网关agw-acc相关联。这就是为什么您会遇到此阻止程序。
有关Application gateway infrastructure configuration,请参阅本文档。
由于您已经为nsgrule110指定了'destinationPortRange: '65200-65535',因此它将不再阻止此范围内的端口。如果需要,您可以为其他网络规则添加相同的规则,如下所示。

resource nsgRule120 'securityRules' = {
    name: ''
    properties: {
      access: 'Allow'
      description: 'Allow traffic'
      destinationAddressPrefix: '*'
      destinationPortRange: '65200-65535'
      direction: 'Inbound'
      priority: 120
      protocol: '*'
      sourceAddressPrefix: 'AzureLoadBalancer'
      sourcePortRange: '*'
    }
  }

我在我的环境中尝试了与您相同的代码,并且成功运行,如下面的快照所示。

  • 部署成功:*

9jyewag0

9jyewag02#

经过大量的尝试和错误,我发现问题出在Bicep上。首先,我为NSG规则使用了嵌套资源。但NSG本身有一个属性securityRules,您也可以在其中添加这些NSG规则,但它有一个区别;它会立即将NSG规则添加到NSG。另一种方法是使用嵌套资源,稍后在部署期间添加它们(因此验证器认为它没有GatewayManager规则),这将使验证规则关闭。
下面是一个可以工作的代码示例:)

resource wafNsg 'Microsoft.Network/networkSecurityGroups@2021-03-01' = {
  name: 'nsg-${environmentName}-waf'
  location: location
  properties: {
    securityRules: [
      {
        name: 'AllowGatewayManager'
        properties: {
          access: 'Allow'
          description: 'Allow traffic from GatewayManager. This port range is required for Azure infrastructure communication.'
          destinationAddressPrefix: '*'
          destinationPortRange: '65200-65535'
          direction: 'Inbound'
          priority: 100
          protocol: '*'
          sourceAddressPrefix: 'GatewayManager'
          sourcePortRange: '*'
        }
      }
      // put additional NSG rules here
    ]
  }
}

相关问题