Bylaw

Gallery › Security Center › Azure built-in policies

Configure Microsoft Defender for Storage to be enabled

Converted Policy DeployIfNotExists Disabled Mode All Version 1.5.0

Microsoft Defender for Storage is an Azure-native layer of security intelligence that detects potential threats to your storage accounts.
This policy will enable all Defender for Storage capabilities; Activity Monitoring, Malware Scanning and Sensitive Data Threat Detection. To learn more about Defender for Storage capabilities and benefits, visit aka.ms/DefenderForStorage.

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

Azure Policy JSONMDC_Microsoft_Defender_For_Storage_Full_DINE.json · 199 lines
{
  "properties": {
    "displayName": "Configure Microsoft Defender for Storage to be enabled",
    "policyType": "BuiltIn",
    "mode": "All",
    "description": "Microsoft Defender for Storage is an Azure-native layer of security intelligence that detects potential threats to your storage accounts.\nThis policy will enable all Defender for Storage capabilities; Activity Monitoring, Malware Scanning and Sensitive Data Threat Detection. To learn more about Defender for Storage capabilities and benefits, visit aka.ms/DefenderForStorage.",
    "version": "1.5.0",
    "metadata": {
      "version": "1.5.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"
      },
      "isOnUploadMalwareScanningEnabled": {
        "type": "String",
        "metadata": {
          "displayName": "Malware Scanning Enabled",
          "description": "Enable or disable the Malware Scanning add-on feature"
        },
        "allowedValues": [
          "true",
          "false"
        ],
        "defaultValue": "true"
      },
      "capGBPerMonthPerStorageAccount": {
        "type": "Integer",
        "metadata": {
          "displayName": "Cap GB Per Month Per Storage Account",
          "description": "Limit the GB scanned per month for each storage account within the subscription.\nValue must be an integer, 10GB or higher\nSet to -1 for unlimited scanning"
        },
        "defaultValue": 10000
      },
      "isSensitiveDataDiscoveryEnabled": {
        "type": "String",
        "metadata": {
          "displayName": "Sensitive Data Threat Detection Enabled",
          "description": "Enable or disable the Sensitive Data Threat Detection add-on feature"
        },
        "allowedValues": [
          "true",
          "false"
        ],
        "defaultValue": "true"
      }
    },
    "policyRule": {
      "if": {
        "field": "type",
        "equals": "Microsoft.Resources/subscriptions"
      },
      "then": {
        "effect": "[parameters('effect')]",
        "details": {
          "type": "Microsoft.Security/pricings",
          "name": "StorageAccounts",
          "deploymentScope": "subscription",
          "existenceScope": "subscription",
          "roleDefinitionIds": [
            "/providers/Microsoft.Authorization/roleDefinitions/8e3af657-a8ff-443c-a75c-2fe8c4bcb635"
          ],
          "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",
                        "equals": "OnUploadMalwareScanning"
                      },
                      {
                        "field": "Microsoft.Security/pricings/extensions[*].isEnabled",
                        "equals": "[parameters('isOnUploadMalwareScanningEnabled')]"
                      }
                    ]
                  }
                },
                "equals": 1
              },
              {
                "count": {
                  "field": "Microsoft.Security/pricings/extensions[*]",
                  "where": {
                    "allOf": [
                      {
                        "field": "Microsoft.Security/pricings/extensions[*].name",
                        "equals": "SensitiveDataDiscovery"
                      },
                      {
                        "field": "Microsoft.Security/pricings/extensions[*].isEnabled",
                        "equals": "[parameters('isSensitiveDataDiscoveryEnabled')]"
                      }
                    ]
                  }
                },
                "equals": 1
              }
            ]
          },
          "deployment": {
            "location": "westeurope",
            "properties": {
              "mode": "incremental",
              "parameters": {
                "isOnUploadMalwareScanningEnabled": {
                  "value": "[parameters('isOnUploadMalwareScanningEnabled')]"
                },
                "capGBPerMonthPerStorageAccount": {
                  "value": "[parameters('capGBPerMonthPerStorageAccount')]"
                },
                "isSensitiveDataDiscoveryEnabled": {
                  "value": "[parameters('isSensitiveDataDiscoveryEnabled')]"
                }
              },
              "template": {
                "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                "contentVersion": "1.3.0.0",
                "parameters": {
                  "isOnUploadMalwareScanningEnabled": {
                    "type": "String"
                  },
                  "capGBPerMonthPerStorageAccount": {
                    "type": "int"
                  },
                  "isSensitiveDataDiscoveryEnabled": {
                    "type": "String"
                  }
                },
                "variables": {
                  "enabledMalwareScanningExtension": {
                    "name": "OnUploadMalwareScanning",
                    "isEnabled": "true",
                    "additionalExtensionProperties": {
                      "CapGBPerMonthPerStorageAccount": "[parameters('capGBPerMonthPerStorageAccount')]"
                    }
                  },
                  "disabledMalwareScanningExtension": {
                    "name": "OnUploadMalwareScanning",
                    "isEnabled": "false"
                  },
                  "malwareScanningExtension": "[if(equals(parameters('isOnUploadMalwareScanningEnabled'),'true'), variables('enabledMalwareScanningExtension'), variables('disabledMalwareScanningExtension'))]"
                },
                "resources": [
                  {
                    "type": "Microsoft.Security/pricings",
                    "apiVersion": "2023-01-01",
                    "name": "StorageAccounts",
                    "properties": {
                      "subPlan": "DefenderForStorageV2",
                      "pricingTier": "Standard",
                      "extensions": [
                        "[variables('malwareScanningExtension')]",
                        {
                          "name": "SensitiveDataDiscovery",
                          "isEnabled": "[parameters('isSensitiveDataDiscoveryEnabled')]"
                        }
                      ]
                    }
                  }
                ],
                "outputs": {}
              }
            }
          }
        }
      }
    },
    "versions": [
      "1.5.0",
      "1.4.0",
      "1.3.0",
      "1.2.0",
      "1.1.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/cfdc5972-75b3-4418-8ae1-7f5c36839390",
  "name": "cfdc5972-75b3-4418-8ae1-7f5c36839390"
}
Bylawcfdc5972-75b3-4418-8ae1-7f5c36839390.bylaw.ps1 · 67 lines
# Converted from MDC_Microsoft_Defender_For_Storage_Full_DINE.json by ConvertTo-Bylaw.
Policy 'cfdc5972-75b3-4418-8ae1-7f5c36839390' {

    Properties @{
        DisplayName   = 'Configure Microsoft Defender for Storage to be enabled'
        Description   = 'Microsoft Defender for Storage is an Azure-native layer of security intelligence that detects potential threats to your storage accounts.
This policy will enable all Defender for Storage capabilities; Activity Monitoring, Malware Scanning and Sensitive Data Threat Detection. To learn more about Defender for Storage capabilities and benefits, visit aka.ms/DefenderForStorage.'
        Version       = '1.5.0'
        Category      = 'Security Center'
        PolicyVersion = '1.5.0'
        Mode          = 'All'
    }

    Parameter Effect @{
        AllowedValues = @('DeployIfNotExists', 'Disabled')
        Default       = 'DeployIfNotExists'
        DisplayName   = 'Effect'
        Description   = 'Enable or disable the execution of the policy'
    }
    Parameter IsOnUploadMalwareScanningEnabled @{
        AllowedValues = @('true', 'false')
        Default       = 'true'
        DisplayName   = 'Malware Scanning Enabled'
        Description   = 'Enable or disable the Malware Scanning add-on feature'
    }
    Parameter CapGBPerMonthPerStorageAccount @{
        Type        = 'Integer'
        Default     = 10000
        DisplayName = 'Cap GB Per Month Per Storage Account'
        Description = 'Limit the GB scanned per month for each storage account within the subscription.
Value must be an integer, 10GB or higher
Set to -1 for unlimited scanning'
    }
    Parameter IsSensitiveDataDiscoveryEnabled @{
        AllowedValues = @('true', 'false')
        Default       = 'true'
        DisplayName   = 'Sensitive Data Threat Detection Enabled'
        Description   = 'Enable or disable the Sensitive Data Threat Detection add-on feature'
    }

    Resource 'Microsoft.Resources/subscriptions'

    DeployIfNotExists 'Microsoft.Security/pricings' -Role 'Owner' -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 -Be 'OnUploadMalwareScanning'
                Field isEnabled | Must -Be (Param IsOnUploadMalwareScanningEnabled)
            } | Must -Be 1
            Count 'extensions[*]' -Where {
                Field name | Must -Be 'SensitiveDataDiscovery'
                Field isEnabled | Must -Be (Param IsSensitiveDataDiscoveryEnabled)
            } | Must -Be 1
        }
        Deployment @{
            TemplateFile = './templates/cfdc5972-75b3-4418-8ae1-7f5c36839390.json'
            Scope        = 'Subscription'
            Location     = 'westeurope'
            Parameters   = [ordered]@{
                isOnUploadMalwareScanningEnabled = (Param IsOnUploadMalwareScanningEnabled)
                capGBPerMonthPerStorageAccount   = (Param CapGBPerMonthPerStorageAccount)
                isSensitiveDataDiscoveryEnabled  = (Param IsSensitiveDataDiscoveryEnabled)
            }
        }
    }
}

Its deployment templates are written beside it:

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