Copyright (c) 2026 MindMesh Academy. All rights reserved. This content is proprietary and may not be reproduced or distributed without permission.

5.1.1.6. Configure Application Security Groups

5.1.1.6. Configure Application Security Groups

💡 First Principle: IP addresses describe where a server is, not what it does. Application security groups let NSG rules name the role ("web servers," "database servers") instead, so the rules keep working as servers are added, removed, or readdressed.

Scenario: A three-tier application has 20 web servers, 6 business-logic servers, and 4 database servers spread across two subnets of one virtual network. The web tier scales out every week. Security wants only the logic tier to reach the databases on port 1433, and nobody wants to edit NSG rules each time a VM is added.

What It Is: An application security group (ASG) is a named resource that groups the network interfaces (NICs) of virtual machines. You then use the ASG as the source or destination of a network security group rule in place of IP addresses or ranges. An ASG holds no rules itself; it's a label that NSG rules point to.

How Membership Works
  • You add a VM's NIC (strictly, an IP configuration of the NIC) to one or more ASGs, from the VM's Networking > Application security groups page or with az network nic ip-config update.
  • A NIC can belong to several ASGs, up to 20 per IP configuration.
  • A rule that names an ASG applies only to the NICs that are members of it. A NIC in the same subnet that isn't a member isn't affected by that rule, even though the NSG is associated with the subnet.
  • When a new web server's NIC joins the web ASG, every rule that names that ASG covers it immediately; no rule changes are needed.
Using ASGs in NSG Rules

The classic pattern from Microsoft's documentation, with one NSG associated to both subnets:

PriorityNameSourceDestinationPortAction
100Allow-HTTP-Inbound-InternetInternetAsgWeb80Allow
110Allow-Database-BusinessLogicAsgLogicAsgDb1433Allow
120Deny-Database-AllAnyAsgDb1433Deny

The deny rule at 120 is needed because the default AllowVNetInBound rule would otherwise let every VM in the virtual network reach the databases. Rule 110 is processed first, so only the logic tier gets through. No extra rule is needed to keep the internet away from the logic and database tiers, because the default DenyAllInbound rule already does.

Constraints
  • One virtual network per ASG: all NICs in an ASG must be in the same virtual network as the first NIC that was added. You can't add a NIC from a second virtual network.
  • Source and destination together: when a rule uses an ASG as both source and destination, the NICs in both ASGs must be in the same virtual network. ASGs therefore can't express rules between peered virtual networks; use address prefixes or service tags there.
  • Limits: up to 3,000 ASGs per subscription per region, up to 20 ASGs per NIC IP configuration, and up to 100 ASGs referenced across all the rules of one NSG.
When ASGs Beat IP-Based Rules

ASGs suit workloads where membership changes often (scale-out, rebuilds, blue-green deployments) or where tiers share a subnet, because the rule follows the role rather than an address. IP ranges or service tags remain the right choice for sources outside your virtual network, such as an on-premises management range or Internet, because those addresses aren't Azure NICs that can join an ASG.

Practical Implementation: Role-Based NSG Rules with Azure CLI
# Create the role groups
az network asg create --resource-group rg-app --name asg-logic --location westus2
az network asg create --resource-group rg-app --name asg-db --location westus2

# Put a VM's NIC IP configuration into a group
az network nic ip-config update --resource-group rg-app --nic-name vm-db1-nic \
  --name ipconfig1 --application-security-groups asg-db

# Allow only the logic tier to reach SQL on the database tier, then deny everyone else
az network nsg rule create --resource-group rg-app --nsg-name nsg-app --name Allow-Logic-To-Db \
  --priority 110 --direction Inbound --access Allow --protocol Tcp \
  --source-asgs asg-logic --source-port-range "*" \
  --destination-asgs asg-db --destination-port-range 1433
az network nsg rule create --resource-group rg-app --nsg-name nsg-app --name Deny-Db-All \
  --priority 120 --direction Inbound --access Deny --protocol "*" \
  --source-address-prefix "*" --source-port-range "*" \
  --destination-asgs asg-db --destination-port-range 1433

⚠️ Common Pitfall: Writing the allow rule from the logic tier to the database tier and forgetting the deny rule. Because AllowVNetInBound sits at priority 65000, every VM in the virtual network can still reach port 1433. An ASG narrows who a rule matches; it doesn't remove the default rules.

⚠️ Exam Trap: ASGs don't filter traffic by themselves, and you can't associate an ASG with a subnet. Traffic is filtered only by an NSG rule that names the ASG, and that NSG must be associated with the subnet or NIC. Also watch for scenarios that need an ASG to span two virtual networks: that isn't possible.

Key Trade-Offs:
  • ASGs vs. one subnet per tier with IP-based rules: Separate subnets give clean boundaries and simple CIDR rules, but force a subnet redesign whenever a role is added. ASGs let roles share subnets and change without touching rules, at the cost of rules that are harder to read without checking membership.
  • ASG membership as a control point: Whoever can change a NIC's ASG membership can change what that VM is allowed to reach, so treat that permission like the right to edit the NSG itself.

Reflection Question: A new reporting VM must read from the database tier on port 1433. Using the rules above, what's the smallest change that grants that access, and why doesn't it require touching the NSG at all?

See how it connects
Alvin Varughese
Written byAlvin Varughese
Founder•22 professional certifications earned