Bylaw

Gallery › Compute › Azure built-in policies

Managed disks should disable public network access

Converted Policy Audit Deny Disabled Mode Indexed Version 2.1.0

Disabling public network access improves security by ensuring that a managed disk isn't exposed on the public internet. Creating private endpoints can limit exposure of managed disks. Learn more at: https://aka.ms/disksprivatelinksdoc.

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

Azure Policy JSONDisks_ExportLimitNetworkAccess_Audit.json · 58 lines
{
  "properties": {
    "displayName": "Managed disks should disable public network access",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Disabling public network access improves security by ensuring that a managed disk isn't exposed on the public internet. Creating private endpoints can limit exposure of managed disks. Learn more at: https://aka.ms/disksprivatelinksdoc.",
    "metadata": {
      "version": "2.1.0",
      "category": "Compute"
    },
    "version": "2.1.0",
    "parameters": {
      "effect": {
        "type": "String",
        "defaultValue": "Audit",
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "The effect determines what happens when the policy rule is evaluated to match"
        }
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Compute/disks"
          },
          {
            "field": "Microsoft.Compute/disks/networkAccessPolicy",
            "notIn": [
              "DenyAll",
              "AllowPrivate"
            ]
          },
          {
            "field": "Microsoft.Compute/disks/publicNetworkAccess",
            "notEquals": "Disabled"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "2.1.0",
      "2.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/8405fdab-1faf-48aa-b702-999c9c172094",
  "name": "8405fdab-1faf-48aa-b702-999c9c172094"
}
Bylaw8405fdab-1faf-48aa-b702-999c9c172094.bylaw.ps1 · 32 lines
# Converted from Disks_ExportLimitNetworkAccess_Audit.json by ConvertTo-Bylaw.
Policy '8405fdab-1faf-48aa-b702-999c9c172094' {

    Properties @{
        DisplayName   = 'Managed disks should disable public network access'
        Description   = 'Disabling public network access improves security by ensuring that a managed disk isn''t exposed on the public internet. Creating private endpoints can limit exposure of managed disks. Learn more at: https://aka.ms/disksprivatelinksdoc.'
        Version       = '2.1.0'
        Category      = 'Compute'
        PolicyVersion = '2.1.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('Audit', 'Deny', 'Disabled')
        Default       = 'Audit'
        DisplayName   = 'Effect'
        Description   = 'The effect determines what happens when the policy rule is evaluated to match'
    }

    Resource 'Microsoft.Compute/disks' {

        When {
            Field networkAccessPolicy | Must -Not -BeIn @('DenyAll', 'AllowPrivate')
        }

        Require 'publicNetworkAccess is Disabled' {
            Field publicNetworkAccess | Must -Be 'Disabled'
        }
    }

    Effect (Param Effect)
}

Source: built-in-policies/policyDefinitions/Compute/Disks_ExportLimitNetworkAccess_Audit.json in Azure/azure-policy, under the MIT licence.