0

问题 - 所以我想阻止人们创建开放互联网访问某些端口(22、3389 等)的 NSG。我可以创建一个策略来阻止特定端口,例如,

{
"allOf": [{
        "field": "Microsoft.Network/networkSecurityGroups/securityRules/access",
        "equals": "Allow"
    },
    {
        "field": "Microsoft.Network/networkSecurityGroups/securityRules/direction",
        "equals": "Inbound"
    },
    {
        "anyOf": [{
                "field": "Microsoft.Network/networkSecurityGroups/securityRules/destinationPortRange",
                "equals": "22"
            },
            {
                "field": "Microsoft.Network/networkSecurityGroups/securityRules/destinationPortRange",
                "equals": "3389"
            }
        ]
    }
]

如果在安全规则中使用特定端口,这将阻止创建 NSG。但如果有人创建了允许端口范围(例如 3300-3400)的 NSG 规则,则可以绕过它。

想知道策略如何处理端口范围以及在这种情况下最好的方法是什么。

我尝试了 destinationPortRanges[*] 数组,但它不起作用。

{
"not": {
    "field": "Microsoft.Network/networkSecurityGroups/securityRules/destinationPortRanges[*]",
    "Equals": "22"
}

}

当destinationPortRanges 指定为“20-25”时,该规则仍允许创建NSG。

4

1 回答 1

1

查看内置策略“应阻止来自 Internet 的 RDP 访问”。还有应该阻止来自 Internet 的 SSH 访问

老实说,读起来很痛苦,但看起来它完全涵盖了你需要的东西。

{
                "anyOf": [
                  {
                    "field": "Microsoft.Network/networkSecurityGroups/securityRules/destinationPortRange",
                    "equals": "*"
                  },
                  {
                    "field": "Microsoft.Network/networkSecurityGroups/securityRules/destinationPortRange",
                    "equals": "3389"
                  },
                  {
                    "value": "[if(and(not(empty(field('Microsoft.Network/networkSecurityGroups/securityRules/destinationPortRange'))), contains(field('Microsoft.Network/networkSecurityGroups/securityRules/destinationPortRange'),'-')), and(lessOrEquals(int(first(split(field('Microsoft.Network/networkSecurityGroups/securityRules/destinationPortRange'), '-'))),3389),greaterOrEquals(int(last(split(field('Microsoft.Network/networkSecurityGroups/securityRules/destinationPortRange'), '-'))),3389)), 'false')]",
                    "equals": "true"
                  },
                  {
                      "count": {
                        "field": "Microsoft.Network/networkSecurityGroups/securityRules/destinationPortRanges[*]",
                        "where": {
                          "value": "[if(and(not(empty(first(field('Microsoft.Network/networkSecurityGroups/securityRules/destinationPortRanges[*]')))), contains(first(field('Microsoft.Network/networkSecurityGroups/securityRules/destinationPortRanges[*]')),'-')), and(lessOrEquals(int(first(split(first(field('Microsoft.Network/networkSecurityGroups/securityRules/destinationPortRanges[*]')), '-'))),3389),greaterOrEquals(int(last(split(first(field('Microsoft.Network/networkSecurityGroups/securityRules/destinationPortRanges[*]')), '-'))),3389)) , 'false')]",
                          "equals": "true"
                        }
                      },
                      "greater": 0
                  },
                  {
                    "not": {
                      "field": "Microsoft.Network/networkSecurityGroups/securityRules/destinationPortRanges[*]",
                      "notEquals": "*"
                    }
                  },
                  {
                    "not": {
                      "field": "Microsoft.Network/networkSecurityGroups/securityRules/destinationPortRanges[*]",
                      "notEquals": "3389"
                    }
                  }
                ]
              },
于 2020-03-17T18:37:48.930 回答