Database resources configured with public network access enabled are accessible from the internet, significantly increasing the attack surface and security risks. This misconfiguration falls under CWE-284: Improper Access Control.
When a database resource has publicNetworkAccess set to "Enabled", it allows connections from any public IP address on the internet. This creates several security risks:
- Increased Attack Surface: The database becomes a target for brute force attacks, credential stuffing, and other network-based attacks
- Data Exposure Risk: If authentication is compromised, sensitive data stored in the database could be accessed by attackers
- Compliance Issues: Many regulatory frameworks require databases containing sensitive data to be isolated from public networks
- Lateral Movement: A compromised publicly accessible database can serve as an entry point for attackers to move laterally within your infrastructure
This issue affects all database types including SQL servers, PostgreSQL, MySQL, MariaDB, Cosmos DB, and others.
Disable public network access by setting publicNetworkAccess to "Disabled" and use one of these secure alternatives:
- Private Endpoints: Use Azure Private Link to create private endpoints for secure connectivity
- Virtual Network Integration: Deploy databases within a virtual network (VNet) for network isolation
- Service Endpoints: Use VNet service endpoints to allow access only from specific subnets
- Firewall Rules: If public access is absolutely necessary, configure strict firewall rules to allow only specific IP addresses
resource insecureSqlServer 'Microsoft.Sql/servers@2021-11-01' = {
name: 'insecure-sql-server'
location: 'eastus'
properties: {
publicNetworkAccess: 'Enabled' // Vulnerable: Allows public internet access
administratorLogin: 'sqladmin'
administratorLoginPassword: password
}
}resource secureSqlServer 'Microsoft.Sql/servers@2021-11-01' = {
name: 'secure-sql-server'
location: 'eastus'
properties: {
publicNetworkAccess: 'Disabled' // Secure: Blocks public internet access
administratorLogin: 'sqladmin'
administratorLoginPassword: password
}
}
// Add a private endpoint for secure connectivity
resource privateEndpoint 'Microsoft.Network/privateEndpoints@2021-05-01' = {
name: 'sql-private-endpoint'
location: 'eastus'
properties: {
subnet: {
id: subnetId
}
privateLinkServiceConnections: [
{
name: 'sql-connection'
properties: {
privateLinkServiceId: secureSqlServer.id
groupIds: ['sqlServer']
}
}
]
}
}