Configure Azure Storage firewalls and virtual networks

Azure Storage provides a layered security model. This model enables you to secure and control the level of access to your storage accounts that your applications and enterprise environments demand, based on the type and subset of networks​ used. When network rules are configured, only applications requesting data over the specified set of networks can access a storage account. You can limit access to your storage account to requests originating from specified IP addresses, IP ranges or from a list of subnets in an Azure Virtual Network (VNet).

Storage accounts have a public endpoint that is accessible through the internet. You can also create Private Endpoints for your storage account, which assigns a private IP address from your VNet to the storage account, and secures all traffic between your VNet and the storage account over a private link. The Azure storage firewall provides access control access for the public endpoint of your storage account. You can also use the firewall to block all access through the public endpoint when using private endpoints. Your storage firewall configuration also enables select trusted Azure platform services to access the storage account securely.

An application that accesses a storage account when network rules are in effect still requires proper authorization for the request. Authorization is supported with Azure Active Directory (Azure AD) credentials for blobs and queues, with a valid account access key, or with an SAS token.

Important

Turning on firewall rules for your storage account blocks incoming requests for data by default, unless the requests originate from a service operating within an Azure Virtual Network (VNet) or from allowed public IP addresses. Requests that are blocked include those from other Azure services, from the Azure portal, from logging and metrics services, and so on.

You can grant access to Azure services that operate from within a VNet by allowing traffic from the subnet hosting the service instance. You can also enable a limited number of scenarios through the Exceptions mechanism described below. To access data from the storage account through the Azure portal, you would need to be on a machine within the trusted boundary (either IP or VNet) that you set up.

Note

This article has been updated to use the new Azure PowerShell Az module. You can still use the AzureRM module, which will continue to receive bug fixes until at least December 2020. To learn more about the new Az module and AzureRM compatibility, see Introducing the new Azure PowerShell Az module. For Az module installation instructions, see Install Azure PowerShell.

Scenarios

To secure your storage account, you should first configure a rule to deny access to traffic from all networks (including internet traffic) on the public endpoint, by default. Then, you should configure rules that grant access to traffic from specific VNets. You can also configure rules to grant access to traffic from select public internet IP address ranges, enabling connections from specific internet or on-premises clients. This configuration enables you to build a secure network boundary for your applications.

You can combine firewall rules that allow access from specific virtual networks and from public IP address ranges on the same storage account. Storage firewall rules can be applied to existing storage accounts, or when creating new storage accounts.

Storage firewall rules apply to the public endpoint of a storage account. You don't need any firewall access rules to allow traffic for private endpoints of a storage account. The process of approving the creation of a private endpoint grants implicit access to traffic from the subnet that hosts the private endpoint.

Network rules are enforced on all network protocols to Azure storage, including REST and SMB. To access data using tools such as the Azure portal, Storage Explorer, and AZCopy, explicit network rules must be configured.

Once network rules are applied, they're enforced for all requests. SAS tokens that grant access to a specific IP address serve to limit the access of the token holder, but don't grant new access beyond configured network rules.

Virtual machine disk traffic (including mount and unmount operations, and disk IO) is not affected by network rules. REST access to page blobs is protected by network rules.

Classic storage accounts do not support firewalls and virtual networks.

You can use unmanaged disks in storage accounts with network rules applied to backup and restore VMs by creating an exception. This process is documented in the Exceptions section of this article. Firewall exceptions aren't applicable with managed disks as they're already managed by Azure.

Change the default network access rule

By default, storage accounts accept connections from clients on any network. To limit access to selected networks, you must first change the default action.

Warning

Making changes to network rules can impact your applications' ability to connect to Azure Storage. Setting the default network rule to deny blocks all access to the data unless specific network rules that grant access are also applied. Be sure to grant access to any allowed networks using network rules before you change the default rule to deny access.

Managing default network access rules

You can manage default network access rules for storage accounts through the Azure portal, PowerShell, or CLIv2.

Azure portal

  1. Go to the storage account you want to secure.

  2. Click on the settings menu called Firewalls and virtual networks.

  3. To deny access by default, choose to allow access from Selected networks. To allow traffic from all networks, choose to allow access from All networks.

  4. Click Save to apply your changes.

