Skip to content

Commit daa331e

Browse files
committed
Restrict live test storage account access to client IP
1 parent 470c31d commit daa331e

1 file changed

Lines changed: 13 additions & 0 deletions

File tree

eng/common/TestResources/New-TestResources.ps1

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -827,6 +827,19 @@ try {
827827
-templateFile $templateFile `
828828
-environmentVariables $EnvironmentVariables
829829

830+
$storageAccounts = Retry { Get-AzResource -ResourceGroupName $ResourceGroupName -ResourceType "Microsoft.Storage/storageAccounts" }
831+
if ($storageAccounts) {
832+
$clientIp = Retry { Invoke-RestMethod -Uri 'https://myip.dnsomatic.com/' } # OpenDNS owned ip site. Some throttling will occur if called quickly.
833+
}
834+
foreach ($account in $storageAccounts) {
835+
$rules = Get-AzStorageAccountNetworkRuleSet -ResourceGroupName $ResourceGroupName -AccountName $account.Name
836+
if ($rules -and $rules.DefaultAction -eq "Allow") {
837+
Write-Host "Restricting network rules in storage account '$account' to deny access except from the current client's IP"
838+
Retry { Update-AzStorageAccountNetworkRuleSet -ResourceGroupName $ResourceGroupName -Name $account.Name -DefaultAction Deny }
839+
Retry { Add-AzStorageAccountNetworkRule -ResourceGroupName $ResourceGroupName -Name $account.Name -IPAddressOrRange $clientIp }
840+
}
841+
}
842+
830843
$postDeploymentScript = $templateFile.originalFilePath | Split-Path | Join-Path -ChildPath "$ResourceType-resources-post.ps1"
831844
if (Test-Path $postDeploymentScript) {
832845
Log "Invoking post-deployment script '$postDeploymentScript'"

0 commit comments

Comments
 (0)