Bylaw

Gallery › Internet of Things › Azure built-in policies

Modify - Configure Azure IoT Hubs to disable public network access

Converted Policy Disabled Modify Mode Indexed Version 1.0.0

Disabling the public network access property improves security by ensuring your Azure IoT Hub can only be accessed from a private endpoint. This policy disables public network access on IoT Hub resources.

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

Azure Policy JSONIoTHub_DisablePublicNetworkAccess_Modify.json · 63 lines
{
  "properties": {
    "displayName": "Modify - Configure Azure IoT Hubs to disable public network access",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Disabling the public network access property improves security by ensuring your Azure IoT Hub can only be accessed from a private endpoint. This policy disables public network access on IoT Hub resources.",
    "metadata": {
      "version": "1.0.0",
      "category": "Internet of Things"
    },
    "version": "1.0.0",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "Modify",
          "Disabled"
        ],
        "defaultValue": "Modify"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Devices/IotHubs"
          },
          {
            "field": "Microsoft.Devices/IotHubs/publicNetworkAccess",
            "notEquals": "Disabled"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "roleDefinitionIds": [
            "/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
          ],
          "conflictEffect": "audit",
          "operations": [
            {
              "condition": "[greaterOrEquals(requestContext().apiVersion, '2020-03-01')]",
              "operation": "addOrReplace",
              "field": "Microsoft.Devices/IotHubs/publicNetworkAccess",
              "value": "Disabled"
            }
          ]
        }
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/114eec6e-5e59-4bad-999d-6eceeb39d582",
  "name": "114eec6e-5e59-4bad-999d-6eceeb39d582"
}
Bylaw114eec6e-5e59-4bad-999d-6eceeb39d582.bylaw.ps1 · 30 lines
# Converted from IoTHub_DisablePublicNetworkAccess_Modify.json by ConvertTo-Bylaw.
Policy '114eec6e-5e59-4bad-999d-6eceeb39d582' {

    Properties @{
        DisplayName   = 'Modify - Configure Azure IoT Hubs to disable public network access'
        Description   = 'Disabling the public network access property improves security by ensuring your Azure IoT Hub can only be accessed from a private endpoint. This policy disables public network access on IoT Hub resources.'
        Version       = '1.0.0'
        Category      = 'Internet of Things'
        PolicyVersion = '1.0.0'
        Mode          = 'Indexed'
    }

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

    Resource 'Microsoft.Devices/IotHubs' {

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

    Modify -Role 'Contributor' -ConflictEffect Audit -Effect (Param Effect) {
        Field publicNetworkAccess | AddOrReplace 'Disabled' -Condition (Arm '[greaterOrEquals(requestContext().apiVersion, ''2020-03-01'')]')
    }
}

Source: built-in-policies/policyDefinitions/Internet of Things/IoTHub_DisablePublicNetworkAccess_Modify.json in Azure/azure-policy, under the MIT licence.