Bylaw

Gallery › Storage › Azure built-in policies

Storage accounts should restrict network access using virtual network rules (excluding storage accounts created by Databricks)

Converted Policy Audit Deny Disabled Mode Indexed Version 1.0.0

Protect your storage accounts from potential threats using virtual network rules as a preferred method instead of IP-based filtering. Disabling IP-based filtering prevents public IPs from accessing your storage accounts.

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

Azure Policy JSONStorageAccountOnlyVnetRulesEnabledWithDatabricksExcluded_Audit.json · 64 lines
{
  "properties": {
    "displayName": "Storage accounts should restrict network access using virtual network rules (excluding storage accounts created by Databricks)",
    "policyType": "BuiltIn",
    "mode": "Indexed",
    "description": "Protect your storage accounts from potential threats using virtual network rules as a preferred method instead of IP-based filtering. Disabling IP-based filtering prevents public IPs from accessing your storage accounts.",
    "metadata": {
      "version": "1.0.0",
      "category": "Storage"
    },
    "version": "1.0.0",
    "parameters": {
      "effect": {
        "type": "String",
        "metadata": {
          "displayName": "Effect",
          "description": "Enable or disable the execution of the audit policy"
        },
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Storage/storageAccounts"
          },
          {
            "value": "[resourcegroup().managedBy]",
            "notContains": "/providers/Microsoft.Databricks/"
          },
          {
            "anyOf": [
              {
                "field": "Microsoft.Storage/storageAccounts/networkAcls.defaultAction",
                "notEquals": "Deny"
              },
              {
                "count": {
                  "field": "Microsoft.Storage/storageAccounts/networkAcls.ipRules[*]"
                },
                "greaterOrEquals": 1
              }
            ]
          }
        ]
      },
      "then": {
        "effect": "[parameters('effect')]"
      }
    },
    "versions": [
      "1.0.0"
    ]
  },
  "id": "/providers/Microsoft.Authorization/policyDefinitions/db4f9b05-5ffd-4b34-b714-3c710dbb3fd6",
  "name": "db4f9b05-5ffd-4b34-b714-3c710dbb3fd6"
}
Bylawdb4f9b05-5ffd-4b34-b714-3c710dbb3fd6.bylaw.ps1 · 36 lines
# Converted from StorageAccountOnlyVnetRulesEnabledWithDatabricksExcluded_Audit.json by ConvertTo-Bylaw.
Policy 'db4f9b05-5ffd-4b34-b714-3c710dbb3fd6' {

    Properties @{
        DisplayName   = 'Storage accounts should restrict network access using virtual network rules (excluding storage accounts created by Databricks)'
        Description   = 'Protect your storage accounts from potential threats using virtual network rules as a preferred method instead of IP-based filtering. Disabling IP-based filtering prevents public IPs from accessing your storage accounts.'
        Version       = '1.0.0'
        Category      = 'Storage'
        PolicyVersion = '1.0.0'
        Mode          = 'Indexed'
    }

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

    Resource 'Microsoft.Storage/storageAccounts' {

        When {
            Arm '[resourcegroup().managedBy]' | Must -Not -ContainText '/providers/Microsoft.Databricks/'
        }

        Require 'networkAcls.defaultAction is Deny' {
            Field networkAcls.defaultAction | Must -Be 'Deny'
        }

        Require 'networkAcls.ipRules is as required' {
            Count 'networkAcls.ipRules[*]' | Must -Be 0
        }
    }

    Effect (Param Effect)
}

Source: built-in-policies/policyDefinitions/Storage/StorageAccountOnlyVnetRulesEnabledWithDatabricksExcluded_Audit.json in Azure/azure-policy, under the MIT licence.