PowerShell

  1. Install the Azure PowerShell and sign in.

  2. Display the status of the default rule for the storage account.

    (Get-AzStorageAccountNetworkRuleSet -ResourceGroupName "myresourcegroup" -AccountName "mystorageaccount").DefaultAction
    
  3. Set the default rule to deny network access by default.

    Update-AzStorageAccountNetworkRuleSet -ResourceGroupName "myresourcegroup" -Name "mystorageaccount" -DefaultAction Deny
    
  4. Set the default rule to allow network access by default.

    Update-AzStorageAccountNetworkRuleSet -ResourceGroupName "myresourcegroup" -Name "mystorageaccount" -DefaultAction Allow
    

CLIv2

  1. Install the Azure CLI and sign in.

  2. Display the status of the default rule for the storage account.

    az storage account show --resource-group "myresourcegroup" --name "mystorageaccount" --query networkRuleSet.defaultAction
    
  3. Set the default rule to deny network access by default.

    az storage account update --resource-group "myresourcegroup" --name "mystorageaccount" --default-action Deny
    
  4. Set the default rule to allow network access by default.

    az storage account update --resource-group "myresourcegroup" --name "mystorageaccount" --default-action Allow
    

Grant access from a virtual network

You can configure storage accounts to allow access only from specific subnets. The allowed subnets may belong to a VNet in the same subscription, or those in a different subscription, including subscriptions belonging to a different Azure Active Directory tenant.

Enable a Service endpoint for Azure Storage within the VNet. The service endpoint routes traffic from the VNet through an optimal path to the Azure Storage service. The identities of the subnet and the virtual network are also transmitted with each request. Administrators can then configure network rules for the storage account that allow requests to be received from specific subnets in a VNet. Clients granted access via these network rules must continue to meet the authorization requirements of the storage account to access the data.

Each storage account supports up to 100 virtual network rules, which may be combined with IP network rules.

Available virtual network regions

In general, service endpoints work between virtual networks and service instances in the same Azure region. When using service endpoints with Azure Storage, this scope grows to include the paired region. Service endpoints allow continuity during a regional failover and access to read-only geo-redundant storage (RA-GRS) instances. Network rules that grant access from a virtual network to a storage account also grant access to any RA-GRS instance.

When planning for disaster recovery during a regional outage, you should create the VNets in the paired region in advance. Enable service endpoints for Azure Storage, with network rules granting access from these alternative virtual networks. Then apply these rules to your geo-redundant storage accounts.

Note

Service endpoints don't apply to traffic outside the region of the virtual network and the designated region pair. You can only apply network rules granting access from virtual networks to storage accounts in the primary region of a storage account or in the designated paired region.

Required permissions

To apply a virtual network rule to a storage account, the user must have the appropriate permissions for the subnets being added. The permission needed is Join Service to a Subnet and is included in the Storage Account Contributor built-in role. It can also be added to custom role definitions.

Storage account and the virtual networks granted access may be in different subscriptions, including subscriptions that are a part of a different Azure AD tenant.

Note

Configuration of rules that grant access to subnets in virtual networks that are a part of a different Azure Active Directory tenant are currently only supported through Powershell, CLI and REST APIs. Such rules cannot be configured through the Azure portal, though they may be viewed in the portal.

Managing virtual network rules

You can manage virtual network rules for storage accounts through the Azure portal, PowerShell, or CLIv2.

Azure portal

  1. Go to the storage account you want to secure.

  2. Click on the settings menu called Firewalls and virtual networks.

  3. Check that you've selected to allow access from Selected networks.

  4. To grant access to a virtual network with a new network rule, under Virtual networks, click Add existing virtual network, select Virtual networks and Subnets options, and then click Add. To create a new virtual network and grant it access, click Add new virtual network. Provide the information necessary to create the new virtual network, and then click Create.

    Note

    If a service endpoint for Azure Storage wasn't previously configured for the selected virtual network and subnets, you can configure it as part of this operation.

    Presently, only virtual networks belonging to the same Azure Active Directory tenant are shown for selection during rule creation. To grant access to a subnet in a virtual network belonging to another tenant, please use Powershell, CLI or REST APIs.

  5. To remove a virtual network or subnet rule, click ... to open the context menu for the virtual network or subnet, and click Remove.

  6. Click Save to apply your changes.

