Bylaw

Gallery › Cognitive Services › Azure Landing Zones Library

Network ACLs should be restricted for Cognitive Services

Converted Policy Audit Deny Disabled Mode All Version 1.0.0

Azure Cognitive Services should not allow adding individual IPs or virtual network rules to the service-level firewall. Enable this to restrict inbound network access and enforce the usage of private endpoints.

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

Azure Policy JSONDeny-CognitiveServices-NetworkAcls.alz_policy_definition.json · 64 lines
{
  "name": "Deny-CognitiveServices-NetworkAcls",
  "properties": {
    "description": "Azure Cognitive Services should not allow adding individual IPs or virtual network rules to the service-level firewall. Enable this to restrict inbound network access and enforce the usage of private endpoints.",
    "displayName": "Network ACLs should be restricted for Cognitive Services",
    "metadata": {
      "alzCloudEnvironments": [
        "AzureCloud",
        "AzureChinaCloud",
        "AzureUSGovernment"
      ],
      "category": "Cognitive Services",
      "source": "https://github.com/Azure/Enterprise-Scale/",
      "version": "1.0.0"
    },
    "mode": "All",
    "parameters": {
      "effect": {
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "defaultValue": "Deny",
        "metadata": {
          "description": "Enable or disable the execution of the policy",
          "displayName": "Effect"
        },
        "type": "String"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "equals": "Microsoft.CognitiveServices/accounts",
            "field": "type"
          },
          {
            "anyOf": [
              {
                "count": {
                  "field": "Microsoft.CognitiveServices/accounts/networkAcls.ipRules[*]"
                },
                "greater": 0
              },
              {
                "count": {
                  "field": "Microsoft.CognitiveServices/accounts/networkAcls.virtualNetworkRules[*]"
                },
                "greater": 0
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "policyType": "Custom"
  },
  "type": "Microsoft.Authorization/policyDefinitions"
}
BylawDeny-CognitiveServices-NetworkAcls.bylaw.ps1 · 32 lines
# Converted from Deny-CognitiveServices-NetworkAcls.alz_policy_definition.json by ConvertTo-Bylaw.
Policy 'Deny-CognitiveServices-NetworkAcls' {

    Properties @{
        DisplayName = 'Network ACLs should be restricted for Cognitive Services'
        Description = 'Azure Cognitive Services should not allow adding individual IPs or virtual network rules to the service-level firewall. Enable this to restrict inbound network access and enforce the usage of private endpoints.'
        Category    = 'Cognitive Services'
        Version     = '1.0.0'
        Mode        = 'All'
        Metadata    = [ordered]@{ alzCloudEnvironments = @('AzureCloud', 'AzureChinaCloud', 'AzureUSGovernment'); source = 'https://github.com/Azure/Enterprise-Scale/' }
    }

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

    Resource 'Microsoft.CognitiveServices/accounts' {

        Require 'networkAcls.ipRules is as required' {
            Count 'networkAcls.ipRules[*]' | Must -Be 0
        }

        Require 'networkAcls.virtualNetworkRules is as required' {
            Count 'networkAcls.virtualNetworkRules[*]' | Must -Be 0
        }
    }

    Effect (Param Effect)
}

Source: policy_definitions/Deny-CognitiveServices-NetworkAcls.alz_policy_definition.json in Azure/Azure-Landing-Zones-Library, under the MIT licence.