@@ -308,8 +308,8 @@ function Remove-WormStorageAccounts() {
308308 }
309309}
310310
311- function SetResourceNetworkAccessRules ([string ]$ResourceGroupName , [array ]$AllowIpRanges , [switch ]$CI ) {
312- SetStorageNetworkAccessRules - ResourceGroupName $ResourceGroupName - AllowIpRanges $AllowIpRanges - CI:$CI
311+ function SetResourceNetworkAccessRules ([string ]$ResourceGroupName , [array ]$AllowIpRanges , [switch ]$CI , [ switch ] $Override ) {
312+ SetStorageNetworkAccessRules - ResourceGroupName $ResourceGroupName - AllowIpRanges $AllowIpRanges - CI:$CI - Override: $Override
313313}
314314
315315function SetStorageNetworkAccessRules ([string ]$ResourceGroupName , [array ]$AllowIpRanges , [switch ]$CI , [switch ]$Override ) {
@@ -327,6 +327,16 @@ function SetStorageNetworkAccessRules([string]$ResourceGroupName, [array]$AllowI
327327 Set-AzStorageAccount - ResourceGroupName $ResourceGroupName - StorageAccountName $account.Name - AllowBlobPublicAccess $false
328328 }
329329
330+ # In override mode, we only want to capture storage accounts that have had incomplete network rules applied,
331+ # otherwise it's not worth updating due to timing and throttling issues.
332+ # If the network rules are deny only without any vnet/ip allowances, then we can't ever purge the storage account
333+ # when immutable blobs need to be removed.
334+ if ($Override -and $rules.DefaultAction -eq " Deny" ) {
335+ if ($rules.VirtualNetworkRules.Length -gt 0 -or $rules.IpRules.Length -gt 0 ) {
336+ return
337+ }
338+ }
339+
330340 if ($rules -and ($Override -or $rules.DefaultAction -eq " Allow" )) {
331341 Write-Host " Restricting network rules in storage account '$ ( $account.Name ) ' to deny access by default"
332342 Retry { Update-AzStorageAccountNetworkRuleSet - ResourceGroupName $ResourceGroupName - Name $account.Name - DefaultAction Deny }
0 commit comments