PowerShell

  1. Install the Azure PowerShell and sign in.

  2. List virtual network rules.

    (Get-AzStorageAccountNetworkRuleSet -ResourceGroupName "myresourcegroup" -AccountName "mystorageaccount").VirtualNetworkRules
    
  3. Enable service endpoint for Azure Storage on an existing virtual network and subnet.

    Get-AzVirtualNetwork -ResourceGroupName "myresourcegroup" -Name "myvnet" | Set-AzVirtualNetworkSubnetConfig -Name "mysubnet" -AddressPrefix "10.0.0.0/24" -ServiceEndpoint "Microsoft.Storage" | Set-AzVirtualNetwork
    
  4. Add a network rule for a virtual network and subnet.

    $subnet = Get-AzVirtualNetwork -ResourceGroupName "myresourcegroup" -Name "myvnet" | Get-AzVirtualNetworkSubnetConfig -Name "mysubnet"
    Add-AzStorageAccountNetworkRule -ResourceGroupName "myresourcegroup" -Name "mystorageaccount" -VirtualNetworkResourceId $subnet.Id
    

    Tip

    To add a network rule for a subnet in a VNet belonging to another Azure AD tenant, use a fully-qualified VirtualNetworkResourceId parameter in the form "/subscriptions/subscription-ID/resourceGroups/resourceGroup-Name/providers/Microsoft.Network/virtualNetworks/vNet-name/subnets/subnet-name".

  5. Remove a network rule for a virtual network and subnet.

    $subnet = Get-AzVirtualNetwork -ResourceGroupName "myresourcegroup" -Name "myvnet" | Get-AzVirtualNetworkSubnetConfig -Name "mysubnet"
    Remove-AzStorageAccountNetworkRule -ResourceGroupName "myresourcegroup" -Name "mystorageaccount" -VirtualNetworkResourceId $subnet.Id
    

Important

Be sure to set the default rule to deny, or network rules have no effect.

CLIv2

  1. Install the Azure CLI and sign in.

  2. List virtual network rules.

    az storage account network-rule list --resource-group "myresourcegroup" --account-name "mystorageaccount" --query virtualNetworkRules
    
  3. Enable service endpoint for Azure Storage on an existing virtual network and subnet.

    az network vnet subnet update --resource-group "myresourcegroup" --vnet-name "myvnet" --name "mysubnet" --service-endpoints "Microsoft.Storage"
    
  4. Add a network rule for a virtual network and subnet.

    $subnetid=(az network vnet subnet show --resource-group "myresourcegroup" --vnet-name "myvnet" --name "mysubnet" --query id --output tsv)
    az storage account network-rule add --resource-group "myresourcegroup" --account-name "mystorageaccount" --subnet $subnetid
    

    Tip

    To add a rule for a subnet in a VNet belonging to another Azure AD tenant, use a fully-qualified subnet ID in the form "/subscriptions/<subscription-ID>/resourceGroups/<resourceGroup-Name>/providers/Microsoft.Network/virtualNetworks/<vNet-name>/subnets/<subnet-name>".

    You can use the subscription parameter to retrieve the subnet ID for a VNet belonging to another Azure AD tenant.

  5. Remove a network rule for a virtual network and subnet.

    $subnetid=(az network vnet subnet show --resource-group "myresourcegroup" --vnet-name "myvnet" --name "mysubnet" --query id --output tsv)
    az storage account network-rule remove --resource-group "myresourcegroup" --account-name "mystorageaccount" --subnet $subnetid
    

Important

Be sure to set the default rule to deny, or network rules have no effect.

Grant access from an internet IP range

You can configure storage accounts to allow access from specific public internet IP address ranges. This configuration grants access to specific internet-based services and on-premises networks and blocks general internet traffic.

Provide allowed internet address ranges using CIDR notation in the form 16.17.18.0/24 or as individual IP addresses like 16.17.18.19.

Note

Small address ranges using "/31" or "/32" prefix sizes are not supported. These ranges should be configured using individual IP address rules.

IP network rules are only allowed for public internet IP addresses. IP address ranges reserved for private networks (as defined in RFC 1918) aren't allowed in IP rules. Private networks include addresses that start with 10.*, 172.16.* - 172.31.*, and 192.168.*.

Note

IP network rules have no effect on requests originating from the same Azure region as the storage account. Use Virtual network rules to allow same-region requests.

Note

Services deployed in the same region as the storage account use private Azure IP addresses for communication. Thus, you cannot restrict access to specific Azure services based on their public inbound IP address range.

Only IPV4 addresses are supported for configuration of storage firewall rules.

Each storage account supports up to 100 IP network rules.

Configuring access from on-premises networks

To grant access from your on-premises networks to your storage account with an IP network rule, you must identify the internet facing IP addresses used by your network. Contact your network administrator for help.

