Skip to content

Commit d5ac45e

Browse files
authored
Changing the Default Rule Set to DRS2.1 in Firewall Policy (#23760)
* edit ruleset * edit test * add changelog
1 parent daececc commit d5ac45e

File tree

6 files changed

+1466
-2
lines changed

6 files changed

+1466
-2
lines changed

src/Network/Network.Test/ScenarioTests/ApplicationGatewayTests.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,14 @@ public void TestApplicationGatewayFirewallPolicyManagedRuleGroupOverrideEmptyRul
221221
TestRunner.RunTestScript(string.Format("Test-ApplicationGatewayFirewallPolicyManagedRuleGroupOverrideEmptyRule -baseDir '{0}'", AppDomain.CurrentDomain.BaseDirectory));
222222
}
223223

224+
[Fact]
225+
[Trait(Category.AcceptanceType, Category.CheckIn)]
226+
[Trait(Category.Owner, NrpTeamAlias.nvadev_subset1)]
227+
public void TestApplicationGatewayFirewallPolicyDefaultRuleSet()
228+
{
229+
TestRunner.RunTestScript(string.Format("Test-ApplicationGatewayFirewallPolicyDefaultRuleSet -baseDir '{0}'", AppDomain.CurrentDomain.BaseDirectory));
230+
}
231+
224232
[Fact]
225233
[Trait(Category.AcceptanceType, Category.CheckIn)]
226234
[Trait(Category.Owner, NrpTeamAlias.nvadev_subset1)]

src/Network/Network.Test/ScenarioTests/ApplicationGatewayTests.ps1

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3875,6 +3875,63 @@ function Test-ApplicationGatewayFirewallPolicyManagedRuleGroupOverrideEmptyRule
38753875
}
38763876
}
38773877

