Gallery › Security Center › Azure built-in policies
Configure Arc-enabled SQL Servers to automatically install Microsoft Defender for SQL and DCR with a user-defined LA workspace
Converted Policy DeployIfNotExists Disabled Mode Indexed Version 1.8.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_Arc.json · 385 lines
{
"properties": {
"displayName": "Configure Arc-enabled SQL Servers 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.8.0",
"metadata": {
"category": "Security Center",
"version": "1.8.0"
},
"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.HybridCompute/machines"
},
{
"field": "Microsoft.HybridCompute/machines/osName",
"equals": "Windows"
},
{
"field": "Microsoft.HybridCompute/machines/mssqlDiscovered",
"equals": "true"
}
]
},
"then": {
"effect": "[parameters('effect')]",
"details": {
"type": "Microsoft.Insights/dataCollectionRuleAssociations",
"name": "MicrosoftDefenderForSQL-RulesAssociation",
"deploymentScope": "subscription",
"roleDefinitionIds": [
"/providers/microsoft.authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c"
],
"deployment": {
"location": "eastus",
"properties": {
"mode": "incremental",
"parameters": {
"resourceGroup": {
"value": "[resourceGroup().name]"
},
"vmName": {
"value": "[field('name')]"
},
"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"
},
"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))]"
},
"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.HybridCompute/machines/providers/dataCollectionRuleAssociations",
"name": "[parameters('dcraName')]",
"apiVersion": "2021-04-01",
"properties": {
"description": "Configure association between Arc-enabled SQL Server and the Microsoft Defender for SQL user-defined DCR. Deleting this association will break the detection of security vulnerabilities for this Arc-enabled SQL Server.",
"dataCollectionRuleId": "[parameters('dcrId')]"
}
}
]
}
}
}
]
}
}
}
}
}
},
"versions": [
"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/63d03cbd-47fd-4ee1-8a1c-9ddf07303de0",
"name": "63d03cbd-47fd-4ee1-8a1c-9ddf07303de0"
}Bylaw63d03cbd-47fd-4ee1-8a1c-9ddf07303de0.bylaw.ps1 · 78 lines
# Converted from MDC_DfSQL_AMA_UserWorkspacePipeline_Arc.json by ConvertTo-Bylaw.
Policy '63d03cbd-47fd-4ee1-8a1c-9ddf07303de0' {
Properties @{
DisplayName = 'Configure Arc-enabled SQL Servers 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.'
Category = 'Security Center'
Version = '1.8.0'
PolicyVersion = '1.8.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.HybridCompute/machines' {
When {
Param BringYourOwnDcr | Must -Be $false
Field osName | Must -Be 'Windows'
}
Require 'mssqlDiscovered is not true' {
Field mssqlDiscovered | Must -Not -Be 'true' -IfPresent
}
}
DeployIfNotExists 'Microsoft.Insights/dataCollectionRuleAssociations' -Role 'Contributor' -Name 'MicrosoftDefenderForSQL-RulesAssociation' -Effect (Param Effect) {
Deployment @{
TemplateFile = './templates/63d03cbd-47fd-4ee1-8a1c-9ddf07303de0.json'
Scope = 'Subscription'
Location = 'eastus'
Parameters = [ordered]@{
resourceGroup = (Arm '[resourceGroup().name]')
vmName = (Arm '[field(''name'')]')
userWorkspaceResourceId = (Param UserWorkspaceResourceId)
workspaceRegion = (Param WorkspaceRegion)
userWorkspaceId = (Param UserWorkspaceId)
enableCollectionOfSqlQueriesForSecurityResearch = (Param EnableCollectionOfSqlQueriesForSecurityResearch)
}
}
}
}Its deployment templates are written beside it:
templates/63d03cbd-47fd-4ee1-8a1c-9ddf07303de0.json
Source: built-in-policies/policyDefinitions/Security Center/MDC_DfSQL_AMA_UserWorkspacePipeline_Arc.json in Azure/azure-policy, under the MIT licence.
Bylaw