If you are using ExpressRoute from your premises, for public peering or Microsoft peering, you will need to identify the NAT IP addresses that are used. For public peering, each ExpressRoute circuit by default uses two NAT IP addresses applied to Azure service traffic when the traffic enters the Microsoft Azure network backbone. For Microsoft peering, the NAT IP addresses used are either customer provided or are provided by the service provider. To allow access to your service resources, you must allow these public IP addresses in the resource IP firewall setting. To find your public peering ExpressRoute circuit IP addresses, open a support ticket with ExpressRoute via the Azure portal. Learn more about NAT for ExpressRoute public and Microsoft peering.

Managing IP network rules

You can manage IP network rules for storage accounts through the Azure portal, PowerShell, or CLIv2.

Azure portal

  1. Go to the storage account you want to secure.

  2. Click on the settings menu called Firewalls and virtual networks.

  3. Check that you've selected to allow access from Selected networks.

  4. To grant access to an internet IP range, enter the IP address or address range (in CIDR format) under Firewall > Address Range.

  5. To remove an IP network rule, click the trash can icon next to the address range.

  6. Click Save to apply your changes.

PowerShell

  1. Install the Azure PowerShell and sign in.

  2. List IP network rules.

    (Get-AzStorageAccountNetworkRuleSet -ResourceGroupName "myresourcegroup" -AccountName "mystorageaccount").IPRules
    
  3. Add a network rule for an individual IP address.

    Add-AzStorageAccountNetworkRule -ResourceGroupName "myresourcegroup" -AccountName "mystorageaccount" -IPAddressOrRange "16.17.18.19"
    
  4. Add a network rule for an IP address range.

    Add-AzStorageAccountNetworkRule -ResourceGroupName "myresourcegroup" -AccountName "mystorageaccount" -IPAddressOrRange "16.17.18.0/24"
    
  5. Remove a network rule for an individual IP address.

    Remove-AzStorageAccountNetworkRule -ResourceGroupName "myresourcegroup" -AccountName "mystorageaccount" -IPAddressOrRange "16.17.18.19"
    
  6. Remove a network rule for an IP address range.

    Remove-AzStorageAccountNetworkRule -ResourceGroupName "myresourcegroup" -AccountName "mystorageaccount" -IPAddressOrRange "16.17.18.0/24"
    

Important

Be sure to set the default rule to deny, or network rules have no effect.

CLIv2

  1. Install the Azure CLI and sign in.

  2. List IP network rules.

    az storage account network-rule list --resource-group "myresourcegroup" --account-name "mystorageaccount" --query ipRules
    
  3. Add a network rule for an individual IP address.

    az storage account network-rule add --resource-group "myresourcegroup" --account-name "mystorageaccount" --ip-address "16.17.18.19"
    
  4. Add a network rule for an IP address range.

    az storage account network-rule add --resource-group "myresourcegroup" --account-name "mystorageaccount" --ip-address "16.17.18.0/24"
    
  5. Remove a network rule for an individual IP address.

    az storage account network-rule remove --resource-group "myresourcegroup" --account-name "mystorageaccount" --ip-address "16.17.18.19"
    
  6. Remove a network rule for an IP address range.

    az storage account network-rule remove --resource-group "myresourcegroup" --account-name "mystorageaccount" --ip-address "16.17.18.0/24"
    

Important

Be sure to set the default rule to deny, or network rules have no effect.

Exceptions

Network rules help to create a secure environment for connections between your applications and your data for most scenarios. However, some applications depend on Azure services that cannot be uniquely isolated through virtual network or IP address rules. But such services must be granted to storage to enable full application functionality. In such situations, you can use the Allow trusted Microsoft services... setting to enable such services to access your data, logs, or analytics.

Trusted Microsoft services

Some Microsoft services operate from networks that can't be included in your network rules. You can grant a subset of such trusted Microsoft services access to the storage account, while maintaining network rules for other apps. These trusted services will then use strong authentication to connect to your storage account securely. We've enabled two modes of trusted access for Microsoft services.

  • Resources of some services, when registered in your subscription, can access your storage account in the same subscription for select operations, such as writing logs or backup.
  • Resources of some services can be granted explicit access to your storage account by assigning an RBAC role to its system-assigned managed identity.

When you enable the Allow trusted Microsoft services... setting, resources of the following services that are registered in the same subscription as your storage account are granted access for a limited set of operations as described:

