Gallery › Security Center › Azure built-in policies
Configure SQL Virtual Machines to automatically install Microsoft Defender for SQL and DCR with a user-defined LA workspace
Converted Policy DeployIfNotExists Disabled Mode Indexed Version 1.10.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 a Data Collection Rule in the same region as the user-defined Log Analytics workspace.
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONMDC_DfSQL_AMA_UserWorkspacePipeline_VM.json · 476 lines
{
"properties": {
"displayName": "Configure SQL Virtual Machines to automatically install Microsoft Defender for SQL and DCR with a user-defined LA 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 a Data Collection Rule in the same region as the user-defined Log Analytics workspace.",
"version": "1.10.0",
"metadata": {
"version": "1.10.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"
},
"userWorkspaceResourceId": {
"type": "String",
"metadata": {
"displayName": "Workspace Resource Id",
"description": "Workspace resource Id of the Log Analytics workspace destination for the Data Collection Rule.",
"strongType": "omsWorkspace"
}
},
"workspaceRegion": {
"type": "String",
"metadata": {
"displayName": "Workspace region",
"description": "Region of the Log Analytics workspace destination for the Data Collection Rule.",
"strongType": "location"
}
},
"userWorkspaceId": {
"type": "String",
"metadata": {
"displayName": "Workspace Id",
"description": "Workspace Id of the Log Analytics workspace destination for the Data Collection Rule."
},
"defaultValue": ""
},
"enableCollectionOfSqlQueriesForSecurityResearch": {
"type": "Boolean",
"metadata": {
"displayName": "Enable collection of SQL queries for security research",
"description": "Enable or disable the collection of SQL queries for security research."
},
"allowedValues": [
true,
false
],
"defaultValue": false
},
"bringYourOwnDcr": {
"type": "Boolean",
"metadata": {
"displayName": "Bring your own DCR",
"description": "Enable or disable the use of a user-defined Data Collection Rule."
},
"allowedValues": [
true,
false
],
"defaultValue": false
}
},
"policyRule": {
"if": {
"allOf": [
{
"value": "[parameters('bringYourOwnDcr')]",
"equals": false
},
{
"field": "type",
"equals": "Microsoft.SqlVirtualMachine/SqlVirtualMachines"
}
]
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "[concat(last(split(field('Microsoft.SqlVirtualMachine/SqlVirtualMachines/virtualMachineResourceId'), '/')), '/?')]",
"evaluationDelay": "AfterProvisioning",
"deploymentScope": "subscription",
"roleDefinitionIds": [
"/providers/microsoft.authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
],
"existenceCondition": {
"anyOf": [
{
"allOf": [
{
"field": "Microsoft.Compute/virtualMachines/extensions/type",
"equals": "SqlIaaSAgentLinux"
},
{
"field": "Microsoft.Compute/virtualMachines/extensions/publisher",
"equals": "Microsoft.SqlServer.Management"
}
]
},
{
"allOf": [
{
"field": "Microsoft.Compute/virtualMachines/extensions/type",
"equals": "AdvancedThreatProtection.Windows"
},
{
"field": "Microsoft.Compute/virtualMachines/extensions/publisher",
"equals": "Microsoft.Azure.AzureDefenderForSQL"
},
{
"field": "Microsoft.Compute/virtualMachines/extensions/provisioningState",
"in": [
"Succeeded",
"Provisioning succeeded"
]
}
]
}
]
},
"deployment": {
"location": "eastus",
"properties": {
"mode": "incremental",
"parameters": {
"resourceGroup": {
"value": "[resourceGroup().name]"
},
"location": {
"value": "[field('location')]"
},
"vmName": {
"value": "[last(split(field('Microsoft.SqlVirtualMachine/SqlVirtualMachines/virtualMachineResourceId'), '/'))]"
},
"userWorkspaceResourceId": {
"value": "[parameters('userWorkspaceResourceId')]"
},
"workspaceRegion": {
"value": "[parameters('workspaceRegion')]"
},
"userWorkspaceId": {
"value": "[parameters('userWorkspaceId')]"
},
"enableCollectionOfSqlQueriesForSecurityResearch": {
"value": "[parameters('enableCollectionOfSqlQueriesForSecurityResearch')]"
}
},
"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"
},
"vmName": {
"type": "string"
},
"userWorkspaceResourceId": {
"type": "string"
},
"workspaceRegion": {
"type": "string"
},
"userWorkspaceId": {
"type": "string"
},
"enableCollectionOfSqlQueriesForSecurityResearch": {
"type": "bool"
}
},
"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('workspaceRegion')), variables('locationLongNameToShortMap')[parameters('workspaceRegion')], parameters('workspaceRegion'))]",
"subscriptionId": "[subscription().subscriptionId]",
"defaultRGName": "[concat('DefaultResourceGroup-', variables('locationCode'))]",
"defaultRGLocation": "[parameters('workspaceRegion')]",
"dcrName": "[if(empty(parameters('userWorkspaceId')), concat('MicrosoftDefenderForSQL-', parameters('workspaceRegion'), '-dcr'), concat('D4SQL-', replace(parameters('userWorkspaceId'), '-', ''), '-dcr'))]",
"dcrId": "[concat('/subscriptions/', variables('subscriptionId'), '/resourceGroups/', variables('defaultRGName'), '/providers/Microsoft.Insights/dataCollectionRules/', variables('dcrName'))]",
"dcraName": "[concat(parameters('vmName'),'/Microsoft.Insights/MicrosoftDefenderForSQL-RulesAssociation')]",
"deployDataCollectionRules": "[concat('deployDataCollectionRules-', uniqueString(deployment().name))]",
"deployDataCollectionRulesAssociation": "[concat('deployDataCollectionRulesAssociation-', uniqueString(deployment().name))]",
"deployDefenderForSQL": "[concat('deployDefenderForSQL-', uniqueString(deployment().name))]"
},
"resources": [
{
"type": "Microsoft.Resources/resourceGroups",
"name": "[variables('defaultRGName')]",
"apiVersion": "2022-09-01",
"location": "[variables('defaultRGLocation')]",
"tags": {
"createdBy": "MicrosoftDefenderForSQL"
}
},
{
"type": "Microsoft.Resources/deployments",
"name": "[variables('deployDataCollectionRules')]",
"apiVersion": "2022-09-01",
"resourceGroup": "[variables('defaultRGName')]",
"dependsOn": [
"[variables('defaultRGName')]"
],
"properties": {
"mode": "Incremental",
"expressionEvaluationOptions": {
"scope": "inner"
},
"parameters": {
"defaultRGLocation": {
"value": "[variables('defaultRGLocation')]"
},
"workspaceResourceId": {
"value": "[parameters('userWorkspaceResourceId')]"
},
"dcrName": {
"value": "[variables('dcrName')]"
},
"dcrId": {
"value": "[variables('dcrId')]"
},
"enableCollectionOfSqlQueriesForSecurityResearch": {
"value": "[parameters('enableCollectionOfSqlQueriesForSecurityResearch')]"
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"defaultRGLocation": {
"type": "string"
},
"workspaceResourceId": {
"type": "string"
},
"dcrName": {
"type": "string"
},
"dcrId": {
"type": "string"
},
"enableCollectionOfSqlQueriesForSecurityResearch": {
"type": "bool"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Insights/dataCollectionRules",
"name": "[parameters('dcrName')]",
"apiVersion": "2021-04-01",
"location": "[parameters('defaultRGLocation')]",
"tags": {
"createdBy": "MicrosoftDefenderForSQL"
},
"properties": {
"description": "Data collection rule for Microsoft Defender for SQL. Deleting this rule will break the detection of security vulnerabilities.",
"dataSources": {
"extensions": [
{
"extensionName": "MicrosoftDefenderForSQL",
"name": "MicrosoftDefenderForSQL",
"streams": [
"Microsoft-DefenderForSqlAlerts",
"Microsoft-DefenderForSqlLogins",
"Microsoft-DefenderForSqlTelemetry",
"Microsoft-DefenderForSqlScanEvents",
"Microsoft-DefenderForSqlScanResults",
"Microsoft-SqlAtpStatus-DefenderForSql"
],
"extensionSettings": {
"enableCollectionOfSqlQueriesForSecurityResearch": "[parameters('enableCollectionOfSqlQueriesForSecurityResearch')]"
}
}
]
},
"destinations": {
"logAnalytics": [
{
"workspaceResourceId": "[parameters('workspaceResourceId')]",
"name": "LogAnalyticsDest"
}
]
},
"dataFlows": [
{
"streams": [
"Microsoft-DefenderForSqlAlerts",
"Microsoft-DefenderForSqlLogins",
"Microsoft-DefenderForSqlTelemetry",
"Microsoft-DefenderForSqlScanEvents",
"Microsoft-DefenderForSqlScanResults",
"Microsoft-SqlAtpStatus-DefenderForSql"
],
"destinations": [
"LogAnalyticsDest"
]
}
]
}
}
]
}
}
},
{
"type": "Microsoft.Resources/deployments",
"name": "[variables('deployDataCollectionRulesAssociation')]",
"apiVersion": "2022-09-01",
"resourceGroup": "[parameters('resourceGroup')]",
"dependsOn": [
"[variables('deployDataCollectionRules')]"
],
"properties": {
"mode": "Incremental",
"expressionEvaluationOptions": {
"scope": "inner"
},
"parameters": {
"dcrId": {
"value": "[variables('dcrId')]"
},
"dcraName": {
"value": "[variables('dcraName')]"
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"dcrId": {
"type": "string"
},
"dcraName": {
"type": "string"
}
},
"resources": [
{
"type": "Microsoft.Compute/virtualMachines/providers/dataCollectionRuleAssociations",
"name": "[parameters('dcraName')]",
"apiVersion": "2021-04-01",
"properties": {
"description": "Configure association between SQL Virtual Machine and the Microsoft Defender for SQL user-defined DCR. Deleting this association will break the detection of security vulnerabilities for this SQL Virtual Machine.",
"dataCollectionRuleId": "[parameters('dcrId')]"
}
}
]
}
}
},
{
"type": "Microsoft.Resources/deployments",
"name": "[variables('deployDefenderForSQL')]",
"apiVersion": "2022-09-01",
"resourceGroup": "[parameters('resourceGroup')]",
"dependsOn": [
"[variables('deployDataCollectionRulesAssociation')]"
],
"properties": {
"mode": "Incremental",
"expressionEvaluationOptions": {
"scope": "inner"
},
"parameters": {
"location": {
"value": "[parameters('location')]"
},
"vmName": {
"value": "[parameters('vmName')]"
}
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string"
},
"vmName": {
"type": "string"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Compute/virtualMachines/extensions",
"name": "[concat(parameters('vmName'), '/', 'MicrosoftDefenderForSQL')]",
"apiVersion": "2023-03-01",
"location": "[parameters('location')]",
"tags": {
"createdBy": "MicrosoftDefenderForSQL"
},
"properties": {
"publisher": "Microsoft.Azure.AzureDefenderForSQL",
"type": "AdvancedThreatProtection.Windows",
"typeHandlerVersion": "2.0",
"autoUpgradeMinorVersion": true,
"enableAutomaticUpgrade": true
}
}
]
}
}
}
]
}
}
}
}
}
},
"versions": [
"1.10.0",
"1.9.0",
"1.8.0",
"1.7.0",
"1.6.0",
"1.5.0",
"1.4.0",
"1.3.1",
"1.3.0-PREVIEW"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/04754ef9-9ae3-4477-bf17-86ef50026304",
"name": "04754ef9-9ae3-4477-bf17-86ef50026304"
}Bylaw04754ef9-9ae3-4477-bf17-86ef50026304.bylaw.ps1 · 87 lines
# Converted from MDC_DfSQL_AMA_UserWorkspacePipeline_VM.json by ConvertTo-Bylaw.
Policy '04754ef9-9ae3-4477-bf17-86ef50026304' {
Properties @{
DisplayName = 'Configure SQL Virtual Machines to automatically install Microsoft Defender for SQL and DCR with a user-defined LA 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 a Data Collection Rule in the same region as the user-defined Log Analytics workspace.'
Version = '1.10.0'
Category = 'Security Center'
PolicyVersion = '1.10.0'
Mode = 'Indexed'
}
Parameter Effect @{
AllowedValues = @('DeployIfNotExists', 'Disabled')
Default = 'DeployIfNotExists'
DisplayName = 'Effect'
Description = 'Enable or disable the execution of the policy'
}
Parameter UserWorkspaceResourceId @{
Type = 'String'
DisplayName = 'Workspace Resource Id'
Description = 'Workspace resource Id of the Log Analytics workspace destination for the Data Collection Rule.'
Metadata = [ordered]@{ strongType = 'omsWorkspace' }
}
Parameter WorkspaceRegion @{
Type = 'String'
DisplayName = 'Workspace region'
Description = 'Region of the Log Analytics workspace destination for the Data Collection Rule.'
Metadata = [ordered]@{ strongType = 'location' }
}
Parameter UserWorkspaceId @{
Default = ''
DisplayName = 'Workspace Id'
Description = 'Workspace Id of the Log Analytics workspace destination for the Data Collection Rule.'
}
Parameter EnableCollectionOfSqlQueriesForSecurityResearch @{
Type = 'Boolean'
AllowedValues = @($true, $false)
Default = $false
DisplayName = 'Enable collection of SQL queries for security research'
Description = 'Enable or disable the collection of SQL queries for security research.'
}
Parameter BringYourOwnDcr @{
Type = 'Boolean'
AllowedValues = @($true, $false)
Default = $false
DisplayName = 'Bring your own DCR'
Description = 'Enable or disable the use of a user-defined Data Collection Rule.'
}
Resource 'Microsoft.SqlVirtualMachine/SqlVirtualMachines' {
Require 'Requirement 1' {
Param BringYourOwnDcr | Must -Not -Be $false
}
}
DeployIfNotExists 'Microsoft.Compute/virtualMachines/extensions' -Role 'Contributor' -Name (Arm '[concat(last(split(field(''Microsoft.SqlVirtualMachine/SqlVirtualMachines/virtualMachineResourceId''), ''/'')), ''/?'')]') -EvaluationDelay AfterProvisioning -Effect (Param Effect) {
Require 'type, publisher and provisioningState are as required' {
AnyOf {
AllOf {
Field 'Microsoft.Compute/virtualMachines/extensions/type' | Must -Be 'SqlIaaSAgentLinux'
Field publisher | Must -Be 'Microsoft.SqlServer.Management'
}
AllOf {
Field 'Microsoft.Compute/virtualMachines/extensions/type' | Must -Be 'AdvancedThreatProtection.Windows'
Field publisher | Must -Be 'Microsoft.Azure.AzureDefenderForSQL'
Field provisioningState | Must -BeIn @('Succeeded', 'Provisioning succeeded')
}
}
}
Deployment @{
TemplateFile = './templates/04754ef9-9ae3-4477-bf17-86ef50026304.json'
Scope = 'Subscription'
Location = 'eastus'
Parameters = [ordered]@{
resourceGroup = (Arm '[resourceGroup().name]')
location = (Arm '[field(''location'')]')
vmName = (Arm '[last(split(field(''Microsoft.SqlVirtualMachine/SqlVirtualMachines/virtualMachineResourceId''), ''/''))]')
userWorkspaceResourceId = (Param UserWorkspaceResourceId)
workspaceRegion = (Param WorkspaceRegion)
userWorkspaceId = (Param UserWorkspaceId)
enableCollectionOfSqlQueriesForSecurityResearch = (Param EnableCollectionOfSqlQueriesForSecurityResearch)
}
}
}
}Its deployment templates are written beside it:
templates/04754ef9-9ae3-4477-bf17-86ef50026304.json
Source: built-in-policies/policyDefinitions/Security Center/MDC_DfSQL_AMA_UserWorkspacePipeline_VM.json in Azure/azure-policy, under the MIT licence.
Bylaw