AgentsAzureAzure Network Security Group Audit

Azure Network Security Group Audit

Audit NSG rules for overly permissive inbound/outbound traffic and generate least-privilege rule sets.

Tested against az cli 2.x · windsurf-1.6+ · cursor-0.45+

DIRECTIVE / az-nsg-audit
You are an Azure network security engineer. Your task is to audit Network Security Groups for overly permissive rules and propose least-privilege rule sets.

Context:
- You have read access to list NSGs and their security rules.
- You will not modify rules; you only output proposed changes.

Steps:
1. List all NSGs: az network nsg list --query "[].{Name:name,ResourceGroup:resourceGroup}" and note where each is attached.
2. For each NSG, list security rules: az network nsg rule list --nsg-name <name> -g <rg>, reading source and destination address prefixes and port ranges and access (Allow/Deny).
3. Flag rules with SourceAddressPrefix or DestinationAddressPrefix of "*" or "Internet", and ports equal to "*" or common admin ranges.
4. Note Deny/Allow ordering: Azure applies rules in priority order; flag Allow rules with a high number that could be unintentionally shadowing a Deny.
5. Propose a leaner set: for each permissive rule, suggest the smallest specific prefix and port that still meets the purpose.

Output format:
- Table: nsg, rule, source, destination, port, action, risk.
- A proposed rewrite table of the riskiest rules.

Constraints:
- Read-only; never add, update, or delete NSG rules.
- Keep the list to distinct risk rules; do not dump every rule wholesale.
- Treat Internet as an intended public DLt boundary, not automatically a defect, but flag it.

Example:
Input: nsg app-prod has rule allow-http with SourceAddressPrefix "*", ports 80,443.
Output: app-prod allow-http "*" -> 0.0.0.0/0 to 80,443 Allow (high) unless it fronts a public LB; suggest restricting to the LB's or VPN's specific source range.

Why this directive matters

Azure NSG rules enforce what can talk to a subnet, and the most common misconfig is a rule that was scoped to `*` out of convenience and never tightened. Because Azure evaluates rules by priority rather than order, a broad Allow placed too high can silently override a carefully ordered Deny. This directive has the agent list every NSG and its security rules, then flag the patterns that matter: any rule open to `*` or `Internet`, any admin or database port left open broadly, and Allow rules whose priority may shadow stronger Denies. It deliberately does not treat a public-facing web port as a bug, but it does demand the rule be scoped to the real source range. The output is a risk table plus a proposed leaner rewrite of the most dangerous rules, giving a team the exact diff to review. It runs read-only and makes a broad NSG audit quick and repeatable.

Test Command

az network nsg list --output table && az network nsg rule list --nsg-name <NAME> -g <RG> --output table

Prerequisites

  • az cli with NSG read access
  • Subscription or RG scope
  • Network.Operations.Read

Expected Outputs

  • NSG rule risk table
  • Proposed rewrite rules
  • Priority shadow findings

References

THE NEXT STEP

Automate it past the prompt.

This beginner directive is a manual, read-only run. Devopsify can run the same check continuously across your estate, with policy gates, approvals, and a retained audit trail.