Skip to content

Commit a50b9dd

Browse files
benbpazure-sdk
authored andcommitted
Skip adding network rules to storage accounts that don't need them during cleanup
1 parent 3621846 commit a50b9dd

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

eng/common/scripts/Helpers/Resource-Helpers.ps1

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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

315315
function 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

Comments
 (0)