Securing access: NSGs, ASGs, Bastion and endpoints
Filter traffic with NSGs and ASGs, read effective rules, give admins safe access with Bastion, and lock PaaS services to your network.
In this lesson you'll learn
- How NSG rules are evaluated, and the order for subnet and NIC NSGs
- Application security groups for role-based rules
- Azure Bastion for RDP and SSH without public IPs
- Service endpoints versus private endpoints
1. Network security groups
New to NSGs? Start here
An NSG is a list of allow and deny rules, like a guest list at a door. Each rule matches on five things, known as the 5-tuple: source, source port, destination, destination port and protocol. You attach an NSG to a subnet, a NIC, or both.
- Rules have a priority from 100 to 4096. Lower numbers are checked first, and the first match wins.
- Sources and destinations can be IPs, ranges, service tags (such as Internet, VirtualNetwork or AzureLoadBalancer) or application security groups.
- NSGs are stateful. If inbound traffic is allowed, the reply is allowed automatically.
| Default inbound rule | Priority | Effect |
|---|---|---|
| AllowVnetInBound | 65000 | Allow traffic from inside the VNet and peered VNets |
| AllowAzureLoadBalancerInBound | 65001 | Allow load balancer health probes |
| DenyAllInBound | 65500 | Deny everything else |
2. Subnet NSG and NIC NSG together
Example: will RDP from the internet reach VM1?
Subnet NSG: priority 100 allows TCP 443 from Internet. Priority 200 denies TCP 3389 from Internet. NIC NSG: priority 100 allows TCP 3389 from Any.
- Inbound starts at the subnet NSG. TCP 3389 does not match the 443 rule, so check the next rule.
- Priority 200 matches and denies it. Evaluation stops here.
- The NIC rule never gets a chance. RDP is blocked. HTTPS on 443 is allowed by the subnet NSG, but must also be allowed by the NIC NSG. It is not, so the NIC's default DenyAllInBound blocks it too.
3. Application security groups
Instead of writing rules with IP addresses that change as you scale, group NICs by role and write rules between groups.
Exam focus
All NICs in an ASG must be in the same VNet as the ASG. Rules that reference ASGs on both sides need both ASGs in the same VNet.
4. Azure Bastion
Bastion gives browser-based RDP and SSH to VMs that have no public IP. Admins connect through the portal over TLS on port 443, so ports 3389 and 22 never face the internet.
- It deploys into a subnet named exactly AzureBastionSubnet, /26 or larger.
- One Bastion serves its own VNet and peered VNets.
- The SKUs are Developer, Basic, Standard and Premium. Standard and above add native client support, shareable links and host scaling.
Example
A security scan finds SS Kaiser's VMs answering RDP from the internet, with thousands of password attempts a day. The team removes every VM public IP, deploys Bastion in the hub, and adds an NSG rule denying 3389 from Internet. Admins still connect, now from the portal.
5. Service endpoints versus private endpoints
| Item | Service endpoint | Private endpoint |
|---|---|---|
| Service address | Stays public | Private IP in your VNet |
| Reachable from on-premises | No | Yes, over VPN or ExpressRoute |
| Cost | Free | Hourly plus per GB |
| DNS changes | None | Needs a private DNS zone, such as privatelink.blob.core.windows.net |
| Configured on | The subnet, plus a VNet rule in the service firewall | A NIC resource in a subnet |
Exam focus
"Traffic must use the Microsoft backbone and the service must have a private IP" means private endpoint. "Allow only this subnet and keep it simple or free" means service endpoint.
Exam traps to remember
- Inbound order is subnet NSG then NIC NSG. Outbound is the reverse. Both must allow.
- NSG rules cannot redirect traffic. Use a UDR for that.
- Use IP flow verify to find which rule blocks a packet.
- AzureBastionSubnet is /26 minimum, and Bastion does not need public IPs on your VMs.
Test yourself: 3 check questions and exam-style practice questions on this topic are in the AZ-104 Azure Administrator app.
Practise in the app