Lesson 2 of 6 Securing Azure Virtual Networks

Grouping VMs with Application Security Groups

This lesson explains how application security groups let NSG rules refer to VMs by role.

Learning outcomes

After completing this lesson, you will be able to:

  • Explain how ASGs are used in NSG rules.
  • Identify the limitations of ASGs.
  • Choose between IP addresses and ASGs in rules.

How ASGs work

An application security group is a resource that acts as a label. Network interfaces of VMs are added to one or more ASGs on the VM's Networking page (Application security groups) or with az network nic ip-config update --application-security-groups. NSG rules then use ASGs as the source or destination, for example "allow asg-web to asg-sql on TCP 1433". When a VM is added to or removed from an ASG, the rules apply to it automatically, without editing IP addresses.

ASGs simplify micro-segmentation within a subnet or across subnets: web and database VMs can share a subnet while rules still distinguish them. A NIC can belong to several ASGs, and a rule can reference several ASGs.

The following diagram shows application security groups that segment web and SQL VMs in one subnet, and the NSG rules that use them.

Segmenting web and SQL VMs in one subnet with application security groups. Each NIC joins asg-web or asg-sql, and three subnet NSG rules use the groups: Internet to asg-web on 443, asg-web to asg-sql on 1433, and a deny from VirtualNetwork to asg-sql on 1433 with a higher number. New web VMs only need to join asg-web.
The deny rule's number must be higher than the allow rule's.
Scenario questions

Using application security groups

Exam skills 4.2.1

Use ASGs to write NSG rules by role instead of by address.

Log in to try this activity Interactive activities are free with an account.

Rules and limitations

All network interfaces in an ASG must be in the same virtual network as the first NIC added to it, and a rule that uses ASGs as both source and destination requires all of them to be in the same VNet. ASGs cannot be used across peered VNets. They are free, and they work together with service tags and IP addresses in the same NSG.

IP addresses in rules
Scaling a tierEdit rules for each new VM's IP
ReadabilityRules show addresses
ScopeAny address
Choose when External ranges, on-premises networks
Application security groups
Scaling a tierAdd the NIC to the ASG
ReadabilityRules show roles, such as asg-web
ScopeNICs in one VNet
Choose when Grouping VMs by role inside a VNet
True or false

ASG rules

Exam skills 4.2.1

Check the rules for application security groups.

Log in to try this activity Interactive activities are free with an account.
Worked example

Segmenting tiers

A subnet contains 6 web VMs and 2 SQL Server VMs. Only web VMs may connect to SQL Server on TCP 1433, the web VMs must accept HTTPS from the internet, and new web VMs will be added often. The solution must minimize rule maintenance. What should you configure?

Create ASGs asg-web and asg-sql, add each VM's NIC to the right ASG, and add NSG rules on the subnet: allow Internet to asg-web on TCP 443; allow asg-web to asg-sql on TCP 1433; and deny VirtualNetwork to asg-sql on 1433 with a higher priority number than the allow rule, so that other VMs are blocked despite the default AllowVNetInBound rule. New web VMs only need their NIC added to asg-web.

Check yourself

Can NICs from two different VNets be members of the same application security group?

Show answer

No. All NICs in an ASG must be in the same virtual network.

Exam Tips

Remember for the exam

  • ASGs group NICs by role so rules do not depend on IP addresses.
  • All NICs in an ASG must be in the same VNet.
  • Add a deny rule to override AllowVNetInBound for tiers that must be isolated.
  • A NIC can belong to several ASGs.