Bylaw

Gallery › Cognitive Services › Azure Landing Zones Library

Only explicit kinds for Cognitive Services should be allowed

Converted Policy Audit Deny Disabled Mode All Version 1.0.0

Azure Cognitive Services should only create explicit allowed kinds.

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

Azure Policy JSONDeny-CognitiveServices-Resource-Kinds.alz_policy_definition.json · 93 lines
{
  "name": "Deny-CognitiveServices-Resource-Kinds",
  "properties": {
    "description": "Azure Cognitive Services should only create explicit allowed kinds.",
    "displayName": "Only explicit kinds for Cognitive Services should be allowed",
    "metadata": {
      "alzCloudEnvironments": [
        "AzureCloud",
        "AzureChinaCloud",
        "AzureUSGovernment"
      ],
      "category": "Cognitive Services",
      "source": "https://github.com/Azure/Enterprise-Scale/",
      "version": "1.0.0"
    },
    "mode": "All",
    "parameters": {
      "allowedKinds": {
        "allowedValues": [
          "AnomalyDetector",
          "ComputerVision",
          "CognitiveServices",
          "ContentModerator",
          "CustomVision.Training",
          "CustomVision.Prediction",
          "Face",
          "FormRecognizer",
          "ImmersiveReader",
          "LUIS",
          "Personalizer",
          "SpeechServices",
          "TextAnalytics",
          "TextTranslation",
          "OpenAI"
        ],
        "defaultValue": [
          "AnomalyDetector",
          "ComputerVision",
          "CognitiveServices",
          "ContentModerator",
          "CustomVision.Training",
          "CustomVision.Prediction",
          "Face",
          "FormRecognizer",
          "ImmersiveReader",
          "LUIS",
          "Personalizer",
          "SpeechServices",
          "TextAnalytics",
          "TextTranslation",
          "OpenAI"
        ],
        "metadata": {
          "description": "Select the allowed resource kinds to be used with Cognitive Services",
          "displayName": "Effect"
        },
        "type": "array"
      },
      "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"
          },
          {
            "field": "kind",
            "notIn": "[parameters('allowedKinds')]"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "policyType": "Custom"
  },
  "type": "Microsoft.Authorization/policyDefinitions"
}
BylawDeny-CognitiveServices-Resource-Kinds.bylaw.ps1 · 35 lines
# Converted from Deny-CognitiveServices-Resource-Kinds.alz_policy_definition.json by ConvertTo-Bylaw.
Policy 'Deny-CognitiveServices-Resource-Kinds' {

    Properties @{
        DisplayName = 'Only explicit kinds for Cognitive Services should be allowed'
        Description = 'Azure Cognitive Services should only create explicit allowed kinds.'
        Category    = 'Cognitive Services'
        Version     = '1.0.0'
        Mode        = 'All'
        Metadata    = [ordered]@{ alzCloudEnvironments = @('AzureCloud', 'AzureChinaCloud', 'AzureUSGovernment'); source = 'https://github.com/Azure/Enterprise-Scale/' }
    }

    Parameter AllowedKinds @{
        Type          = 'array'
        AllowedValues = @('AnomalyDetector', 'ComputerVision', 'CognitiveServices', 'ContentModerator', 'CustomVision.Training', 'CustomVision.Prediction', 'Face', 'FormRecognizer', 'ImmersiveReader', 'LUIS', 'Personalizer', 'SpeechServices', 'TextAnalytics', 'TextTranslation', 'OpenAI')
        Default       = @('AnomalyDetector', 'ComputerVision', 'CognitiveServices', 'ContentModerator', 'CustomVision.Training', 'CustomVision.Prediction', 'Face', 'FormRecognizer', 'ImmersiveReader', 'LUIS', 'Personalizer', 'SpeechServices', 'TextAnalytics', 'TextTranslation', 'OpenAI')
        DisplayName   = 'Effect'
        Description   = 'Select the allowed resource kinds to be used with Cognitive Services'
    }
    Parameter Effect @{
        AllowedValues = @('Audit', 'Deny', 'Disabled')
        Default       = 'Deny'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }

    Resource 'Microsoft.CognitiveServices/accounts' {

        Require 'kind is one of the AllowedKinds parameter' {
            Field kind | Must -BeIn (Param AllowedKinds)
        }
    }

    Effect (Param Effect)
}

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