Securing access: NSGs, ASGs, Bastion and endpoints

AZ-104 Azure AdministratorNetworkingAbout 25 minutesBy Cloud Hands On

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

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 rulePriorityEffect
AllowVnetInBound65000Allow traffic from inside the VNet and peered VNets
AllowAzureLoadBalancerInBound65001Allow load balancer health probes
DenyAllInBound65500Deny everything else

2. Subnet NSG and NIC NSG together

Inbound traffic passes the subnet NSG then the NIC NSG. Outbound passes the NIC NSG then the subnet NSG. Internet Subnet NSGchecked 1st NIC NSGchecked 2nd VM Inbound NIC NSG 1stSubnet NSG 2ndOutbound runs in reverse. Traffic must be allowed by both.
Use Effective security rules on the NIC to see the combined result.
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.

  1. Inbound starts at the subnet NSG. TCP 3389 does not match the 443 rule, so check the next rule.
  2. Priority 200 matches and denies it. Evaluation stops here.
  3. 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.

An NSG rule allows asg-web to reach asg-db on port 1433 asg-webweb-vm1, web-vm2, web-vm3(any subnet in the VNet) asg-dbsql-vm1, sql-vm2 Allow TCP 1433
New web VMs join asg-web and inherit the rule automatically.

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

Service endpoint keeps the storage public IP. Private endpoint puts a private IP for storage inside the VNet. Service endpointPrivate endpoint VNet subnetVM Storage accountpublic IP backbone route,firewall allows subnet VNet subnetVM Private endpoint10.20.2.5 Storage account
A private endpoint is reachable from peered VNets and on-premises. A service endpoint only helps the subnet it is enabled on.
ItemService endpointPrivate endpoint
Service addressStays publicPrivate IP in your VNet
Reachable from on-premisesNoYes, over VPN or ExpressRoute
CostFreeHourly plus per GB
DNS changesNoneNeeds a private DNS zone, such as privatelink.blob.core.windows.net
Configured onThe subnet, plus a VNet rule in the service firewallA 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

Keep going