ASG
👥 What is an Application Security Group (ASG)?¶
Application Security Groups (ASGs) are logical containers used to group virtual machines (VMs) or network interfaces (NICs) within a Virtual Network (VNet), allowing you to simplify and manage NSG rules at scale.
Instead of using static IPs in NSGs, you use ASGs to define dynamic, scalable rules.
📚 Table of Contents¶
-
What ASG Solves
-
ASG vs NSG
-
How ASG Works
-
Real-World Architecture Example
-
Hands-On (Portal & CLI)
-
ASG Best Practices
-
Interview Questions
1️⃣ What Problem Does ASG Solve?¶
Without ASG:
-
You define NSG rules with IP addresses.
-
It's hard to manage and not scalable when IPs change.
With ASG:
-
Group VMs (e.g., "Web", "App", "DB") into ASGs.
-
Define NSG rules based on group name, not IP.
-
Rules auto-apply to any VM/NIC in the ASG.
2️⃣ ASG vs NSG — Relationship¶
| Feature | NSG | ASG |
|---|---|---|
| Purpose | Controls traffic | Groups VMs |
| Scope | Subnet or NIC | VMs/NICs |
| Used in | NSG rules | As source or destination in NSG rules |
| Dynamic? | No | Yes (auto-updates as VMs join ASG) |
3️⃣ How ASG Works¶
Example Scenario¶
| Group | VMs | ASG Name |
|---|---|---|
| Web Tier | VM1, VM2 | web-asg |
| App Tier | VM3, VM4 | app-asg |
| DB Tier | VM5 | db-asg |
NSG Rule¶
Allow app tier to access DB on port 1433 (SQL):
Whenever you add or remove VMs, the rule automatically applies — no manual update needed.
4️⃣ Real-World Architecture¶
┌────────────┐
│ web-asg │
│ (VM1, VM2) │
└────┬───────┘
↓ Port 443
┌────┴───────┐
│ app-asg │
│ (VM3, VM4) │
└────┬───────┘
↓ Port 1433
┌────┴───────┐
│ db-asg │
│ (VM5) │
└────────────┘
NSG rules reference ASG names instead of IPs.
5️⃣ Hands-On Guide¶
✅ Create ASG via Portal¶
-
Go to "Application Security Groups" → Create
-
Fill:
-
Name:
web-asg -
Region: Same as VNet
-
Resource Group
-
-
Repeat for
app-asg,db-asg
🧩 Associate VM NIC with ASG¶
-
Go to the VM → Networking
-
Click on Network Interface
-
Click on "Application security groups"
-
Add the ASG (e.g.,
web-asg)
💻 Azure CLI Example¶
# Create ASG
az network asg create \
--name web-asg \
--resource-group my-rg \
--location eastus
# Add VM NIC to ASG
az network nic update \
--name myVMNic \
--resource-group my-rg \
--application-security-groups web-asg
# Create NSG
az network nsg create \
--name web-nsg \
--resource-group my-rg
# Create NSG rule using ASG
az network nsg rule create \
--resource-group my-rg \
--nsg-name web-nsg \
--name AllowAppToDB \
--priority 100 \
--direction Inbound \
--access Allow \
--protocol Tcp \
--source-asg app-asg \
--destination-asg db-asg \
--destination-port-ranges 1433
6️⃣ Best Practices¶
| Tip | Why |
|---|---|
| Use ASG for tiers (web, app, db) | Logical grouping improves readability |
| Avoid IPs in NSG rules | Makes your infra scalable |
| Use clear ASG naming | E.g., asg-web-tier-eastus |
| Keep ASG in same region as VM | ASG is regional |
| Monitor with NSG flow logs | See traffic flow per ASG |
7️⃣ Interview Questions¶
-
What is the difference between NSG and ASG?
-
Can a VM belong to multiple ASGs?
- ✅ Yes
-
Can ASG be applied directly to a subnet?
- ❌ No (only at NIC level)
-
Can ASG span across regions?
- ❌ No (region-specific)
-
How does ASG help with dynamic scaling?