Bylaw

Gallery › Azure Ai Services › Azure built-in policies

Diagnostic logs in Azure AI services resources should be enabled

Converted Policy AuditIfNotExists Disabled Mode Indexed Version 1.0.0

Enable logs for Azure AI services resources. This enables you to recreate activity trails for investigation purposes, when a security incident occurs or your network is compromised

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

Azure Policy JSONDiagnosticLogs_Audit.json · 56 lines
{
  "properties": {
    "displayName": "Diagnostic logs in Azure AI services resources should be enabled",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Enable logs for Azure AI services resources. This enables you to recreate activity trails for investigation purposes, when a security incident occurs or your network is compromised",
    "metadata": {
      "version": "1.0.0",
      "category": "Azure Ai Services"
    },
    "version": "1.0.0",
    "parameters": {
      "effect": {
        "type": "string",
        "defaultValue": "AuditIfNotExists",
        "allowedValues": [
          "AuditIfNotExists",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      }
    },
    "policyRule": {
      "if": {
        "anyOf": [
          {
            "field": "type",
            "equals": "Microsoft.CognitiveServices/accounts"
          },
          {
            "field": "type",
            "equals": "Microsoft.Search/searchServices"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Insights/diagnosticSettings",
          "existenceCondition": {
            "field": "Microsoft.Insights/diagnosticSettings/logs[*]",
            "exists": true
          }
        }
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/1b4d1c4e-934c-4703-944c-27c82c06bebb",
  "name": "1b4d1c4e-934c-4703-944c-27c82c06bebb"
}
Bylaw1b4d1c4e-934c-4703-944c-27c82c06bebb.bylaw.ps1 · 40 lines
# Converted from DiagnosticLogs_Audit.json by ConvertTo-Bylaw.
Policy '1b4d1c4e-934c-4703-944c-27c82c06bebb' {

    Properties @{
        DisplayName   = 'Diagnostic logs in Azure AI services resources should be enabled'
        Description   = 'Enable logs for Azure AI services resources. This enables you to recreate activity trails for investigation purposes, when a security incident occurs or your network is compromised'
        Version       = '1.0.0'
        Category      = 'Azure Ai Services'
        PolicyVersion = '1.0.0'
        Mode          = 'Indexed'
    }

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

    Resource * {

        Require 'type is not Microsoft.CognitiveServices/accounts' {
            Field type | Must -Not -Be 'Microsoft.CognitiveServices/accounts' -IfPresent
        }

        Require 'type is not Microsoft.Search/searchServices' {
            Field type | Must -Not -Be 'Microsoft.Search/searchServices' -IfPresent
        }
    }

    AuditIfNotExists 'Microsoft.Insights/diagnosticSettings' -Effect (Param Effect) {
        Require 'logs is as required' {
            Field logs | Must -Exist
            Each 'logs[*]' {
                Element | Must -Exist
            }
        }
    }
}

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