Azure Storage Accounts: Configure Storage Firewall IP and Subnet Rules
See more Azure Storage Accounts Examples
Reads and preserves existing network ACLs, adds an IP rule and optionally a subnet rule, then prepares publicNetworkAccess=Enabled with defaultAction=Deny. Replace the documentation IP with a real public outbound IPv4 address. A subnet must already have the appropriate Storage service endpoint.
Review the target and set applyChanges=true to submit. This can interrupt clients and can reopen a disabled public endpoint for selected sources. Existing bypass exceptions and resource-instance rules remain in effect. These rules do not create private endpoints, configure DNS, or grant data permissions. Coordinate concurrent network-policy writers.
See Storage firewall and network access for same-region Azure traffic, service endpoints, private networking, and service-specific limitations.
These calls manage Azure resources at management.azure.com. They do not upload or download stored data. Supply a current Microsoft Entra access token for Azure Resource Manager in private qa_data/tokens/azureToken.json, with a nonempty access_token string. For v2 client credentials, request https://management.azure.com/.default; obtain a new token when it expires. A storage account key, SAS, Microsoft Graph token, or Storage data-plane token is not an ARM token. Never print the token or commit its file.
Azure RBAC must grant the caller the required management actions at the appropriate scope. An app registration alone does not grant resource access. Management permissions and blob/file data permissions are distinct. These examples target public Azure; sovereign clouds require the corresponding authority, ARM endpoint, token audience, and continuation-host validation.
Chilkat Classic ASP Downloads
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<%
success = 0
set stringCompare = Server.CreateObject("Chilkat.StringBuilder")
' This example requires the Chilkat API to have been previously unlocked.
' See Global.UnlockBundle for sample code.
' This is Azure Resource Manager (the management plane), not a blob data request.
' Load an unexpired Microsoft Entra token whose audience is Azure Resource Manager.
' For the v2 token endpoint, request scope https://management.azure.com/.default.
' Keep the token file private and out of source control and public web directories.
set token = Server.CreateObject("Chilkat.JsonObject")
token.Strict = 1
success = token.LoadFile("qa_data/tokens/azureToken.json")
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not load the private Azure Resource Manager token file.") & "</pre>"
Response.End
End If
If ((token.JsonTypeOf("access_token") <> 1) Or (token.StringOfEquals("access_token","",1) = 1)) Then
Response.Write "<pre>" & Server.HTMLEncode( "A nonempty access_token string is required.") & "</pre>"
Response.End
End If
' Use your subscription ID as a string. The all-zero value is only a placeholder.
subscriptionId = "00000000-0000-0000-0000-000000000000"
set http = Server.CreateObject("Chilkat.Http")
http.AuthToken = token.StringOf("access_token")
http.Accept = "application/json"
http.RequireSslCertVerify = 1
http.FollowRedirects = 0
http.ConnectTimeout = 30
http.ReadTimeout = 60
success = http.SetUrlVar("subscriptionId",subscriptionId)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not encode subscription ID.") & "</pre>"
Response.End
End If
ERROR: ASP example cannot use request or response as a variable name.
set result = Server.CreateObject("Chilkat.JsonObject")
result.Strict = 1
set parsed = Server.CreateObject("Chilkat.Url")
resourceGroupName = "my-resource-group"
success = http.SetUrlVar("resourceGroupName",resourceGroupName)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not encode resource group.") & "</pre>"
Response.End
End If
accountName = "youruniquestorageaccount"
success = http.SetUrlVar("accountName",accountName)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not encode account name.") & "</pre>"
Response.End
End If
resourceUrl = "https://management.azure.com/subscriptions/{$subscriptionId}/resourceGroups/{$resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{$accountName}?api-version=2026-09-01"
success = http.HttpNoBody("GET",resourceUrl,response)
If (response.StatusCode = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( "No HTTP response. Inspect LastErrorText privately; it may contain credentials.") & "</pre>"
Response.End
End If
If ((response.StatusCode <> 200)) Then
Response.Write "<pre>" & Server.HTMLEncode( "HTTP status: " & response.StatusCode) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "Request ID: " & response.GetHeaderField("x-ms-request-id")) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "Retry-After: " & response.GetHeaderField("Retry-After")) & "</pre>"
' Inspect the error body privately. Do not log tokens, headers, or full responses.
' For 401 check the token/audience; for 403 check Azure RBAC and policy.
' Honor Retry-After for 429 and use bounded backoff for transient failures.
Response.End
End If
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "The HTTP response could not be read completely.") & "</pre>"
Response.End
End If
success = result.Load(response.BodyStr)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Expected a well-formed JSON response.") & "</pre>"
Response.End
End If
If (result.JsonTypeOf("properties.networkAcls") <> 3) Then
Response.Write "<pre>" & Server.HTMLEncode( "Missing or invalid properties.networkAcls.") & "</pre>"
Response.End
End If
set network = Server.CreateObject("Chilkat.JsonObject")
success = result.ObjectOf2("properties.networkAcls",network)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not read network rules.") & "</pre>"
Response.End
End If
' Preserve existing exceptions, resource-instance rules, IP rules, and subnet IDs.
' Replace this documentation address with your client's PUBLIC outbound IPv4.
allowedIp = "198.51.100.10"
' Optional: full ARM subnet ID, kept as a string. Its Storage service endpoint
' must already be enabled. This example does not create a subnet or endpoint.
subnetId = ""
set ipRules = Server.CreateObject("Chilkat.JsonArray")
If (network.HasMember("ipRules") <> 1) Then
success = network.UpdateNewArray("ipRules")
End If
success = network.ArrayOf2("ipRules",ipRules)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Invalid IP rule array.") & "</pre>"
Response.End
End If
set rule = Server.CreateObject("Chilkat.JsonObject")
ipFound = 0
i = 0
Do While (i < ipRules.Size)
success = ipRules.ObjectAt2(i,rule)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Invalid IP rule.") & "</pre>"
Response.End
End If
If (rule.StringOfEquals("value",allowedIp,1) = 1) Then
ipFound = 1
End If
i = i + 1
Loop
If (ipFound <> 1) Then
success = ipRules.AddObjectAt2(-1,rule)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not append IP rule.") & "</pre>"
Response.End
End If
success = rule.UpdateString("value",allowedIp)
success = rule.UpdateString("action","Allow")
End If
set subnets = Server.CreateObject("Chilkat.JsonArray")
If (network.HasMember("virtualNetworkRules") <> 1) Then
success = network.UpdateNewArray("virtualNetworkRules")
End If
success = network.ArrayOf2("virtualNetworkRules",subnets)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Invalid subnet rule array.") & "</pre>"
Response.End
End If
subnetFound = 0
i = 0
Do While (i < subnets.Size)
success = subnets.ObjectAt2(i,rule)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Invalid subnet rule.") & "</pre>"
Response.End
End If
' state is returned by GET but is not a writable rule property.
success = rule.Delete("state")
If (rule.StringOfEquals("id",subnetId,0) = 1) Then
subnetFound = 1
End If
i = i + 1
Loop
success = stringCompare.SetString(subnetId)
stringMatch1 = stringCompare.ContentsEqual("",1)
If ((stringMatch1 <> 1) And (subnetFound <> 1)) Then
success = subnets.AddObjectAt2(-1,rule)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not append subnet rule.") & "</pre>"
Response.End
End If
success = rule.UpdateString("id",subnetId)
success = rule.UpdateString("action","Allow")
End If
success = network.UpdateString("defaultAction","Deny")
ERROR: ASP example cannot use request or response as a variable name.
set properties = Server.CreateObject("Chilkat.JsonObject")
success = request.AppendObject2("properties",properties)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not create properties.") & "</pre>"
Response.End
End If
success = properties.AppendObjectCopy("networkAcls",network)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Could not copy network rules.") & "</pre>"
Response.End
End If
' Enabled + defaultAction Deny means selected public networks. Disabled would
' block public endpoint access; SecuredByPerimeter is a different policy mode.
success = properties.UpdateString("publicNetworkAccess","Enabled")
applyChanges = 0
If (applyChanges <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Network changes prepared, not applied. Review rules and set applyChanges to true.") & "</pre>"
Response.End
End If
' This may reopen a previously disabled public endpoint for the selected sources.
' Preserve exceptions intentionally; preserved trusted-service bypasses still apply.
' On a write timeout, read the resource before deciding whether to retry.
success = http.HttpJson("PATCH",resourceUrl,request,"application/json",response)
If (response.StatusCode = 0) Then
Response.Write "<pre>" & Server.HTMLEncode( "No HTTP response. Inspect LastErrorText privately; it may contain credentials.") & "</pre>"
Response.End
End If
If ((response.StatusCode <> 200)) Then
Response.Write "<pre>" & Server.HTMLEncode( "HTTP status: " & response.StatusCode) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "Request ID: " & response.GetHeaderField("x-ms-request-id")) & "</pre>"
Response.Write "<pre>" & Server.HTMLEncode( "Retry-After: " & response.GetHeaderField("Retry-After")) & "</pre>"
' Inspect the error body privately. Do not log tokens, headers, or full responses.
' For 401 check the token/audience; for 403 check Azure RBAC and policy.
' Honor Retry-After for 429 and use bounded backoff for transient failures.
Response.End
End If
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "The HTTP response could not be read completely.") & "</pre>"
Response.End
End If
success = result.Load(response.BodyStr)
If (success <> 1) Then
Response.Write "<pre>" & Server.HTMLEncode( "Expected a well-formed JSON response.") & "</pre>"
Response.End
End If
Response.Write "<pre>" & Server.HTMLEncode( "Network policy update returned successfully. Verify access from intended clients.") & "</pre>"
%>
</body>
</html>