Bylaw

Gallery › Cognitive Services › Azure Community Policy

Audit OpenAI instances public access enabled

Converted Policy Audit Deny Disabled Mode Indexed Version 1.0.0

Azure OpenAI instances should not have public access enabled. Open AI instances should only be accessible via select networks or a private endpoint.

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

Azure Policy JSONazurepolicy.json · 73 lines
{
  "name": "5e68f029-0f81-4ee3-b578-705b0fdb237c",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Audit OpenAI instances public access enabled",
    "description": "Azure OpenAI instances should not have public access enabled. Open AI instances should only be accessible via select networks or a private endpoint.",
    "metadata": {
      "category": "Cognitive Services",
      "version": "1.0.0"
    },
    "mode": "Indexed",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.CognitiveServices/accounts"
          },
          {
            "field": "kind",
            "equals": "OpenAI"
          },
          {
            "anyof": [
              {
                "allof": [
                  {
                    "field": "Microsoft.CognitiveServices/accounts/networkAcls.defaultAction",
                    "notEquals": "Deny"
                  },
                  {
                    "field": "Microsoft.CognitiveServices/accounts/publicNetworkAccess",
                    "equals": "Enabled"
                  }
                ]
              },
              {
                "allof": [
                  {
                    "field": "Microsoft.CognitiveServices/accounts/networkAcls",
                    "exists": "false"
                  },
                  {
                    "field": "Microsoft.CognitiveServices/accounts/publicNetworkAccess",
                    "equals": "Enabled"
                  }
                ]
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    }
  }
}
Bylaw5e68f029-0f81-4ee3-b578-705b0fdb237c.bylaw.ps1 · 41 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '5e68f029-0f81-4ee3-b578-705b0fdb237c' {

    Properties @{
        DisplayName = 'Audit OpenAI instances public access enabled'
        Description = 'Azure OpenAI instances should not have public access enabled. Open AI instances should only be accessible via select networks or a private endpoint.'
        Category    = 'Cognitive Services'
        Version     = '1.0.0'
        Mode        = 'Indexed'
    }

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

    Resource 'Microsoft.CognitiveServices/accounts' {

        When {
            Field kind | Must -Be 'OpenAI'
        }

        Require 'networkAcls.defaultAction and publicNetworkAccess are as required' {
            AnyOf {
                Field networkAcls.defaultAction | Must -Be 'Deny'
                Field publicNetworkAccess | Must -Not -Be 'Enabled' -IfPresent
            }
        }

        Require 'networkAcls and publicNetworkAccess are as required' {
            AnyOf {
                Field networkAcls | Must -Exist
                Field publicNetworkAccess | Must -Not -Be 'Enabled' -IfPresent
            }
        }
    }

    Effect (Param Effect)
}

Source: policyDefinitions/Cognitive Services/public-access-restriction/azurepolicy.json in Azure/Community-Policy, under the MIT licence.