Press "Enter" to skip to content

ipSecurityRestrictions on Azure App Services

With the powershell scripts underneath you can easily close and open traffic towards your azure app services.
Note: by adjusting the resource name variable you can add appsettings to your staging slot as well.


### Open to the world ###
Write-Host “Open all traffic to app service”
$resourceGroupName = ‘TOBEFILLED’
$resourceName = ‘YOURAPPNAMEHERE’ + ‘/web’
$r = Get-AzureRmResource -ResourceGroupName $resourceGroupName -ResourceType Microsoft.Web/sites/config -ResourceName $resourceName -ApiVersion 2016-08-01

$p = $r.Properties
$empty = @()
$p.ipSecurityRestrictions = $empty

Set-AzureRmResource -ResourceGroupName $resourceGroupName -ResourceType Microsoft.Web/sites/config -ResourceName $resourceName -ApiVersion 2016-08-01 -PropertyObject $p

Script: open to the world

### Open to specified IP addresses ###
Write-Host “Block all traffic to app service except specified ips”
$resourceGroupName = ‘TOBEFILLED’
$resourceName = ‘YOURAPPNAMEHERE’ + ‘/web’
$r = Get-AzureRmResource -ResourceGroupName $resourceGroupName -ResourceType Microsoft.Web/sites/config -ResourceName $resourceName -ApiVersion 2016-08-01

$p = $r.Properties
$p.ipSecurityRestrictions = @()
$restriction = @{}
$restriction.Add(“ipAddress”,”YOURIPADDRESSHERE”)
$restriction.Add(“subnetMask”,”255.255.0.0″)
$p.ipSecurityRestrictions+= $restriction

Set-AzureRmResource -ResourceGroupName $resourceGroupName -ResourceType Microsoft.Web/sites/config -ResourceName $resourceName -ApiVersion 2016-08-01 -PropertyObject $p

Script: set IP restrictions

Be First to Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.