3878+
<#
3879+
.SYNOPSIS
3880+
Application gateway v2 waf policy default managed rule set
3881+
#>
3882+
function Test-ApplicationGatewayFirewallPolicyDefaultRuleSet
3883+
3884+
{
3885+
# Setup
3886+
$location = Get-ProviderLocation "Microsoft.Network/applicationGateways" "West US 2"
3887+
3888+
$rgname = Get-ResourceGroupName
3889+
$wafPolicy = Get-ResourceName
3890+
3891+
try
3892+
{
3893+
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $location -Tags @{ testtag = "APPGw tag"}
3894+
3895+
# WAF Policy and Custom Rule
3896+
$variable = New-AzApplicationGatewayFirewallMatchVariable -VariableName RequestHeaders -Selector Content-Length
3897+
$condition = New-AzApplicationGatewayFirewallCondition -MatchVariable $variable -Operator GreaterThan -MatchValue 1000 -Transform Lowercase -NegationCondition $False
3898+
$rule = New-AzApplicationGatewayFirewallCustomRule -Name example -Priority 2 -RuleType MatchRule -MatchCondition $condition -Action Block
3899+
$policySettings = New-AzApplicationGatewayFirewallPolicySetting -Mode Prevention -State Enabled -MaxFileUploadInMb 70 -MaxRequestBodySizeInKb 70
3900+
New-AzApplicationGatewayFirewallPolicy -Name $wafPolicy -ResourceGroupName $rgname -Location $location -PolicySetting $policySettings
3901+
3902+
$policy = Get-AzApplicationGatewayFirewallPolicy -Name $wafPolicy -ResourceGroupName $rgname
3903+
$policy.CustomRules = $rule
3904+
Set-AzApplicationGatewayFirewallPolicy -InputObject $policy
3905+
3906+
$policy = Get-AzApplicationGatewayFirewallPolicy -Name $wafPolicy -ResourceGroupName $rgname
3907+
3908+
# Second check firewll policy
3909+
Assert-AreEqual $policy.CustomRules[0].Name $rule.Name
3910+
Assert-AreEqual $policy.CustomRules[0].RuleType $rule.RuleType
3911+
Assert-AreEqual $policy.CustomRules[0].Action $rule.Action
3912+
Assert-AreEqual $policy.CustomRules[0].Priority $rule.Priority
3913+
Assert-AreEqual $policy.CustomRules[0].MatchConditions[0].OperatorProperty $rule.MatchConditions[0].OperatorProperty
3914+
Assert-AreEqual $policy.CustomRules[0].MatchConditions[0].Transforms[0] $rule.MatchConditions[0].Transforms[0]
3915+
Assert-AreEqual $policy.CustomRules[0].MatchConditions[0].NegationConditon $rule.MatchConditions[0].NegationConditon
3916+
Assert-AreEqual $policy.CustomRules[0].MatchConditions[0].MatchValues[0] $rule.MatchConditions[0].MatchValues[0]
3917+
Assert-AreEqual $policy.CustomRules[0].MatchConditions[0].MatchVariables[0].VariableName $rule.MatchConditions[0].MatchVariables[0].VariableName
3918+
Assert-AreEqual $policy.CustomRules[0].MatchConditions[0].MatchVariables[0].Selector $rule.MatchConditions[0].MatchVariables[0].Selector
3919+
Assert-AreEqual $policy.PolicySettings.FileUploadLimitInMb $policySettings.FileUploadLimitInMb
3920+
Assert-AreEqual $policy.PolicySettings.MaxRequestBodySizeInKb $policySettings.MaxRequestBodySizeInKb
3921+
Assert-AreEqual $policy.PolicySettings.RequestBodyCheck $policySettings.RequestBodyCheck
3922+
Assert-AreEqual $policy.PolicySettings.Mode $policySettings.Mode
3923+
Assert-AreEqual $policy.PolicySettings.State $policySettings.State
3924+
Assert-AreEqual $policy.ManagedRules.ManagedRuleSets.RuleSetType "Microsoft_DefaultRuleSet"
3925+
Assert-AreEqual $policy.ManagedRules.ManagedRuleSets.RuleSetVersion "2.1"
3926+
3927+
}
3928+
finally
3929+
{
3930+
# Cleanup
3931+
Clean-ResourceGroup $rgname
3932+
}
3933+
}
3934+
38783935

38793936
<#
38803937
.SYNOPSIS

src/Network/Network.Test/SessionRecords/Commands.Network.Test.ScenarioTests.ApplicationGatewayTests/TestApplicationGatewayFirewallPolicyDefaultRuleSet.json

Lines changed: 1398 additions & 0 deletions
Large diffs are not rendered by default.

src/Network/Network/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
## Upcoming Release
2222
* Fixed a few minor issues
23+
* Changed the Default Rule Set from CRS3.0 to DRS2.1 in `NewAzureApplicationGatewayFirewallPolicy`
2324

2425
## Version 7.1.0
2526
* Added DefaultOutboundAccess parameter on subnet creation

src/Network/Network/FirewallPolicy/ManagedRules/AzureApplicationGatewayFirewallPolicyManagedRules.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected PSApplicationGatewayFirewallPolicyManagedRules NewObject()
5252
{
5353
new PSApplicationGatewayFirewallPolicyManagedRuleSet()
5454
{
55-
RuleSetType = "DRS",
55+
RuleSetType = "Microsoft_DefaultRuleSet",
5656
RuleSetVersion = "2.1"
5757
}
5858
};

src/Network/Network/FirewallPolicy/NewAzureApplicationGatewayFirewallPolicyCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private PSApplicationGatewayWebApplicationFirewallPolicy CreateApplicationGatewa
123123
{
124124
new PSApplicationGatewayFirewallPolicyManagedRuleSet()
125125
{
126-
RuleSetType = "DRS",
126+
RuleSetType = "Microsoft_DefaultRuleSet",
127127
RuleSetVersion = "2.1"
128128
}
129129
}

0 commit comments

Comments
 (0)