Skip to content

Commit 6d5edeb

Browse files
committed
Validate and update ip firewall rules
1 parent 616a5ba commit 6d5edeb

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

eng/common/TestResources/New-TestResources.ps1

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ param (
8383
# List of CIDR ranges to add to specific resource firewalls, e.g. @(10.100.0.0/16, 10.200.0.0/16)
8484
[Parameter()]
8585
[ValidateCount(0,399)]
86+
[Validatescript({
87+
foreach ($range in $PSItem) {
88+
if ($range -like '*/31' -or $range -like '*/32') {
89+
throw "Firewall IP Ranges cannot contain a /31 or /32 CIDR"
90+
}
91+
}
92+
return $true
93+
})]
8694
[array] $AllowIpRanges = @(),
8795

8896
[Parameter()]
@@ -128,9 +136,9 @@ $azsdkPipelineSubnetMap = @{
128136

129137
$poolSubnet = ''
130138
if ($env:Pool) {
131-
$poolSubnet = $azsdkPipelineSubnetMap[$env:Pool]
139+
$poolSubnet = $azsdkPipelineSubnetMap[$env:Pool]
132140
} else {
133-
Write-Warning "Pool environment variable is not defined! Subnet allowlisting will not work and live test resources may be non-compliant."
141+
Write-Warning "Pool environment variable is not defined! Subnet allowlisting will not work and live test resources may be non-compliant."
134142
}
135143

136144
if (!$ServicePrincipalAuth) {
@@ -877,7 +885,7 @@ try {
877885
} elseif (!$CI) {
878886
Write-Host "Enabling access to '$($account.Name)' from client IP"
879887
$clientIp ??= Retry { Invoke-RestMethod -Uri 'https://icanhazip.com/' } # cloudflare owned ip site
880-
Retry { Update-AzStorageAccountNetworkRuleSet -ResourceGroupName $ResourceGroupName -Name $account.Name -IPRule @{ Action = 'allow'; IPAddressOrRange = $clientIp } | Out-Null }
888+
Retry { Add-AzStorageAccountNetworkRule -ResourceGroupName $ResourceGroupName -Name $account.Name -IPAddressOrRange $clientIp | Out-Null }
881889
}
882890
}
883891
}

eng/common/TestResources/deploy-test-resources.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ steps:
6868
-DeleteAfterHours '${{ parameters.DeleteAfterHours }}' `
6969
@subscriptionConfiguration `
7070
-AdditionalParameters ${{ parameters.ArmTemplateParameters }} `
71+
-AllowIpRanges ('$(azsdk-corp-net-ip-ranges)' -split ',') `
7172
-CI `
7273
-Force `
7374
-Verbose | Out-Null
@@ -89,6 +90,7 @@ steps:
8990
-DeleteAfterHours '${{ parameters.DeleteAfterHours }}' `
9091
@subscriptionConfiguration `
9192
-AdditionalParameters ${{ parameters.ArmTemplateParameters }} `
93+
-AllowIpRanges ('$(azsdk-corp-net-ip-ranges)' -split ',') `
9294
-CI `
9395
-ServicePrincipalAuth `
9496
-Force `

0 commit comments

Comments
 (0)