How to enable "Allow Azure services and resources to access this server" through PowerShell (Azure CLI)?
Asked Answered
W

6

9

After creating a new Azure SQL server using az sql server create, how can I enable the following options through PowerShell(Azure CLI)?

enter image description here

Woodborer answered 18/10, 2019 at 10:33 Comment(0)
F
15

It's in the documentation for Azure SQL somewhere, if you search for "azure sql firewall allow azure services", but here's what you need to do - create a rule with a start and end address of 0.0.0.0, like this:

az sql server firewall-rule create --resource-group <resource group name> --server <azure sql name> -n <any name> --start-ip-address 0.0.0.0 --end-ip-address 0.0.0.0
Fowlkes answered 18/10, 2019 at 11:30 Comment(2)
This seems to enable that option. Thanks!Woodborer
It's in the API docs: learn.microsoft.com/en-us/rest/api/sql/firewallrules/…Mar
R
3

To expand on Scott answer, the equivalent way to do this in the Azure PowerShell module is:

New-AzSqlServerFirewallRule -FirewallRuleName <fw-rule-name> -StartIpAddress '0.0.0.0' -EndIpAddress '0.0.0.0' -ServerName <sql-server-name> -ResourceGroupName <resource-group-name>
Rotman answered 23/7, 2020 at 16:51 Comment(1)
Do you know what to do when you have "Deny public access" to Yes. Then you can't configure firewall rules.Amoritta
D
2

my small contribution here.

the below az command with the respective group and sqlservername sets "Allow Azure services and resources to access this server" to Yes

az sql server firewall-rule create -g -s -n AllowAllWindowsAzureIps --start-ip-address 0.0.0.0 --end-ip-address 0.0.0.0

Desperation answered 21/1, 2021 at 9:15 Comment(0)
D
1

Just add a new rule with specific name (AllowAllWindowsAzureIps);

New-AzSqlServerFirewallRule -ResourceGroupName <resourceGroup> -ServerName <serverName> -FirewallRuleName "AllowAllWindowsAzureIps" -StartIpAddress "0.0.0.0" -EndIpAddress "0.0.0.0"
Discard answered 17/2, 2021 at 15:33 Comment(0)
S
0

Just came across this and I believe it's doable via the following script now...

New-AzSqlServerFirewallRule -ResourceGroupName <ResourceGroup> -ServerName <SQLServerName> -AllowAllAzureIPs
Schultz answered 27/4, 2022 at 11:29 Comment(0)
E
-1
az sql server firewall-rule create --resource-group <resource group name> --server <azure sql name> -n <any name> --start-ip-address 0.0.0.0 --end-ip-address 0.0.0

this command will open up the server for all the world. From a security perspective, it is not ok. But the question was in opening the server just for Azure services.

Employ answered 15/3 at 10:47 Comment(1)
This only changes that setting flag, it won't open up the server to everyting, right? (Or is the -end-ip-address 0.0.0 not a typo?)Woodborer

© 2022 - 2024 — McMap. All rights reserved.