Gallery › Security Center › Azure built-in policies
Configure SQL Virtual Machines to automatically install Microsoft Defender for SQL extension
Converted Policy DeployIfNotExists Disabled Mode Indexed Version 1.0.0
Configure Windows SQL Virtual Machines to automatically install the Microsoft Defender for SQL extension. Microsoft Defender for SQL collects events from the agent and uses them to provide security alerts and tailored hardening tasks (recommendations).
ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.
Azure Policy JSONMDC_DfSQL_MicrosoftDefenderForSQLWindowsAgent_VM_DINE.json · 127 lines
{
"properties": {
"displayName": "Configure SQL Virtual Machines to automatically install Microsoft Defender for SQL extension",
"policyType": "BuiltIn",
"mode": "Indexed",
"description": "Configure Windows SQL Virtual Machines to automatically install the Microsoft Defender for SQL extension. Microsoft Defender for SQL collects events from the agent and uses them to provide security alerts and tailored hardening tasks (recommendations).",
"version": "1.0.0",
"metadata": {
"version": "1.0.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": {
"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",
"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"
]
}
]
}
]
},
"roleDefinitionIds": [
"/providers/microsoft.authorization/roleDefinitions/92aaf0da-9dab-42b6-94a3-d43ce8d16293"
],
"deployment": {
"properties": {
"mode": "incremental",
"parameters": {
"location": {
"value": "[field('location')]"
},
"vmName": {
"value": "[last(split(field('Microsoft.SqlVirtualMachine/SqlVirtualMachines/virtualMachineResourceId'), '/'))]"
}
},
"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"
}
},
"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.0.0"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/9345b7fb-67c5-496c-9f12-eaa74f676875",
"name": "9345b7fb-67c5-496c-9f12-eaa74f676875"
}Bylaw9345b7fb-67c5-496c-9f12-eaa74f676875.bylaw.ps1 · 41 lines
# Converted from MDC_DfSQL_MicrosoftDefenderForSQLWindowsAgent_VM_DINE.json by ConvertTo-Bylaw.
Policy '9345b7fb-67c5-496c-9f12-eaa74f676875' {
Properties @{
DisplayName = 'Configure SQL Virtual Machines to automatically install Microsoft Defender for SQL extension'
Description = 'Configure Windows SQL Virtual Machines to automatically install the Microsoft Defender for SQL extension. Microsoft Defender for SQL collects events from the agent and uses them to provide security alerts and tailored hardening tasks (recommendations).'
Version = '1.0.0'
Category = 'Security Center'
PolicyVersion = '1.0.0'
Mode = 'Indexed'
}
Parameter Effect @{
AllowedValues = @('DeployIfNotExists', 'Disabled')
Default = 'DeployIfNotExists'
DisplayName = 'Effect'
Description = 'Enable or disable the execution of the policy'
}
Resource 'Microsoft.SqlVirtualMachine/SqlVirtualMachines'
DeployIfNotExists 'Microsoft.Compute/virtualMachines/extensions' -Role 'Log Analytics 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/9345b7fb-67c5-496c-9f12-eaa74f676875.json' -Parameters ([ordered]@{
location = (Arm '[field(''location'')]')
vmName = (Arm '[last(split(field(''Microsoft.SqlVirtualMachine/SqlVirtualMachines/virtualMachineResourceId''), ''/''))]')
})
}
}Its deployment templates are written beside it:
templates/9345b7fb-67c5-496c-9f12-eaa74f676875.json
Source: built-in-policies/policyDefinitions/Security Center/MDC_DfSQL_MicrosoftDefenderForSQLWindowsAgent_VM_DINE.json in Azure/azure-policy, under the MIT licence.
Bylaw