Bylaw

Gallery › Security Center › Azure built-in policies

Microsoft Defender for Storage should be enabled

Converted Policy AuditIfNotExists Disabled Mode All Version 1.0.0

Microsoft Defender for Storage detects potential threats to your storage accounts. It helps prevent the three major impacts on your data and workload: malicious file uploads, sensitive data exfiltration, and data corruption. The new Defender for Storage plan includes Malware Scanning and Sensitive Data Threat Detection. This plan also provides a predictable pricing structure (per storage account) for control over coverage and costs.

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

Azure Policy JSONMDC_Microsoft_Defender_For_Storage_Full_Audit.json · 79 lines
{
  "properties": {
    "displayName": "Microsoft Defender for Storage should be enabled",
    "policyType": "BuiltIn",
    "mode": "All",
    "description": "Microsoft Defender for Storage detects potential threats to your storage accounts. It helps prevent the three major impacts on your data and workload: malicious file uploads, sensitive data exfiltration, and data corruption. The new Defender for Storage plan includes Malware Scanning and Sensitive Data Threat Detection. This plan also provides a predictable pricing structure (per storage account) for control over coverage and costs.",
    "version": "1.0.0",
    "metadata": {
      "version": "1.0.0",
      "category": "Security Center"
    },
    "parameters": {
      "effect": {
        "type": "string",
        "defaultValue": "AuditIfNotExists",
        "allowedValues": [
          "AuditIfNotExists",
          "Disabled"
        ],
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the policy"
        }
      }
    },
    "policyRule": {
      "if": {
        "field": "type",
        "equals": "Microsoft.Resources/subscriptions"
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Security/pricings",
          "name": "StorageAccounts",
          "existenceScope": "subscription",
          "existenceCondition": {
            "allOf": [
              {
                "field": "Microsoft.Security/pricings/pricingTier",
                "equals": "Standard"
              },
              {
                "field": "Microsoft.Security/pricings/subPlan",
                "equals": "DefenderForStorageV2"
              },
              {
                "count": {
                  "field": "Microsoft.Security/pricings/extensions[*]",
                  "where": {
                    "allOf": [
                      {
                        "field": "Microsoft.Security/pricings/extensions[*].name",
                        "in": [
                          "OnUploadMalwareScanning",
                          "SensitiveDataDiscovery"
                        ]
                      },
                      {
                        "field": "Microsoft.Security/pricings/extensions[*].isEnabled",
                        "equals": "true"
                      }
                    ]
                  }
                },
                "equals": 2
              }
            ]
          }
        }
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/640d2586-54d2-465f-877f-9ffc1d2109f4",
  "name": "640d2586-54d2-465f-877f-9ffc1d2109f4"
}
Bylaw640d2586-54d2-465f-877f-9ffc1d2109f4.bylaw.ps1 · 33 lines
# Converted from MDC_Microsoft_Defender_For_Storage_Full_Audit.json by ConvertTo-Bylaw.
Policy '640d2586-54d2-465f-877f-9ffc1d2109f4' {

    Properties @{
        DisplayName   = 'Microsoft Defender for Storage should be enabled'
        Description   = 'Microsoft Defender for Storage detects potential threats to your storage accounts. It helps prevent the three major impacts on your data and workload: malicious file uploads, sensitive data exfiltration, and data corruption. The new Defender for Storage plan includes Malware Scanning and Sensitive Data Threat Detection. This plan also provides a predictable pricing structure (per storage account) for control over coverage and costs.'
        Version       = '1.0.0'
        Category      = 'Security Center'
        PolicyVersion = '1.0.0'
        Mode          = 'All'
    }

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

    Resource 'Microsoft.Resources/subscriptions'

    AuditIfNotExists 'Microsoft.Security/pricings' -Name 'StorageAccounts' -ExistenceScope Subscription -Effect (Param Effect) {
        Require 'pricingTier, subPlan, extensions and 2 more are as required' {
            Field pricingTier | Must -Be 'Standard'
            Field subPlan | Must -Be 'DefenderForStorageV2'
            Count 'extensions[*]' -Where {
                Field name | Must -BeIn @('OnUploadMalwareScanning', 'SensitiveDataDiscovery')
                Field isEnabled | Must -Be 'true'
            } | Must -Be 2
        }
    }
}

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