Gallery › Storage › Azure built-in policies
Storage accounts should restrict network access using virtual network rules
Converted Policy Audit Deny Disabled Mode Indexed Version 1.1.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 JSONStorageAccountOnlyVnetRulesEnabled_Audit.json · 123 lines
{
"properties": {
"displayName": "Storage accounts should restrict network access using virtual network rules",
"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.1.0",
"category": "Storage"
},
"version": "1.1.0",
"parameters": {
"effect": {
"type": "String",
"metadata": {
"displayName": "Effect",
"description": "Enable or disable the execution of the audit policy"
},
"allowedValues": [
"Audit",
"Deny",
"Disabled"
],
"defaultValue": "Audit"
},
"excludedManagedByResourceProviders": {
"type": "Array",
"metadata": {
"displayName": "Managed services to exclude",
"description": "Select managed services whose storage accounts should be excluded from this policy, or select all managed resource groups. Leave empty to evaluate all storage accounts."
},
"allowedValues": [
"Azure Red Hat OpenShift",
"Azure Databricks",
"Microsoft Purview",
"All managed resource groups"
],
"defaultValue": []
}
},
"policyRule": {
"if": {
"allOf": [
{
"field": "type",
"equals": "Microsoft.Storage/storageAccounts"
},
{
"anyOf": [
{
"value": "[contains(parameters('excludedManagedByResourceProviders'), 'Azure Red Hat OpenShift')]",
"equals": false
},
{
"value": "[resourcegroup().managedBy]",
"notContains": "/providers/Microsoft.RedHatOpenShift/"
}
]
},
{
"anyOf": [
{
"value": "[contains(parameters('excludedManagedByResourceProviders'), 'Azure Databricks')]",
"equals": false
},
{
"value": "[resourcegroup().managedBy]",
"notContains": "/providers/Microsoft.Databricks/"
}
]
},
{
"anyOf": [
{
"value": "[contains(parameters('excludedManagedByResourceProviders'), 'Microsoft Purview')]",
"equals": false
},
{
"value": "[resourcegroup().managedBy]",
"notContains": "/providers/Microsoft.Purview/"
}
]
},
{
"anyOf": [
{
"value": "[contains(parameters('excludedManagedByResourceProviders'), 'All managed resource groups')]",
"equals": false
},
{
"value": "[empty(resourcegroup().managedBy)]",
"equals": true
}
]
},
{
"anyOf": [
{
"field": "Microsoft.Storage/storageAccounts/networkAcls.defaultAction",
"notEquals": "Deny"
},
{
"count": {
"field": "Microsoft.Storage/storageAccounts/networkAcls.ipRules[*]"
},
"greaterOrEquals": 1
}
]
}
]
},
"then": {
"effect": "[parameters('effect')]"
}
},
"versions": [
"1.1.0",
"1.0.1"
]
},
"id": "/providers/Microsoft.Authorization/policyDefinitions/2a1a9cdf-e04d-429a-8416-3bfb72a1b26f",
"name": "2a1a9cdf-e04d-429a-8416-3bfb72a1b26f"
}Bylaw2a1a9cdf-e04d-429a-8416-3bfb72a1b26f.bylaw.ps1 · 58 lines
# Converted from StorageAccountOnlyVnetRulesEnabled_Audit.json by ConvertTo-Bylaw.
Policy '2a1a9cdf-e04d-429a-8416-3bfb72a1b26f' {
Properties @{
DisplayName = 'Storage accounts should restrict network access using virtual network rules'
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.1.0'
Category = 'Storage'
PolicyVersion = '1.1.0'
Mode = 'Indexed'
}
Parameter Effect @{
AllowedValues = @('Audit', 'Deny', 'Disabled')
Default = 'Audit'
DisplayName = 'Effect'
Description = 'Enable or disable the execution of the audit policy'
}
Parameter ExcludedManagedByResourceProviders @{
Type = 'Array'
AllowedValues = @('Azure Red Hat OpenShift', 'Azure Databricks', 'Microsoft Purview', 'All managed resource groups')
Default = @()
DisplayName = 'Managed services to exclude'
Description = 'Select managed services whose storage accounts should be excluded from this policy, or select all managed resource groups. Leave empty to evaluate all storage accounts.'
}
Resource 'Microsoft.Storage/storageAccounts' {
When {
AnyOf {
Arm '[contains(parameters(''excludedManagedByResourceProviders''), ''Azure Red Hat OpenShift'')]' | Must -Be $false
Arm '[resourcegroup().managedBy]' | Must -Not -ContainText '/providers/Microsoft.RedHatOpenShift/'
}
AnyOf {
Arm '[contains(parameters(''excludedManagedByResourceProviders''), ''Azure Databricks'')]' | Must -Be $false
Arm '[resourcegroup().managedBy]' | Must -Not -ContainText '/providers/Microsoft.Databricks/'
}
AnyOf {
Arm '[contains(parameters(''excludedManagedByResourceProviders''), ''Microsoft Purview'')]' | Must -Be $false
Arm '[resourcegroup().managedBy]' | Must -Not -ContainText '/providers/Microsoft.Purview/'
}
AnyOf {
Arm '[contains(parameters(''excludedManagedByResourceProviders''), ''All managed resource groups'')]' | Must -Be $false
Arm '[empty(resourcegroup().managedBy)]' | Must -Be $true
}
}
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/StorageAccountOnlyVnetRulesEnabled_Audit.json in Azure/azure-policy, under the MIT licence.
Bylaw