This guide explains how to set up automated validation for firewall rules CSV files on pull requests.
The PR validation pipeline (PR-Validation.yaml) automatically runs the Test-FirewallRulesCsv.ps1 script whenever a pull request is created or updated that modifies CSV files in config/parameters/FirewallRules/.
- Navigate to your Azure DevOps project
- Go to Pipelines → Pipelines
- Click New Pipeline (or Create Pipeline)
- Select Azure Repos Git (or your repository source)
- Select your repository
- Choose Existing Azure Pipelines YAML file
- Select the branch (e.g.,
mainordevelopment-testscript) - Path:
/.azuredevops/PR-Validation.yaml - Click Continue
- Click Save (or Run to test it)
To make the validation mandatory and block pull requests from being completed if validation fails:
- Go to Repos → Branches
- Find your target branch (e.g.,
main) - Click the ... menu next to the branch
- Select Branch policies
- Under Build Validation, click + to add a build policy
- Configure:
- Build pipeline: Select
PR-Validation(the pipeline you just created) - Trigger:
Automatic (whenever the source branch is updated) - Policy requirement:
Required✅⚠️ CRITICAL: Must be "Required", not "Optional" - Build expiration:
Immediately when main is updated - Display name:
Firewall Rules CSV Validation
- Build pipeline: Select
- Click Save
⚠️ Important: If you set the policy requirement to "Optional" instead of "Required", the Complete button will NOT be disabled when validation fails. You must use "Required" to block PRs.
-
Create a new branch from
main:git checkout main git pull git checkout -b test-pr-validation
-
Make a change to a CSV file (introduce an error for testing):
# Edit config/parameters/FirewallRules/FirewallRules.csv # For example, remove a quote to create a malformed CSV
-
Commit and push:
git add . git commit -m "Test PR validation" git push -u origin test-pr-validation
-
Create a pull request to
main -
The validation pipeline should automatically run
-
If validation fails:
- The PR will show a failed check ❌
- The Complete merge button will be greyed out/disabled
- A red warning banner will appear: "Firewall Rules CSV Validation failed"
- You cannot merge until errors are fixed
-
If validation passes:
- The PR will show a passed check ✅
- The Complete merge button will be enabled (blue/clickable)
- The PR can be completed/merged
The validation script checks:
-
✅ CSV Formatting
- Balanced quotes
- Proper field delimiters
- No missing commas between fields
-
✅ Required Columns
- All mandatory columns present
-
✅ Enum Values
- Valid RuleType, Action, CollectionType, SourceType, DestinationType
-
✅ Priority Conflicts
- No duplicate priorities within rule collection groups
- Consistent priority values
-
✅ IP Addresses & CIDR
- Valid IP address format
- Valid CIDR notation (e.g.,
10.0.0.0/24)
-
✅ FQDNs
- Valid domain name format
- Supports wildcards (e.g.,
*.microsoft.com)
-
✅ Protocols & Ports
- Valid protocol types
- Valid port numbers (1-65535)
- Proper format for application rules (e.g.,
Https:443)
-
✅ Rule Completeness
- Required fields present for each rule type
-
✅ Priority Ranges
- Priorities between 100-65000
-
🔒 Destination Restrictions (Security Check)
- Blocks Allow rules with destination
*(permits traffic to ANY destination) - Blocks Allow rules with
0.0.0.0/0or overly broad CIDR ranges - Wildcard FQDNs like
*.microsoft.comare allowed - Use
-AllowWildcardDestinationsto override (not recommended for production)
- Blocks Allow rules with destination
- Automatic: Runs on any PR to
mainthat modifies CSV files inconfig/parameters/FirewallRules/ - Manual: Can be run manually from Azure DevOps if needed
0: Validation passed ✅1: Validation failed ❌
- Detailed validation report in pipeline logs
- Color-coded results (errors in red, warnings in yellow, success in green)
- Line numbers for errors to help locate issues quickly
If you need to bypass validation in an emergency:
- Go to the PR
- Click on the failed validation check
- If you have permissions, you can override the policy
- Warning: This should only be used in exceptional circumstances
Solution:
- Check that the PR targets the
mainbranch - Check that the CSV file path matches
config/parameters/FirewallRules/**/*.csv - Verify the pipeline is enabled in Azure DevOps
Solution:
- Check for line ending differences (CRLF vs LF)
- Ensure the CSV file is committed with UTF-8 encoding
- Run:
.\pipeline-scripts\Test-FirewallRulesCsv.ps1 -PolicyCsvPath '.\config\parameters\FirewallRules\FirewallRules.csv'
Solution:
- Check for other branch policies (e.g., required reviewers)
- Ensure the build policy shows as "Succeeded"
- Try refreshing the PR page
Solution:
- Go to Repos → Branches → Find
main→ ... → Branch policies - Under Build Validation, find your
PR-Validationpolicy - Click Edit (pencil icon)
- Verify Policy requirement is set to
Required(NOT "Optional") - If it was "Optional", change it to "Required" and click Save
- Close and reopen your PR, or trigger the validation again
Before creating a PR, test locally:
# Test a specific CSV file
.\pipeline-scripts\Test-FirewallRulesCsv.ps1 -PolicyCsvPath '.\config\parameters\FirewallRules\FirewallRules.csv'
# Test with strict mode (warnings fail validation)
.\pipeline-scripts\Test-FirewallRulesCsv.ps1 -PolicyCsvPath '.\config\parameters\FirewallRules\FirewallRules.csv' -Strict