Skip to content

Commit

Permalink
Validate and update ip firewall rules
Browse files Browse the repository at this point in the history
  • Loading branch information
benbp committed Jun 24, 2024
1 parent 616a5ba commit 6d5edeb
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
14 changes: 11 additions & 3 deletions eng/common/TestResources/New-TestResources.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ param (
# List of CIDR ranges to add to specific resource firewalls, e.g. @(10.100.0.0/16, 10.200.0.0/16)
[Parameter()]
[ValidateCount(0,399)]
[Validatescript({
foreach ($range in $PSItem) {
if ($range -like '*/31' -or $range -like '*/32') {
throw "Firewall IP Ranges cannot contain a /31 or /32 CIDR"
}
}
return $true
})]
[array] $AllowIpRanges = @(),

[Parameter()]
Expand Down Expand Up @@ -128,9 +136,9 @@ $azsdkPipelineSubnetMap = @{

$poolSubnet = ''
if ($env:Pool) {
$poolSubnet = $azsdkPipelineSubnetMap[$env:Pool]
$poolSubnet = $azsdkPipelineSubnetMap[$env:Pool]
} else {
Write-Warning "Pool environment variable is not defined! Subnet allowlisting will not work and live test resources may be non-compliant."
Write-Warning "Pool environment variable is not defined! Subnet allowlisting will not work and live test resources may be non-compliant."
}

if (!$ServicePrincipalAuth) {
Expand Down Expand Up @@ -877,7 +885,7 @@ try {
} elseif (!$CI) {
Write-Host "Enabling access to '$($account.Name)' from client IP"
$clientIp ??= Retry { Invoke-RestMethod -Uri 'https://icanhazip.com/' } # cloudflare owned ip site
Retry { Update-AzStorageAccountNetworkRuleSet -ResourceGroupName $ResourceGroupName -Name $account.Name -IPRule @{ Action = 'allow'; IPAddressOrRange = $clientIp } | Out-Null }
Retry { Add-AzStorageAccountNetworkRule -ResourceGroupName $ResourceGroupName -Name $account.Name -IPAddressOrRange $clientIp | Out-Null }
}
}
}
Expand Down
2 changes: 2 additions & 0 deletions eng/common/TestResources/deploy-test-resources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ steps:
-DeleteAfterHours '${{ parameters.DeleteAfterHours }}' `
@subscriptionConfiguration `
-AdditionalParameters ${{ parameters.ArmTemplateParameters }} `
-AllowIpRanges ('$(azsdk-corp-net-ip-ranges)' -split ',') `
-CI `
-Force `
-Verbose | Out-Null
Expand All @@ -89,6 +90,7 @@ steps:
-DeleteAfterHours '${{ parameters.DeleteAfterHours }}' `
@subscriptionConfiguration `
-AdditionalParameters ${{ parameters.ArmTemplateParameters }} `
-AllowIpRanges ('$(azsdk-corp-net-ip-ranges)' -split ',') `
-CI `
-ServicePrincipalAuth `
-Force `
Expand Down

0 comments on commit 6d5edeb

Please sign in to comment.