Task 02: Manage Network Security Groups
DOCUMENT CATEGORY: Runbook SCOPE: Day 2 NSG management PURPOSE: Manage NSG rules, associations, and troubleshooting for Azure Local VMs MASTER REFERENCE: SDN Network Security Groups INITIAL SETUP: See Phase 06 — Task 07: Configure NSGs
Status: Active
Overview
This document covers Day 2 operations for NSGs that were initially created during Phase 06 — Post-Deployment Task 07 and associated with logical networks during Task 08 — Logical Network Creation.
Day 2 operations include:
- Adding or removing security rules
- Associating or dissociating NSGs from logical networks and VM NICs
- Troubleshooting connectivity issues related to NSG rules
Common NSG Patterns
Web Server NSG
| Rule | Direction | Port | Source | Action |
|---|---|---|---|---|
| Allow-HTTPS | Inbound | 443 | * | Allow |
| Allow-HTTP | Inbound | 80 | * | Allow |
| Allow-RDP-Mgmt | Inbound | 3389 | Management CIDR | Allow |
| Deny-All | Inbound | * | * | Deny |
Database Server NSG
| Rule | Direction | Port | Source | Action |
|---|---|---|---|---|
| Allow-SQL | Inbound | 1433 | App Server CIDR | Allow |
| Allow-RDP-Mgmt | Inbound | 3389 | Management CIDR | Allow |
| Deny-All | Inbound | * | * | Deny |
Application Server NSG
| Rule | Direction | Port | Source | Action |
|---|---|---|---|---|
| Allow-App-Port | Inbound | 8080 | Web Server CIDR | Allow |
| Allow-RDP-Mgmt | Inbound | 3389 | Management CIDR | Allow |
| Deny-All | Inbound | * | * | Deny |
NIC Configuration Note
If you provision multiple static NICs on an Azure Local VM, all NICs receive the default gateway by default.
Resolution: Remove the default gateway from secondary NICs to prevent:
- Asymmetric networking
- Packet loss
- Unpredictable network behavior
# Inside the VM - remove default gateway from secondary NIC
Remove-NetRoute -InterfaceAlias "Ethernet 2" -DestinationPrefix "0.0.0.0/0" -Confirm:$false
Day 2 Operations
Add a Rule to an Existing NSG
az stack-hci-vm network nsg rule create \
--nsg-name nsg-iic-production \
--resource-group rg-iic-platform-01 \
--subscription <subscription-id> \
--name "Allow-SQL-AppTier" \
--priority 300 \
--direction Inbound \
--access Allow \
--protocol Tcp \
--source-address-prefixes "10.200.0.0/24" \
--source-port-ranges "*" \
--destination-address-prefixes "*" \
--destination-port-ranges "1433"
Remove a Rule
az stack-hci-vm network nsg rule delete \
--nsg-name nsg-iic-production \
--resource-group rg-iic-platform-01 \
--subscription <subscription-id> \
--name "Allow-SQL-AppTier"
Associate NSG with VM NIC
- Navigate to Azure Arc → Azure Local → Virtual Machines
- Select the target VM
- Go to Networking
- Select the target NIC
- Click Network Security Group
- Choose the NSG to associate
- Click Save
Dissociate NSG from a Logical Network
To change or remove an NSG from a logical network, the network must be recreated. NSG association is set at logical network creation time.
NIC Configuration Note
If you provision multiple static NICs on an Azure Local VM, all NICs receive the default gateway by default.
Resolution: Remove the default gateway from secondary NICs to prevent:
- Asymmetric networking
- Packet loss
- Unpredictable network behavior
# Inside the VM - remove default gateway from secondary NIC
Remove-NetRoute -InterfaceAlias "Ethernet 2" -DestinationPrefix "0.0.0.0/0" -Confirm:$false
Verification
List NSG Rules
az stack-hci-vm network nsg rule list \
--nsg-name nsg-iic-management \
--resource-group rg-iic-platform-01 \
--subscription <subscription-id> -o table
Verify NSG Association
- Navigate to Azure Portal → Azure Arc → Azure Local
- Check Logical Networks for NSG association
- Check Virtual Machines → Networking for NIC NSG association
Test Connectivity
# From a test VM, verify rules are working
Test-NetConnection -ComputerName <target-vm-ip> -Port 443
Test-NetConnection -ComputerName <target-vm-ip> -Port 3389
Troubleshooting
| Issue | Resolution |
|---|---|
| NSG not applying | Verify VM was deployed from Azure interfaces |
| Rules not blocking | Check rule priority (lower = processed first) |
| Connectivity lost | Verify management access rules exist |
| NSG not visible | Ensure SDN is enabled on the cluster |
Related Documentation
- Phase 06 — Task 07: Configure NSGs (Initial Setup)
- Phase 06 — Task 08: Logical Network Creation
- NSG Overview - Azure
- SDN Overview - Azure Local
- Manual
- Orchestrated Script
- Azure CLI
When to use: Use this option for manual step-by-step execution.
See procedure steps above for manual execution guidance.
PowerShell
No PowerShell script of its own in this task folder.
Invoke-SdnIntegration-Orchestrated.ps1is a placeholder: it printsNOT IMPLEMENTED, changes nothing and exits with code 3. The earlierSet-SdnIntegration.ps1is removed: SDN enabled by Azure Arc has no load balancer or gateway to configure. The Day 2 work on the rules of a group has an Azure CLI script: see the Azure CLI tab.
Script
| Script | What it does |
|---|---|
scripts/deploy/04-cluster-deployment/phase-06-post-deployment/task-07-configure-nsgs/powershell/New-NetworkSecurityGroup.ps1 | Creates the network security groups of networking.network_security_groups[] with their rules. Needs sdn.enabled: true. Refuses a group without rules. |
Run
./New-NetworkSecurityGroup.ps1 -InfrastructureFile ./infrastructure.yml -WhatIf
Azure CLI
When to use: Run the task from a host that has the Azure CLI and not the Az PowerShell modules. The script is PowerShell 7 that calls
az; it readsinfrastructure.ymland carries no values of its own.
Script
| Script | What it does |
|---|---|
scripts/deploy/05-operational-foundations/phase-01-sdn-deployment/task-02-configure-network-security-groups/azurecli/Set-NetworkSecurityGroupRule.azcli.ps1 | Day 2 management of the rules of the Azure Local network security groups, from networking.network_security_groups of infrastructure.yml, with the Azure CLI. Supports -WhatIf. |
scripts/deploy/05-operational-foundations/phase-01-sdn-deployment/task-03-configure-network-security-groups/azurecli/Test-NetworkSecurityGroupRule.azcli.ps1 | Checks the rules of the groups against infrastructure.yml with the Azure CLI. Read only. |
Requires: PowerShell 7 and the Azure CLI, signed in with az login --tenant <azure.tenant_id>. Needs the Azure CLI extension stack-hci-vm (az extension add --name stack-hci-vm); the script does not install it.
SDN enabled by Azure Arc must be on (sdn.enabled true). The first script creates the rules of the file that a group lacks and updates the ones that differ; a rule the group has and the file does not list is reported as Unlisted, and removed only with -RemoveUnlistedRules (after every rule of the file is in place). It never creates a group: a missing group is reported as Failed (create it with the script of the post-deployment NSG task). The second script is the Verification section as a script. It never changes anything: a missing or different rule fails the check, and a rule only the group has is reported as Extra without failing it. Neither script associates a group with a logical network or a network interface.
Run
./Set-NetworkSecurityGroupRule.azcli.ps1 -InfrastructureFile ./infrastructure.yml -WhatIf
./Test-NetworkSecurityGroupRule.azcli.ps1 -InfrastructureFile ./infrastructure.yml
Scripts for this task are located in the azurelocal-toolkit repository under scripts/deploy/ in the appropriate task folder.
Alternatives
The procedures in this task use the methods shown in the tabs above. The toolkit is PowerShell 7 only and has no Bash scripts. A few tasks that act on Azure also have an Azure CLI script written in PowerShell. The script status page of the toolkit lists which task has which script.
Values from infrastructure.yml
The values for this task come from infrastructure.yml (schema 5). Every key, with its type, default and example, is in the variables reference.
Navigation
| Previous | Up | Next |
|---|---|---|
| ← Task 01: Validate Prerequisites | Phase 01: SDN Operations | Phase 02: Monitoring & Observability → |
Version Control
| Version | Date | Author | Changes |
|---|---|---|---|
| 1.0.0 | 2025-03-25 | AzureLocal | Initial release |
| 1.1.0 | 2026-04-01 | AzureLocal | Align naming conventions, remove consulting language |
| 2.0.0 | 2025-07-25 | AzureLocal | Repurpose as Day 2 management — initial creation moved to Phase 06 Task 07 |