Azure database firewall permits broad access

Review broad Azure database firewall ranges and service-access exceptions, and allow only the clients that need access.

Description

A public database firewall should allow the source addresses the service sees for approved applications and administrators. In Azure SQL Database, setting both ends to 0.0.0.0 grants an exception to Azure resources, including those in other customers’ subscriptions. Other services can interpret exceptions differently.

Potential impact

An unnecessary public rule lets more clients attempt sign-in. Leaked credentials or excessive database permissions can then expose data.

Remediation

Check the combined firewall rules, including Azure-service exceptions. Remove unneeded ranges and use the approved clients’ post-NAT addresses. Splitting a range preserves its coverage. For private-only access, test DNS and client connectivity before disabling public access. Verify the expected connections and denials, and apply least-privilege database permissions.

Examples

These AzureRM v4.50.0 excerpts require azurerm_mssql_server.example and real client addresses. When migrating the rule from an older resource type, check Terraform state and the plan before applying.

Before

hcl
resource "azurerm_mssql_firewall_rule" "wide_firewall_rule" {
  name                = "FirewallRule1"
  server_id           = azurerm_mssql_server.example.id
  start_ip_address    = "203.0.113.0"
  end_ip_address      = "203.0.113.255"
}

After

hcl
resource "azurerm_mssql_firewall_rule" "wide_firewall_rule" {
  name                = "FirewallRule1"
  server_id           = azurerm_mssql_server.example.id
  start_ip_address    = "203.0.113.10"
  end_ip_address      = "203.0.113.10"
}

Explanation:

  • Before: The rule covers all 256 addresses from 203.0.113.0 through 203.0.113.255.
  • After: Matching start and end addresses allow only 203.0.113.10 through this rule.

References