File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 '"
You can’t perform that action at this time.
0 commit comments