Bylaw

Gallery › Security Center › Azure built-in policies

[Preview]: Machines should have ports closed that might expose attack vectors

Converted Policy AuditIfNotExists Disabled Mode Indexed Version 1.0.0-preview Preview

Azure's Terms Of Use prohibit the use of Azure services in ways that could damage, disable, overburden, or impair any Microsoft server, or the network. The exposed ports identified by this recommendation need to be closed for your continued security. For each identified port, the recommendation also provides an explanation of the potential threat.

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

Azure Policy JSONASC_OpenTOUPortsOnVirtualMachines_Audit.json · 53 lines
{
  "properties": {
    "displayName": "[Preview]: Machines should have ports closed that might expose attack vectors",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Azure's Terms Of Use prohibit the use of Azure services in ways that could damage, disable, overburden, or impair any Microsoft server, or the network. The exposed ports identified by this recommendation need to be closed for your continued security. For each identified port, the recommendation also provides an explanation of the potential threat.",
    "metadata": {
      "category": "Security Center",
      "version": "1.0.0-preview",
      "preview": true
    },
    "version": "1.0.0-preview",
    "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",
        "equals": "Microsoft.Compute/virtualMachines"
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Security/assessments",
          "name": "bbff27d2-73db-4c2d-8b1a-5f20b1f1da7e",
          "existenceCondition": {
            "field": "Microsoft.Security/assessments/status.code",
            "in": [
              "NotApplicable",
              "Healthy"
            ]
          }
        }
      }
    },
    "versions": [
      "1.0.0-PREVIEW"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/af99038c-02fd-4a2f-ac24-386b62bf32de",
  "name": "af99038c-02fd-4a2f-ac24-386b62bf32de"
}
Bylawaf99038c-02fd-4a2f-ac24-386b62bf32de.bylaw.ps1 · 29 lines
# Converted from ASC_OpenTOUPortsOnVirtualMachines_Audit.json by ConvertTo-Bylaw.
Policy 'af99038c-02fd-4a2f-ac24-386b62bf32de' {

    Properties @{
        DisplayName   = '[Preview]: Machines should have ports closed that might expose attack vectors'
        Description   = 'Azure''s Terms Of Use prohibit the use of Azure services in ways that could damage, disable, overburden, or impair any Microsoft server, or the network. The exposed ports identified by this recommendation need to be closed for your continued security. For each identified port, the recommendation also provides an explanation of the potential threat.'
        Category      = 'Security Center'
        Version       = '1.0.0-preview'
        Preview       = $true
        PolicyVersion = '1.0.0-preview'
        Mode          = 'Indexed'
    }

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

    Resource 'Microsoft.Compute/virtualMachines'

    AuditIfNotExists 'Microsoft.Security/assessments' -Name 'bbff27d2-73db-4c2d-8b1a-5f20b1f1da7e' -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_OpenTOUPortsOnVirtualMachines_Audit.json in Azure/azure-policy, under the MIT licence.