Bylaw

Gallery › Security Center › Azure built-in policies

Configure Arc-enabled SQL Servers with Data Collection Rule Association to Microsoft Defender for SQL DCR

Converted Policy DeployIfNotExists Disabled Mode Indexed Version 1.1.0

Configure association between Arc-enabled SQL Servers and the Microsoft Defender for SQL DCR. Deleting this association will break the detection of security vulnerabilities for this Arc-enabled SQL Servers.

ConvertTo-Bylaw converted this policy, and proved that the file compiles back to the same definition.

Azure Policy JSONMDC_DfSQL_AMA_DefaultPipeline_DCRA_Arc.json · 151 lines
{
  "properties": {
    "displayName": "Configure Arc-enabled SQL Servers with Data Collection Rule Association to Microsoft Defender for SQL DCR",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Configure association between Arc-enabled SQL Servers and the Microsoft Defender for SQL DCR. Deleting this association will break the detection of security vulnerabilities for this Arc-enabled SQL Servers.",
    "version": "1.1.0",
    "metadata": {
      "category": "Security Center",
      "version": "1.1.0"
    },
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        },
        "allowedValues": [
          "DeployIfNotExists",
          "Disabled"
        ],
        "defaultValue": "DeployIfNotExists"
      }
    },
    "policyRule": {
      "if": {
        "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.Insights/dataCollectionRuleAssociations",
          "name": "MicrosoftDefenderForSQL-RulesAssociation",
          "roleDefinitionIds": [
            "/providers/microsoft.authorization/roleDefinitions/749f88d5-cbae-40b8-bcfc-e573ddc772fa",
            "/providers/microsoft.authorization/roleDefinitions/92aaf0da-9dab-42b6-94a3-d43ce8d16293"
          ],
          "deployment": {
            "properties": {
              "mode": "incremental",
              "parameters": {
                "resourceGroup": {
                  "value": "[resourceGroup().name]"
                },
                "location": {
                  "value": "[field('location')]"
                },
                "vmName": {
                  "value": "[field('name')]"
                }
              },
              "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"
                  }
                },
                "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'))]",
                  "dcrName": "[concat('MicrosoftDefenderForSQL-', parameters('location'), '-dcr')]",
                  "dcrId": "[concat('/subscriptions/', variables('subscriptionId'), '/resourceGroups/', variables('defaultRGName'), '/providers/Microsoft.Insights/dataCollectionRules/', variables('dcrName'))]",
                  "dcraName": "[concat(parameters('vmName'),'/Microsoft.Insights/MicrosoftDefenderForSQL-RulesAssociation')]"
                },
                "resources": [
                  {
                    "type": "Microsoft.HybridCompute/machines/providers/dataCollectionRuleAssociations",
                    "name": "[variables('dcraName')]",
                    "apiVersion": "2021-04-01",
                    "properties": {
                      "description": "Configure association between Arc-enabled SQL Server and the Microsoft Defender for SQL DCR. Deleting this association will break the detection of security vulnerabilities for this Arc-enabled SQL Server.",
                      "dataCollectionRuleId": "[variables('dcrId')]"
                    }
                  }
                ]
              }
            }
          }
        }
      }
    },
    "versions": [
      "1.1.0",
      "1.0.2",
      "1.0.1-PREVIEW"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/cbdd12e1-193a-445c-9926-560118c6daaa",
  "name": "cbdd12e1-193a-445c-9926-560118c6daaa"
}
Bylawcbdd12e1-193a-445c-9926-560118c6daaa.bylaw.ps1 · 38 lines
# Converted from MDC_DfSQL_AMA_DefaultPipeline_DCRA_Arc.json by ConvertTo-Bylaw.
Policy 'cbdd12e1-193a-445c-9926-560118c6daaa' {

    Properties @{
        DisplayName   = 'Configure Arc-enabled SQL Servers with Data Collection Rule Association to Microsoft Defender for SQL DCR'
        Description   = 'Configure association between Arc-enabled SQL Servers and the Microsoft Defender for SQL DCR. Deleting this association will break the detection of security vulnerabilities for this Arc-enabled SQL Servers.'
        Category      = 'Security Center'
        Version       = '1.1.0'
        PolicyVersion = '1.1.0'
        Mode          = 'Indexed'
    }

    Parameter Effect @{
        AllowedValues = @('DeployIfNotExists', 'Disabled')
        Default       = 'DeployIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }

    Resource 'Microsoft.HybridCompute/machines' {

        When {
            Field osName | Must -Be 'Windows'
        }

        Require 'mssqlDiscovered is not true' {
            Field mssqlDiscovered | Must -Not -Be 'true' -IfPresent
        }
    }

    DeployIfNotExists 'Microsoft.Insights/dataCollectionRuleAssociations' -Role 'Monitoring Contributor', 'Log Analytics Contributor' -Name 'MicrosoftDefenderForSQL-RulesAssociation' -Effect (Param Effect) {
        Deployment -TemplateFile './templates/cbdd12e1-193a-445c-9926-560118c6daaa.json' -Parameters ([ordered]@{
                resourceGroup = (Arm '[resourceGroup().name]')
                location      = (Arm '[field(''location'')]')
                vmName        = (Arm '[field(''name'')]')
            })
    }
}

Its deployment templates are written beside it:

Source: built-in-policies/policyDefinitions/Security Center/MDC_DfSQL_AMA_DefaultPipeline_DCRA_Arc.json in Azure/azure-policy, under the MIT licence.