Gallery › SQL › Azure Community Policy
Deploy Threat Detection on SQL servers
Converted Policy AuditIfNotExists DeployIfNotExists Disabled Mode Indexed Version 1.0.0
This policy ensures that Threat Detection is enabled on SQL Servers.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONazurepolicy.json · 79 lines
{
"name": "cd6c8d4a-a0f5-4367-b696-899bc197f78c",
"type": "Microsoft.Authorization/policyDefinitions",
"properties": {
"displayName": "Deploy Threat Detection on SQL servers",
"description": "This policy ensures that Threat Detection is enabled on SQL Servers.",
"metadata": {
"category": "SQL",
"version": "1.0.0"
},
"mode": "Indexed",
"parameters": {
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "DeployIfNotExists, AuditIfNotExists or Disabled the execution of the Policy"
},
"allowedValues": [
"DeployIfNotExists",
"AuditIfNotExists",
"Disabled"
],
"defaultValue": "DeployIfNotExists"
}
},
"policyRule": {
"if": {
"field": "type",
"equals": "Microsoft.Sql/servers"
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.Sql/servers/securityAlertPolicies",
"name": "Default",
"existenceCondition": {
"field": "Microsoft.Sql/securityAlertPolicies.state",
"equals": "Enabled"
},
"roleDefinitionIds": [
"/providers/microsoft.authorization/roleDefinitions/9b7fa17d-e63e-47b0-bb0a-15c516ac86ec"
],
"deployment": {
"properties": {
"mode": "incremental",
"template": {
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"serverName": {
"type": "string"
}
},
"variables": {},
"resources": [
{
"name": "[concat(parameters('serverName'), '/Default')]",
"type": "Microsoft.Sql/servers/securityAlertPolicies",
"apiVersion": "2017-03-01-preview",
"properties": {
"state": "Enabled",
"emailAccountAdmins": true
}
}
]
},
"parameters": {
"serverName": {
"value": "[field('name')]"
}
}
}
}
}
}
}
}
}Bylawcd6c8d4a-a0f5-4367-b696-899bc197f78c.bylaw.ps1 · 29 lines
# Converted from azurepolicy.json by ConvertTo-Bylaw.
Policy 'cd6c8d4a-a0f5-4367-b696-899bc197f78c' {
Properties @{
DisplayName = 'Deploy Threat Detection on SQL servers'
Description = 'This policy ensures that Threat Detection is enabled on SQL Servers.'
Category = 'SQL'
Version = '1.0.0'
Mode = 'Indexed'
}
Parameter Effect @{
AllowedValues = @('DeployIfNotExists', 'AuditIfNotExists', 'Disabled')
Default = 'DeployIfNotExists'
DisplayName = 'Effect'
Description = 'DeployIfNotExists, AuditIfNotExists or Disabled the execution of the Policy'
}
Resource 'Microsoft.Sql/servers'
DeployIfNotExists 'Microsoft.Sql/servers/securityAlertPolicies' -Role 'SQL DB Contributor' -Name 'Default' -Effect (Param Effect) {
Require 'securityAlertPolicies.state is Enabled' {
Field 'Microsoft.Sql/securityAlertPolicies.state' | Must -Be 'Enabled'
}
Deployment -TemplateFile './templates/cd6c8d4a-a0f5-4367-b696-899bc197f78c.json' -Parameters ([ordered]@{
serverName = (Arm '[field(''name'')]')
})
}
}Its deployment templates are written beside it:
templates/cd6c8d4a-a0f5-4367-b696-899bc197f78c.json
Source: policyDefinitions/SQL/deploy-threat-detection-on-sql-servers/azurepolicy.json in Azure/Community-Policy, under the MIT licence.
Bylaw