Bylaw

Gallery › Security Center - Granular Pricing › Azure built-in policies

Configure Azure Defender for Servers to be disabled for all resources (resource level)

Converted Policy DeployIfNotExists Disabled Mode All Version 1.0.0

Azure Defender for Servers provides real-time threat protection for server workloads and generates hardening recommendations as well as alerts about suspicious activities. This policy will disable the Defender for Servers plan for all resources (VMs, VMSSs and ARC Machines) in the selected scope (subscription or resource group).

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

Azure Policy JSONASC_Azure_Defender_Servers_Disable_ResourceLevel_DINE.json · 88 lines
{
  "properties": {
    "displayName": "Configure Azure Defender for Servers to be disabled for all resources (resource level)",
    "policyType": "BuiltIn",
    "mode": "All",
    "description": "Azure Defender for Servers provides real-time threat protection for server workloads and generates hardening recommendations as well as alerts about suspicious activities. This policy will disable the Defender for Servers plan for all resources (VMs, VMSSs and ARC Machines) in the selected scope (subscription or resource group).",
    "metadata": {
      "version": "1.0.0",
      "category": "Security Center - Granular Pricing"
    },
    "version": "1.0.0",
    "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",
        "in": [
          "Microsoft.Compute/virtualMachines",
          "Microsoft.Compute/virtualMachineScaleSets",
          "Microsoft.HybridCompute/machines"
        ]
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Security/pricings",
          "name": "VirtualMachines",
          "roleDefinitionIds": [
            "/providers/Microsoft.Authorization/roleDefinitions/fb1c8493-542b-48eb-b624-b4c8fea62acd"
          ],
          "existenceCondition": {
            "field": "Microsoft.Security/pricings/pricingTier",
            "equals": "Free"
          },
          "deployment": {
            "properties": {
              "mode": "incremental",
              "parameters": {
                "fullResourceName": {
                  "value": "[field('id')]"
                }
              },
              "template": {
                "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                "contentVersion": "1.0.0.0",
                "parameters": {
                  "fullResourceName": {
                    "type": "string"
                  }
                },
                "variables": {},
                "resources": [
                  {
                    "type": "Microsoft.Security/pricings",
                    "apiVersion": "2024-01-01",
                    "scope": "[parameters('fullResourceName')]",
                    "name": "VirtualMachines",
                    "properties": {
                      "pricingTier": "Free"
                    }
                  }
                ],
                "outputs": {}
              }
            }
          }
        }
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/f6ff485a-7630-4730-854d-cd3ad855435e",
  "name": "f6ff485a-7630-4730-854d-cd3ad855435e"
}
Bylawf6ff485a-7630-4730-854d-cd3ad855435e.bylaw.ps1 · 35 lines
# Converted from ASC_Azure_Defender_Servers_Disable_ResourceLevel_DINE.json by ConvertTo-Bylaw.
Policy 'f6ff485a-7630-4730-854d-cd3ad855435e' {

    Properties @{
        DisplayName   = 'Configure Azure Defender for Servers to be disabled for all resources (resource level)'
        Description   = 'Azure Defender for Servers provides real-time threat protection for server workloads and generates hardening recommendations as well as alerts about suspicious activities. This policy will disable the Defender for Servers plan for all resources (VMs, VMSSs and ARC Machines) in the selected scope (subscription or resource group).'
        Version       = '1.0.0'
        Category      = 'Security Center - Granular Pricing'
        PolicyVersion = '1.0.0'
        Mode          = 'All'
    }

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

    Resource * {

        Require 'type is not one of 3 values' {
            Field type | Must -Not -BeIn @('Microsoft.Compute/virtualMachines', 'Microsoft.Compute/virtualMachineScaleSets', 'Microsoft.HybridCompute/machines') -IfPresent
        }
    }

    DeployIfNotExists 'Microsoft.Security/pricings' -Role 'Security Admin' -Name 'VirtualMachines' -Effect (Param Effect) {
        Require 'pricingTier is Free' {
            Field pricingTier | Must -Be 'Free'
        }
        Deployment -TemplateFile './templates/f6ff485a-7630-4730-854d-cd3ad855435e.json' -Parameters ([ordered]@{
                fullResourceName = (Arm '[field(''id'')]')
            })
    }
}

Its deployment templates are written beside it:

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