Bylaw

Gallery › SQL › Azure Community Policy

Audit DB level threat detection setting

Converted Policy AuditIfNotExists Disabled Mode All Version 1.0.0

Audit threat detection setting for SQL databases

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

Azure Policy JSONazurepolicy.json · 62 lines
{
  "name": "3d079490-86cc-441b-9829-0af390856adc",
  "type": "Microsoft.Authorization/policyDefinitions",
  "properties": {
    "displayName": "Audit DB level threat detection setting",
    "description": "Audit threat detection setting for SQL databases",
    "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": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.SQL/servers/databases"
          },
          {
            "field": "name",
            "notEquals": "master"
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.SQL/servers/databases/securityAlertPolicies",
          "name": "default",
          "existenceCondition": {
            "field": "Microsoft.Sql/securityAlertPolicies.state",
            "equals": "[parameters('setting')]"
          }
        }
      }
    }
  }
}
Bylaw3d079490-86cc-441b-9829-0af390856adc.bylaw.ps1 · 36 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy '3d079490-86cc-441b-9829-0af390856adc' {

    Properties @{
        DisplayName = 'Audit DB level threat detection setting'
        Description = 'Audit threat detection setting for SQL databases'
        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/databases' {

        Require 'name is master' {
            Field name | Must -Be 'master'
        }
    }

    AuditIfNotExists 'Microsoft.SQL/servers/databases/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-db-level-threat-detection-setting/azurepolicy.json in Azure/Community-Policy, under the MIT licence.