Bylaw

Gallery › Azure Ai Services › Azure built-in policies

Configure Azure AI Services resources to disable local key access (disable local authentication)

Converted Policy DeployIfNotExists Disabled Mode Indexed Version 1.0.0

Key access (local authentication) is recommended to be disabled for security. Azure OpenAI Studio, typically used in development/testing, requires key access and will not function if key access is disabled. After disabling, Microsoft Entra ID becomes the only access method, which allows maintaining minimum privilege principle and granular control. Learn more at: https://aka.ms/AI/auth

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

Azure Policy JSONDisableLocalAuth_CognitiveServices_DINE.json · 150 lines
{
  "properties": {
    "displayName": "Configure Azure AI Services resources to disable local key access (disable local authentication)",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Key access (local authentication) is recommended to be disabled for security. Azure OpenAI Studio, typically used in development/testing, requires key access and will not function if key access is disabled. After disabling, Microsoft Entra ID becomes the only access method, which allows maintaining minimum privilege principle and granular control. Learn more at: https://aka.ms/AI/auth",
    "metadata": {
      "version": "1.0.0",
      "category": "Azure Ai Services"
    },
    "version": "1.0.0",
    "parameters": {
      "effect": {
        "type": "string",
        "defaultValue": "DeployIfNotExists",
        "allowedValues": [
          "DeployIfNotExists",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      },
      "disableLocalAuth": {
        "type": "String",
        "metadata": {
          "displayName": "disableLocalAuth",
          "description": "The disableLocalAuth property of the Azure AI service"
        },
        "allowedValues": [
          "true",
          "false"
        ],
        "defaultValue": "true"
      },
      "publicNetworkAccess": {
        "type": "String",
        "metadata": {
          "displayName": "publicNetworkAccess",
          "description": "The publicNetworkAccess property of the Azure AI service"
        },
        "allowedValues": [
          "Disabled",
          "Enabled"
        ],
        "defaultValue": "Disabled"
      }
    },
    "policyRule": {
      "if": {
        "field": "type",
        "equals": "Microsoft.CognitiveServices/accounts"
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.CognitiveServices/accounts",
          "name": "[field('name')]",
          "existenceCondition": {
            "field": "Microsoft.CognitiveServices/accounts/disableLocalAuth",
            "equals": true
          },
          "roleDefinitionIds": [
            "/providers/Microsoft.Authorization/roleDefinitions/a001fd3d-188f-4b5d-821b-7da978bf7442",
            "/providers/microsoft.authorization/roleDefinitions/25fbc0a9-bd7c-42a3-aa1a-3b75d497ee68"
          ],
          "deployment": {
            "properties": {
              "mode": "incremental",
              "template": {
                "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                "contentVersion": "1.0.0.0",
                "parameters": {
                  "resourceName": {
                    "type": "string"
                  },
                  "location": {
                    "type": "string"
                  },
                  "disableLocalAuth": {
                    "type": "string"
                  },
                  "kind": {
                    "type": "string"
                  },
                  "sku": {
                    "type": "object"
                  },
                  "publicNetworkAccess": {
                    "type": "string"
                  },
                  "networkAcls": {
                    "type": "object"
                  }
                },
                "variables": {},
                "resources": [
                  {
                    "type": "Microsoft.CognitiveServices/accounts",
                    "apiVersion": "2023-10-01-preview",
                    "name": "[parameters('resourceName')]",
                    "kind": "[parameters('kind')]",
                    "sku": "[parameters('sku')]",
                    "location": "[parameters('location')]",
                    "properties": {
                      "customSubDomainName": "[parameters('resourceName')]",
                      "disableLocalAuth": "[parameters('disableLocalAuth')]",
                      "publicNetworkAccess": "[parameters('publicNetworkAccess')]",
                      "networkAcls": "[parameters('networkAcls')]"
                    }
                  }
                ],
                "outputs": {}
              },
              "parameters": {
                "location": {
                  "value": "[field('location')]"
                },
                "resourceName": {
                  "value": "[field('name')]"
                },
                "disableLocalAuth": {
                  "value": "[parameters('disableLocalAuth')]"
                },
                "kind": {
                  "value": "[field('kind')]"
                },
                "sku": {
                  "value": "[field('Microsoft.CognitiveServices/accounts/sku')]"
                },
                "publicNetworkAccess": {
                  "value": "[parameters('publicNetworkAccess')]"
                },
                "networkAcls": {
                  "value": "[field('Microsoft.CognitiveServices/accounts/networkAcls')]"
                }
              }
            }
          }
        }
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/55eff01b-f2bd-4c32-9203-db285f709d30",
  "name": "55eff01b-f2bd-4c32-9203-db285f709d30"
}
Bylaw55eff01b-f2bd-4c32-9203-db285f709d30.bylaw.ps1 · 49 lines
# Converted from DisableLocalAuth_CognitiveServices_DINE.json by ConvertTo-Bylaw.
Policy '55eff01b-f2bd-4c32-9203-db285f709d30' {

    Properties @{
        DisplayName   = 'Configure Azure AI Services resources to disable local key access (disable local authentication)'
        Description   = 'Key access (local authentication) is recommended to be disabled for security. Azure OpenAI Studio, typically used in development/testing, requires key access and will not function if key access is disabled. After disabling, Microsoft Entra ID becomes the only access method, which allows maintaining minimum privilege principle and granular control. Learn more at: https://aka.ms/AI/auth'
        Version       = '1.0.0'
        Category      = 'Azure Ai Services'
        PolicyVersion = '1.0.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        Type          = 'string'
        AllowedValues = @('DeployIfNotExists', 'Disabled')
        Default       = 'DeployIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }
    Parameter DisableLocalAuth @{
        AllowedValues = @('true', 'false')
        Default       = 'true'
        DisplayName   = 'disableLocalAuth'
        Description   = 'The disableLocalAuth property of the Azure AI service'
    }
    Parameter PublicNetworkAccess @{
        AllowedValues = @('Disabled', 'Enabled')
        Default       = 'Disabled'
        DisplayName   = 'publicNetworkAccess'
        Description   = 'The publicNetworkAccess property of the Azure AI service'
    }

    Resource 'Microsoft.CognitiveServices/accounts'

    DeployIfNotExists 'Microsoft.CognitiveServices/accounts' -Role 'Cognitive Services OpenAI Contributor', 'Cognitive Services Contributor' -Name (Arm '[field(''name'')]') -Effect (Param Effect) {
        Require 'disableLocalAuth is true' {
            Field disableLocalAuth | Must -Be $true
        }
        Deployment -TemplateFile './templates/55eff01b-f2bd-4c32-9203-db285f709d30.json' -Parameters ([ordered]@{
                location            = (Arm '[field(''location'')]')
                resourceName        = (Arm '[field(''name'')]')
                disableLocalAuth    = (Param DisableLocalAuth)
                kind                = (Arm '[field(''kind'')]')
                sku                 = (Arm '[field(''Microsoft.CognitiveServices/accounts/sku'')]')
                publicNetworkAccess = (Param PublicNetworkAccess)
                networkAcls         = (Arm '[field(''Microsoft.CognitiveServices/accounts/networkAcls'')]')
            })
    }
}

Its deployment templates are written beside it:

Source: built-in-policies/policyDefinitions/Azure Ai Services/DisableLocalAuth_CognitiveServices_DINE.json in Azure/azure-policy, under the MIT licence.