Description
Check which network security group (NSG) is associated with the deployed subnet. Omitting security_group leaves a new subnet without a specified NSG, but an update can preserve an existing association.
Potential impact
A missing NSG can leave intended subnet restrictions unapplied. Leave the service subnets GatewaySubnet and AzureFirewallSubnet without an NSG.
Remediation
For an application subnet, set security_group to the existing NSG name or resource ID. Review the effective subnet and NIC rules and their priorities, then test both permitted and denied connections.
Examples
For the short module name, install azure.azcollection and include it in the play’s collections. The second task attaches mySecurityGroup in myResourceGroup to mySubnet in the existing VNet. Neither task creates the group or its rules.
Before
- name: Create a subnet
azure_rm_subnet:
resource_group: myResourceGroup
virtual_network_name: myVirtualNetwork
name: mySubnet
address_prefix_cidr: "10.1.0.0/24"
After
- name: Create a subnet
azure_rm_subnet:
resource_group: myResourceGroup
virtual_network_name: myVirtualNetwork
name: mySubnet
address_prefix_cidr: "10.1.0.0/24"
security_group: mySecurityGroup
References
- CWE-285
- Ansible azure.azcollection.azure_rm_subnet documentation
- Ansible azure.azcollection 3.21.0 subnet module implementation
- Azure NSG rules and default behavior
- How subnet and network-interface NSGs are applied
- Unsupported NSG associations on GatewaySubnet
- NSG restrictions on AzureFirewallSubnet