Bylaw

Gallery › Internet of Things › Azure built-in policies

Private endpoint should be enabled for IoT Hub

Converted Policy Audit Disabled Mode Indexed Version 1.0.0

Private endpoint connections enforce secure communication by enabling private connectivity to IoT Hub. Configure a private endpoint connection to enable access to traffic coming only from known networks and prevent access from all other IP addresses, including within Azure.

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

Azure Policy JSONIoTHub_EnablePrivateEndpoint_Audit.json · 55 lines
{
  "properties": {
    "displayName": "Private endpoint should be enabled for IoT Hub",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Private endpoint connections enforce secure communication by enabling private connectivity to IoT Hub. Configure a private endpoint connection to enable access to traffic coming only from known networks and prevent access from all other IP addresses, including within Azure.",
    "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": [
          "Audit",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Devices/IotHubs"
          },
          {
            "count": {
              "field": "Microsoft.Devices/IotHubs/privateEndpointConnections[*]",
              "where": {
                "field": "Microsoft.Devices/IotHubs/privateEndpointConnections[*].privateLinkServiceConnectionState.status",
                "equals": "Approved"
              }
            },
            "less": 1
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/0d40b058-9f95-4a19-93e3-9b0330baa2a3",
  "name": "0d40b058-9f95-4a19-93e3-9b0330baa2a3"
}
Bylaw0d40b058-9f95-4a19-93e3-9b0330baa2a3.bylaw.ps1 · 30 lines
# Converted from IoTHub_EnablePrivateEndpoint_Audit.json by ConvertTo-Bylaw.
Policy '0d40b058-9f95-4a19-93e3-9b0330baa2a3' {

    Properties @{
        DisplayName   = 'Private endpoint should be enabled for IoT Hub'
        Description   = 'Private endpoint connections enforce secure communication by enabling private connectivity to IoT Hub. Configure a private endpoint connection to enable access to traffic coming only from known networks and prevent access from all other IP addresses, including within Azure.'
        Version       = '1.0.0'
        Category      = 'Internet of Things'
        PolicyVersion = '1.0.0'
        Mode          = 'Indexed'
    }

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

    Resource 'Microsoft.Devices/IotHubs' {

        Require 'privateEndpointConnections and privateLinkServiceConnectionState.status are as required' {
            Count 'privateEndpointConnections[*]' -Where {
                Field privateLinkServiceConnectionState.status | Must -Be 'Approved'
            } | Must -BeGreaterOrEqual 1
        }
    }

    Effect (Param Effect)
}

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