Bylaw

Gallery › Security Center › Azure built-in policies

All network ports should be restricted on network security groups associated to your virtual machine

Converted Policy AuditIfNotExists Disabled Mode All Version 3.0.0

Azure Security Center has identified some of your network security groups' inbound rules to be too permissive. Inbound rules should not allow access from 'Any' or 'Internet' ranges. This can potentially enable attackers to target your resources.

ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.

Azure Policy JSONASC_UnprotectedEndpoints_Audit.json · 55 lines
{
  "properties": {
    "displayName": "All network ports should be restricted on network security groups associated to your virtual machine",
    "policyType": "BuiltIn",
    "mode": "All",
    "description": "Azure Security Center has identified some of your network security groups' inbound rules to be too permissive. Inbound rules should not allow access from 'Any' or 'Internet' ranges. This can potentially enable attackers to target your resources.",
    "metadata": {
      "version": "3.0.0",
      "category": "Security Center"
    },
    "version": "3.0.0",
    "parameters": {
      "effect": {
        "type": "string",
        "defaultValue": "AuditIfNotExists",
        "allowedValues": [
          "AuditIfNotExists",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      }
    },
    "policyRule": {
      "if": {
        "field": "type",
        "in": [
          "Microsoft.Compute/virtualMachines",
          "Microsoft.ClassicCompute/virtualMachines"
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Security/assessments",
          "name": "3b20e985-f71f-483b-b078-f30d73936d43",
          "existenceCondition": {
            "field": "Microsoft.Security/assessments/status.code",
            "in": [
              "NotApplicable",
              "Healthy"
            ]
          }
        }
      }
    },
    "versions": [
      "3.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/9daedab3-fb2d-461e-b861-71790eead4f6",
  "name": "9daedab3-fb2d-461e-b861-71790eead4f6"
}
Bylaw9daedab3-fb2d-461e-b861-71790eead4f6.bylaw.ps1 · 33 lines
# Converted from ASC_UnprotectedEndpoints_Audit.json by ConvertTo-Bylaw.
Policy '9daedab3-fb2d-461e-b861-71790eead4f6' {

    Properties @{
        DisplayName   = 'All network ports should be restricted on network security groups associated to your virtual machine'
        Description   = 'Azure Security Center has identified some of your network security groups'' inbound rules to be too permissive. Inbound rules should not allow access from ''Any'' or ''Internet'' ranges. This can potentially enable attackers to target your resources.'
        Version       = '3.0.0'
        Category      = 'Security Center'
        PolicyVersion = '3.0.0'
        Mode          = 'All'
    }

    Parameter Effect @{
        Type          = 'string'
        AllowedValues = @('AuditIfNotExists', 'Disabled')
        Default       = 'AuditIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }

    Resource * {

        Require 'type is not one of 2 values' {
            Field type | Must -Not -BeIn @('Microsoft.Compute/virtualMachines', 'Microsoft.ClassicCompute/virtualMachines') -IfPresent
        }
    }

    AuditIfNotExists 'Microsoft.Security/assessments' -Name '3b20e985-f71f-483b-b078-f30d73936d43' -Effect (Param Effect) {
        Require 'status.code is one of 2 values' {
            Field status.code | Must -BeIn @('NotApplicable', 'Healthy')
        }
    }
}

Source: built-in-policies/policyDefinitions/Security Center/ASC_UnprotectedEndpoints_Audit.json in Azure/azure-policy, under the MIT licence.