Bylaw

Gallery › Storage › Azure built-in policies

Storage accounts should restrict network access using virtual network rules (excluding storage accounts managed by ARO)

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. Storage accounts in resource groups managed by Azure Red Hat OpenShift are excluded from evaluation.

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

Azure Policy JSONStorageAccountOnlyVnetRulesEnabledWithAROExcluded_Audit.json · 64 lines
{
  "properties": {
    "displayName": "Storage accounts should restrict network access using virtual network rules (excluding storage accounts managed by ARO)",
    "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. Storage accounts in resource groups managed by Azure Red Hat OpenShift are excluded from evaluation.",
    "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 policy"
        },
        "allowedValues": [
          "Audit",
          "Deny",
          "Disabled"
        ],
        "defaultValue": "Audit"
      }
    },
    "policyRule": {
      "if": {
        "allOf": [
          {
            "field": "type",
            "equals": "Microsoft.Storage/storageAccounts"
          },
          {
            "value": "[resourcegroup().managedBy]",
            "notContains": "/providers/Microsoft.RedHatOpenShift/"
          },
          {
            "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/ed9bd083-7bfb-4fec-bbb4-12635e096a09",
  "name": "ed9bd083-7bfb-4fec-bbb4-12635e096a09"
}
Bylawed9bd083-7bfb-4fec-bbb4-12635e096a09.bylaw.ps1 · 36 lines
# Converted from StorageAccountOnlyVnetRulesEnabledWithAROExcluded_Audit.json by ConvertTo-Bylaw.
Policy 'ed9bd083-7bfb-4fec-bbb4-12635e096a09' {

    Properties @{
        DisplayName   = 'Storage accounts should restrict network access using virtual network rules (excluding storage accounts managed by ARO)'
        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. Storage accounts in resource groups managed by Azure Red Hat OpenShift are excluded from evaluation.'
        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 policy'
    }

    Resource 'Microsoft.Storage/storageAccounts' {

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

        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/StorageAccountOnlyVnetRulesEnabledWithAROExcluded_Audit.json in Azure/azure-policy, under the MIT licence.