Bylaw

Gallery › SQL › Azure Community Policy

Audit Server level threat detection setting

Converted Policy AuditIfNotExists Disabled Mode All Version 1.0.0

Audit threat detection setting for SQL Server

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

Azure Policy JSONazurepolicy.json · 58 lines
{
  "name": "2ad98ec6-3f37-452a-bb1f-b7adcbf44872",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Audit Server level threat detection setting",
    "description": "Audit threat detection setting for SQL Server",
    "metadata": {
      "version": "1.0.0",
      "category": "SQL"
    },
    "mode": "All",
    "parameters": {
      "setting": {
        "type": "String",
        "allowedValues": [
          "enabled",
          "disabled"
        ],
        "metadata": {
          "displayName": "Threat Detection Setting"
        }
      },
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "AuditIfNotExists or Disabled the execution of the Policy"
        },
        "allowedValues": [
          "AuditIfNotExists",
          "Disabled"
        ],
        "defaultValue": "AuditIfNotExists"
      }
    },
    "policyRule": {
      "if": {
        "field": "type",
        "equals": "Microsoft.SQL/servers"
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.SQL/servers/securityAlertPolicies",
          "name": "default",
          "existenceCondition": {
            "allOf": [
              {
                "field": "Microsoft.Sql/securityAlertPolicies.state",
                "equals": "[parameters('setting')]"
              }
            ]
          }
        }
      }
    }
  }
}
Bylaw2ad98ec6-3f37-452a-bb1f-b7adcbf44872.bylaw.ps1 · 31 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '2ad98ec6-3f37-452a-bb1f-b7adcbf44872' {

    Properties @{
        DisplayName = 'Audit Server level threat detection setting'
        Description = 'Audit threat detection setting for SQL Server'
        Version     = '1.0.0'
        Category    = 'SQL'
        Mode        = 'All'
    }

    Parameter Setting @{
        Type          = 'String'
        AllowedValues = @('enabled', 'disabled')
        DisplayName   = 'Threat Detection Setting'
    }
    Parameter Effect @{
        AllowedValues = @('AuditIfNotExists', 'Disabled')
        Default       = 'AuditIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'AuditIfNotExists or Disabled the execution of the Policy'
    }

    Resource 'Microsoft.SQL/servers'

    AuditIfNotExists 'Microsoft.SQL/servers/securityAlertPolicies' -Name 'default' -Effect (Param Effect) {
        Require 'securityAlertPolicies.state is the Setting parameter' {
            Field 'Microsoft.Sql/securityAlertPolicies.state' | Must -Be (Param Setting)
        }
    }
}

Source: policyDefinitions/SQL/audit-server-level-threat-detection-setting/azurepolicy.json in Azure/Community-Policy, under the MIT licence.