Description
Associate a network security group (NSG) with an application subnet to apply traffic rules across that subnet. To determine internet reachability, also check NIC-level NSGs and routes.
Potential impact
Missing subnet rules can broaden access to applications or databases. Attaching an NSG to a dedicated service subnet that does not support it can interrupt the service.
Remediation
For an application subnet, configure and associate an NSG that permits the required application, database and management traffic. Review effective rules, including defaults and priorities, and test allowed and denied connections. Leave GatewaySubnet and AzureFirewallSubnet without an NSG.
Examples
The excerpts use the legacy azure provider and reference an existing app-subnet-nsg. With AzureRM, supply the subnet and NSG IDs to azurerm_subnet_network_security_group_association.
Before
resource "azure_virtual_network" "app_network" {
name = "test-network"
address_space = ["10.1.2.0/24"]
location = "West US"
subnet {
name = "subnet1"
address_prefix = "10.1.2.0/25"
}
}
After
resource "azure_virtual_network" "app_network" {
name = "test-network"
address_space = ["10.1.2.0/24"]
location = "West US"
subnet {
name = "subnet1"
address_prefix = "10.1.2.0/25"
security_group = "app-subnet-nsg"
}
}