Gallery › Security Center › Azure built-in policies
Configure the Microsoft Defender for SQL Log Analytics workspace
Converted Policy DeployIfNotExists Disabled Mode Indexed Version 1.5.0
Microsoft Defender for SQL collects events from the agent and uses them to provide security alerts and tailored hardening tasks (recommendations). Create a resource group and Log Analytics workspace in the same region as the machine.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONMDC_DfSQL_DeployDefaultWorkspace.json · 229 lines
{
"properties": {
"displayName": "Configure the Microsoft Defender for SQL Log Analytics workspace",
"policyType": "BuiltIn",
"mode": "Indexed",
"description": "Microsoft Defender for SQL collects events from the agent and uses them to provide security alerts and tailored hardening tasks (recommendations). Create a resource group and Log Analytics workspace in the same region as the machine.",
"version": "1.5.0",
"metadata": {
"version": "1.5.0",
"category": "Security Center"
},
"parameters": {
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "Enable or disable the execution of the policy"
},
"allowedValues": [
"DeployIfNotExists",
"Disabled"
],
"defaultValue": "DeployIfNotExists"
}
},
"policyRule": {
"if": {
"anyOf": [
{
"allOf": [
{
"field": "type",
"equals": "Microsoft.SqlVirtualMachine/SqlVirtualMachines"
},
{
"field": "Microsoft.SqlVirtualMachine/sqlVirtualMachines/osType",
"equals": "Windows"
}
]
},
{
"allOf": [
{
"field": "type",
"equals": "Microsoft.HybridCompute/machines"
},
{
"field": "Microsoft.HybridCompute/machines/osName",
"equals": "Windows"
},
{
"field": "Microsoft.HybridCompute/machines/mssqlDiscovered",
"equals": "true"
}
]
}
]
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.OperationalInsights/workspaces",
"deploymentScope": "subscription",
"roleDefinitionIds": [
"/providers/microsoft.authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
],
"existenceScope": "subscription",
"existenceCondition": {
"allOf": [
{
"field": "location",
"equals": "[field('location')]"
},
{
"field": "name",
"equals": "[concat('D4SQL-', replace(subscription().subscriptionId, '-', ''),'-', field('location'))]"
}
]
},
"deployment": {
"location": "eastus",
"properties": {
"mode": "incremental",
"parameters": {
"resourceGroup": {
"value": "[resourceGroup().name]"
},
"location": {
"value": "[field('location')]"
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"resourceGroup": {
"type": "string"
},
"location": {
"type": "string"
}
},
"variables": {
"locationLongNameToShortMap": {
"australiacentral": "CAU",
"australiaeast": "EAU",
"australiasoutheast": "SEAU",
"brazilsouth": "CQ",
"canadacentral": "CCA",
"canadaeast": "CCA",
"centralindia": "CIN",
"centralus": "CUS",
"eastasia": "EA",
"eastus2euap": "eus2p",
"eastus": "EUS",
"eastus2": "EUS2",
"francecentral": "PAR",
"germanywestcentral": "DEWC",
"japaneast": "EJP",
"jioindiawest": "CIN",
"koreacentral": "SE",
"koreasouth": "SE",
"northcentralus": "NCUS",
"northeurope": "NEU",
"norwayeast": "NOE",
"southafricanorth": "JNB",
"southcentralus": "SCUS",
"southeastasia": "SEA",
"southindia": "CIN",
"swedencentral": "SEC",
"switzerlandnorth": "CHN",
"switzerlandwest": "CHW",
"uaenorth": "DXB",
"uksouth": "SUK",
"ukwest": "WUK",
"westcentralus": "WCUS",
"westeurope": "WEU",
"westindia": "CIN",
"westus": "WUS",
"westus2": "WUS2"
},
"locationCode": "[if(contains(variables('locationLongNameToShortMap'), parameters('location')), variables('locationLongNameToShortMap')[parameters('location')], parameters('location'))]",
"subscriptionId": "[subscription().subscriptionId]",
"defaultRGName": "[concat('DefaultResourceGroup-', variables('locationCode'))]",
"defaultRGLocation": "[parameters('location')]",
"workspaceName": "[concat('D4SQL-', replace(subscription().subscriptionId, '-', ''),'-', parameters('location'))]",
"deployWorkspace": "[concat('deployWS-', variables('workspaceName'))]"
},
"resources": [
{
"type": "Microsoft.Resources/resourceGroups",
"name": "[variables('defaultRGName')]",
"apiVersion": "2022-09-01",
"location": "[variables('defaultRGLocation')]",
"tags": {
"createdBy": "MicrosoftDefenderForSQL"
}
},
{
"type": "Microsoft.Resources/deployments",
"name": "[variables('deployWorkspace')]",
"apiVersion": "2022-09-01",
"resourceGroup": "[variables('defaultRGName')]",
"dependsOn": [
"[variables('defaultRGName')]"
],
"properties": {
"mode": "Incremental",
"expressionEvaluationOptions": {
"scope": "inner"
},
"parameters": {
"defaultRGLocation": {
"value": "[variables('defaultRGLocation')]"
},
"workspaceName": {
"value": "[variables('workspaceName')]"
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"defaultRGLocation": {
"type": "string"
},
"workspaceName": {
"type": "string"
}
},
"resources": [
{
"type": "Microsoft.OperationalInsights/workspaces",
"name": "[parameters('workspaceName')]",
"apiVersion": "2022-10-01",
"location": "[parameters('defaultRGLocation')]",
"tags": {
"createdBy": "MicrosoftDefenderForSQL"
},
"properties": {
"sku": {
"name": "pergb2018"
},
"retentionInDays": 30
}
}
]
}
}
}
]
}
}
}
}
}
},
"versions": [
"1.5.0",
"1.4.0",
"1.3.0",
"1.2.0",
"1.1.2",
"1.1.1-PREVIEW"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/242300d6-1bfc-4d64-8d01-cee583709ebd",
"name": "242300d6-1bfc-4d64-8d01-cee583709ebd"
}Bylaw242300d6-1bfc-4d64-8d01-cee583709ebd.bylaw.ps1 · 53 lines
# Converted from MDC_DfSQL_DeployDefaultWorkspace.json by ConvertTo-Bylaw.
Policy '242300d6-1bfc-4d64-8d01-cee583709ebd' {
Properties @{
DisplayName = 'Configure the Microsoft Defender for SQL Log Analytics workspace'
Description = 'Microsoft Defender for SQL collects events from the agent and uses them to provide security alerts and tailored hardening tasks (recommendations). Create a resource group and Log Analytics workspace in the same region as the machine.'
Version = '1.5.0'
Category = 'Security Center'
PolicyVersion = '1.5.0'
Mode = 'Indexed'
}
Parameter Effect @{
AllowedValues = @('DeployIfNotExists', 'Disabled')
Default = 'DeployIfNotExists'
DisplayName = 'Effect'
Description = 'Enable or disable the execution of the policy'
}
Resource * {
Require 'type and osType are as required' {
AnyOf {
Field type | Must -Not -Be 'Microsoft.SqlVirtualMachine/SqlVirtualMachines' -IfPresent
Field 'Microsoft.SqlVirtualMachine/sqlVirtualMachines/osType' | Must -Not -Be 'Windows' -IfPresent
}
}
Require 'type, osName and mssqlDiscovered are as required' {
AnyOf {
Field type | Must -Not -Be 'Microsoft.HybridCompute/machines' -IfPresent
Field 'Microsoft.HybridCompute/machines/osName' | Must -Not -Be 'Windows' -IfPresent
Field 'Microsoft.HybridCompute/machines/mssqlDiscovered' | Must -Not -Be 'true' -IfPresent
}
}
}
DeployIfNotExists 'Microsoft.OperationalInsights/workspaces' -Role 'Contributor' -ExistenceScope Subscription -Effect (Param Effect) {
Require 'location and name are as required' {
Field location | Must -Be (Arm '[field(''location'')]')
Field name | Must -Be (Arm '[concat(''D4SQL-'', replace(subscription().subscriptionId, ''-'', ''''),''-'', field(''location''))]')
}
Deployment @{
TemplateFile = './templates/242300d6-1bfc-4d64-8d01-cee583709ebd.json'
Scope = 'Subscription'
Location = 'eastus'
Parameters = [ordered]@{
resourceGroup = (Arm '[resourceGroup().name]')
location = (Arm '[field(''location'')]')
}
}
}
}Its deployment templates are written beside it:
templates/242300d6-1bfc-4d64-8d01-cee583709ebd.json
Source: built-in-policies/policyDefinitions/Security Center/MDC_DfSQL_DeployDefaultWorkspace.json in Azure/azure-policy, under the MIT licence.
Bylaw