SecOps Observer
← All labs

Azure network security / Intermediate / 25–40 min

The Azure deny rule that never wins

An outbound deny rule is shadowed by a broader, higher-priority allow. Fix the rule order on a real, unattached Azure network security group.

LAB IDsecops-03-azure-shadowed-egressTRACK / secops.observer
Security analyst monitoring alerts beside a server rack

The scenario

A lab NSG contains an allow for TCP 443 to any destination and a deny for the documentation network 198.51.100.0/24. The allow is evaluated first. Restore the intended rule order without attaching the NSG or removing either rule.

Mission objectives

  • Inspect the real Azure NSG and compare the two outbound rule priorities.
  • Change the allow priority so the specific deny is evaluated first.
  • Verify the Azure configuration and Terraform state, then remove the lab resources.

Lab README

The Azure deny rule that never wins

Two real outbound rules overlap: an allow for TCP 443 to any destination and a deny for the documentation-only network 198.51.100.0/24. The allow's lower priority number makes it win first. Reorder the allow while preserving both rules: the deny should be priority 200 and the allow priority 300.

Before you begin

This exercise creates a uniquely named resource group and an unattached Azure network security group. Never attach it to a VM, network interface or subnet. It creates no VM, public IP or data and does not send network traffic. An unattached NSG and empty resource group normally have no direct usage charge, but Azure pricing and policies vary; check costs and remove resources promptly. Use an isolated subscription with known safe guardrails.

Install Azure CLI, Terraform 1.5+, Python 3 and Bash on Linux. Log in and select the intended subscription. Microsoft.Resources and Microsoft.Network must already be registered. Use a private local Linux filesystem for Terraform state. The provided IP range is an example, not a production policy.

export AZURE_SUBSCRIPTION_ID="your-subscription-id"
./setup.sh "$AZURE_SUBSCRIPTION_ID" northeurope --accept-costs

Inspect the lab NSG and its rules in Azure. Change the allow priority through .lab-state/access.auto.tfvars.json, inspect the Terraform plan in .lab-state, and apply only the intended in-place update:

terraform -chdir=.lab-state plan -out=repair.tfplan
terraform -chdir=.lab-state show repair.tfplan
# Apply the saved plan only if it updates the lab NSG in place.
terraform -chdir=.lab-state apply repair.tfplan
./verify.sh

./verify.sh reads the Azure rules and checks Terraform for drift; it does not test actual packet flow or other NSGs, routes or firewalls.

Run ./teardown.sh when finished. Teardown refuses unexpected group contents or an attached NSG and retains private state on failure. Confirm that the lab resource group is gone before removing .lab-state.

View Markdown source ↗

Get the lab

Download and inspect the installer before running it. It checks the archive's SHA-256 digest and refuses to overwrite an existing lab directory.

curl -fsSLO https://devops.download/labs/secops-03-azure-shadowed-egress.sh
less secops-03-azure-shadowed-egress.sh
bash secops-03-azure-shadowed-egress.sh
cd labs/secops-03-azure-shadowed-egress
./setup.sh "$AZURE_SUBSCRIPTION_ID" northeurope --accept-costs

When you've made your changes, run ./verify.sh. Remove lab resources with ./teardown.sh.

Download the archive instead ↗

Need a nudge?

Hint #1

Azure evaluates lower numbered NSG priorities first. Compare the overlapping outbound rules.

Hint #2

The allow priority is controlled by .lab-state/access.auto.tfvars.json. Preserve both rules and review the Terraform plan before applying.

Hint #3 · Learning paths on opsbreakfix.com

Explore learning paths ↗

Solved it?

Continue learning with the paths on opsbreakfix.com.

Continue to opsbreakfix.com ↗

One ecosystem.
Many perspectives.

Follow the connection from a hands-on lab to the knowledge and tools behind it.