Bylaw

Gallery › Web PubSub › Azure built-in policies

Configure Azure Web PubSub Service to disable public network access

Converted Policy Disabled Modify Mode Indexed Version 1.0.0

Disable public network access for your Azure Web PubSub resource so that it's not accessible over the public internet. This can reduce data leakage risks. Learn more at: https://aka.ms/awps/networkacls.

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

Azure Policy JSONPublicNetworkAccessDisabled_Modify.json · 62 lines
{
  "properties": {
    "displayName": "Configure Azure Web PubSub Service to disable public network access",
    "description": "Disable public network access for your Azure Web PubSub resource so that it's not accessible over the public internet. This can reduce data leakage risks. Learn more at: https://aka.ms/awps/networkacls. ",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "metadata": {
      "version": "1.0.0",
      "category": "Web PubSub"
    },
    "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.SignalRService/webPubSub"
          },
          {
            "field": "Microsoft.SignalRService/webPubSub/publicNetworkAccess",
            "notEquals": "Disabled"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "conflictEffect": "Audit",
          "roleDefinitionIds": [
            "/providers/Microsoft.Authorization/roleDefinitions/8cf5e20a-e4b2-4e9d-b3a1-5ceb692c2761"
          ],
          "operations": [
            {
              "operation": "addOrReplace",
              "field": "Microsoft.SignalRService/webPubSub/publicNetworkAccess",
              "value": "Disabled"
            }
          ]
        }
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/5b1213e4-06e4-4ccc-81de-4201f2f7131a",
  "name": "5b1213e4-06e4-4ccc-81de-4201f2f7131a"
}
Bylaw5b1213e4-06e4-4ccc-81de-4201f2f7131a.bylaw.ps1 · 30 lines
# Converted from PublicNetworkAccessDisabled_Modify.json by ConvertTo-Bylaw.
Policy '5b1213e4-06e4-4ccc-81de-4201f2f7131a' {

    Properties @{
        DisplayName   = 'Configure Azure Web PubSub Service to disable public network access'
        Description   = 'Disable public network access for your Azure Web PubSub resource so that it''s not accessible over the public internet. This can reduce data leakage risks. Learn more at: https://aka.ms/awps/networkacls. '
        Version       = '1.0.0'
        Category      = 'Web PubSub'
        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.SignalRService/webPubSub' {

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

    Modify -Role 'SignalR/Web PubSub Contributor' -ConflictEffect Audit -Effect (Param Effect) {
        Field publicNetworkAccess | AddOrReplace 'Disabled'
    }
}

Source: built-in-policies/policyDefinitions/Web PubSub/PublicNetworkAccessDisabled_Modify.json in Azure/azure-policy, under the MIT licence.