Whitelist IP between Web apps and SQL Server

Viewed 280

I have a SQL Server and a Web App in the Azure. I need securing network between them. I imagine both of them are connected with specific IP address, exclusively. I think about this idea for securing and preventing Web App by cloning it.

enter image description here

So far, I also know about securing SQL database using firewall and Web apps using whitelist. But these two terms don't give any exclusive IP connection between them.

So, any idea how to solve this issue ?

2 Answers

Usually in Azure SQL Server, IP firewall rules are set to ensure connection security. So I guess what you want is the following way to ensure connection security.

App Service provides a managed identity for your app, which is a turn-key solution for securing access to Azure SQL Database and other Azure services.

I wrote below powershell script to do the job. This script will whitelist all possible outbound ip addresses of multiple web app to an azure sql server.

$rg = "azure-sql-resource-group-name"
$rg1 = "webapp-resource-group-name"
$sn = "sql-server-name"
$WebApps = @("webApp1","webApp2","webApp3", "webApp4") #List of web apps to be whitelisted..

    foreach($app in $WebApps ) { 
        $i = 0
        $IPs = (az webapp show --resource-group $rg1 --name $app --query possibleOutboundIpAddresses).Replace('"', '')
        foreach ($ip in $IPs -split ',' ) {
            $i = $i + 1
            $rn = $app + '-' + $i
            $o = 'Adding.. ' + $rn + ' : ' + $ip
            Write-Output $o
            az sql server firewall-rule create --name $rn --resource-group $rg --server $sn  --end-ip-address $ip --start-ip-address $ip
        }
    }
Related