Service Resource Provider Name Operations allowed
Azure Backup Microsoft.RecoveryServices Run backups and restores of unmanaged disks in IAAS virtual machines. (not required for managed disks). Learn more.
Azure Data Box Microsoft.DataBox Enables import of data to Azure using Data Box. Learn more.
Azure DevTest Labs Microsoft.DevTestLab Custom image creation and artifact installation. Learn more.
Azure Event Grid Microsoft.EventGrid Enable Blob Storage event publishing and allow Event Grid to publish to storage queues. Learn about blob storage events and publishing to queues.
Azure Event Hubs Microsoft.EventHub Archive data with Event Hubs Capture. Learn More.
Azure File Sync Microsoft.StorageSync Enables you to transform your on-prem file server to a cache for Azure File shares. Allowing for multi-site sync, fast disaster-recovery, and cloud-side backup. Learn more
Azure HDInsight Microsoft.HDInsight Provision the initial contents of the default file system for a new HDInsight cluster. Learn more.
Azure Monitor Microsoft.Insights Allows writing of monitoring data to a secured storage account Learn more.
Azure Networking Microsoft.Network Store and analyze network traffic logs. Learn more.
Azure Site Recovery Microsoft.SiteRecovery Enable replication for disaster-recovery of Azure IaaS virtual machines when using firewall-enabled cache, source, or target storage accounts. Learn more.

The Allow trusted Microsoft services... setting also allows a particular instance of the below services to access the storage account, if you explicitly assign an RBAC role to the system-assigned managed identity for that resource instance. In this case, the scope of access for the instance corresponds to the RBAC role assigned to the managed identity.

Service Resource Provider Name Purpose
Azure Data Factory Microsoft.DataFactory/factories Allows access to storage accounts through the ADF runtime.
Azure Logic Apps Microsoft.Logic/workflows Enables logic apps to access storage accounts. Learn more.
Azure Machine Learning Service Microsoft.MachineLearningServices Authorized Azure Machine Learning workspaces write experiment output, models, and logs to Blob storage. Learn more.
Azure SQL Data Warehouse Microsoft.Sql Allows import and export of data from specific SQL Database instances using PolyBase. Learn more.
Azure Stream Analytics Microsoft.StreamAnalytics Allows data from a streaming job to be written to Blob storage. This feature is currently in preview. Learn more.

Storage analytics data access

In some cases, access to read diagnostic logs and metrics is required from outside the network boundary. When configuring trusted services access to the storage account, you can allow read-access for the log files, metrics tables, or both. Learn more about working with storage analytics.

Managing exceptions

You can manage network rule exceptions through the Azure portal, PowerShell, or Azure CLI v2.

Azure portal

  1. Go to the storage account you want to secure.

  2. Click on the settings menu called Firewalls and virtual networks.

  3. Check that you've selected to allow access from Selected networks.

  4. Under Exceptions, select the exceptions you wish to grant.

  5. Click Save to apply your changes.

PowerShell

  1. Install the Azure PowerShell and sign in.

  2. Display the exceptions for the storage account network rules.

    (Get-AzStorageAccountNetworkRuleSet -ResourceGroupName "myresourcegroup" -Name "mystorageaccount").Bypass
    
  3. Configure the exceptions to the storage account network rules.

    Update-AzStorageAccountNetworkRuleSet -ResourceGroupName "myresourcegroup" -Name "mystorageaccount" -Bypass AzureServices,Metrics,Logging
    
  4. Remove the exceptions to the storage account network rules.

    Update-AzStorageAccountNetworkRuleSet -ResourceGroupName "myresourcegroup" -Name "mystorageaccount" -Bypass None
    

Important

Be sure to set the default rule to deny, or removing exceptions have no effect.

CLIv2

  1. Install the Azure CLI and sign in.

  2. Display the exceptions for the storage account network rules.

    az storage account show --resource-group "myresourcegroup" --name "mystorageaccount" --query networkRuleSet.bypass
    
  3. Configure the exceptions to the storage account network rules.

    az storage account update --resource-group "myresourcegroup" --name "mystorageaccount" --bypass Logging Metrics AzureServices
    
  4. Remove the exceptions to the storage account network rules.

    az storage account update --resource-group "myresourcegroup" --name "mystorageaccount" --bypass None
    

Important

Be sure to set the default rule to deny, or removing exceptions have no effect.

Next steps

Learn more about Azure Network service endpoints in Service endpoints.

Dig deeper into Azure Storage security in Azure Storage security guide.