Skip to content

Commit fc8c820

Browse files
authored
Inspection Limit Feature for Application Gateway Firewall Policy Settings (#21603)
* 2 * 1 * 2 * new change * final test * true * new sdk * test name * merge conflict * description change * change test case var to false * help msg for var change * address comment * edit help file * revert previous change * change var to diabled * help edit * null condition * move condition outside * help function * new function to new var * edit var to nullable
1 parent db25c22 commit fc8c820

File tree

9 files changed

+1576
-3
lines changed

9 files changed

+1576
-3
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,14 @@ public void TestApplicationGatewayFirewallPolicyWithUppercaseTransform()
261261
TestRunner.RunTestScript("Test-ApplicationGatewayFirewallPolicyWithUppercaseTransform");
262262
}
263263

264+
[Fact]
265+
[Trait(Category.AcceptanceType, Category.CheckIn)]
266+
[Trait(Category.Owner, NrpTeamAlias.nvadev_subset1)]
267+
public void TestApplicationGatewayFirewallPolicyWithInspectionLimit()
268+
{
269+
TestRunner.RunTestScript("Test-ApplicationGatewayFirewallPolicyWithInspectionLimit");
270+
}
271+
264272
[Fact]
265273
[Trait(Category.AcceptanceType, Category.CheckIn)]
266274
[Trait(Category.Owner, NrpTeamAlias.nvadev_subset1)]

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

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4401,6 +4401,60 @@ function Test-ApplicationGatewayFirewallPolicyWithUppercaseTransform
44014401
}
44024402
}
44034403

4404+
function Test-ApplicationGatewayFirewallPolicyWithInspectionLimit
4405+
{
4406+
# Setup
4407+
$location = Get-ProviderLocation "Microsoft.Network/applicationGateways" "West US 2"
4408+
4409+
$rgname = Get-ResourceGroupName
4410+
$wafPolicy = Get-ResourceName
4411+
4412+
try
4413+
{
4414+
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $location -Tags @{ testtag = "APPGw tag"}
4415+
4416+
# WAF Policy and Custom Rule
4417+
$variable = New-AzApplicationGatewayFirewallMatchVariable -VariableName RequestHeaders -Selector Content-Length
4418+
$condition = New-AzApplicationGatewayFirewallCondition -MatchVariable $variable -Operator GreaterThan -MatchValue 1000 -Transform Uppercase -NegationCondition $False
4419+
$rule = New-AzApplicationGatewayFirewallCustomRule -Name example -Priority 2 -RuleType MatchRule -MatchCondition $condition -Action Block
4420+
$policySettings = New-AzApplicationGatewayFirewallPolicySetting -Mode Prevention -State Enabled -DisableRequestBodyEnforcement $True -RequestBodyInspectLimitInKB 2000 -MaxFileUploadInMb 70 -DisableFileUploadEnforcement $True -MaxRequestBodySizeInKb 70
4421+
$managedRuleSet = New-AzApplicationGatewayFirewallPolicyManagedRuleSet -RuleSetType "OWASP" -RuleSetVersion "3.2"
4422+
$managedRule = New-AzApplicationGatewayFirewallPolicyManagedRule -ManagedRuleSet $managedRuleSet
4423+
New-AzApplicationGatewayFirewallPolicy -Name $wafPolicy -ResourceGroupName $rgname -Location $location -ManagedRule $managedRule -PolicySetting $policySettings
4424+
4425+
$policy = Get-AzApplicationGatewayFirewallPolicy -Name $wafPolicy -ResourceGroupName $rgname
4426+
$policy.CustomRules = $rule
4427+
Set-AzApplicationGatewayFirewallPolicy -InputObject $policy
4428+
4429+
$policy = Get-AzApplicationGatewayFirewallPolicy -Name $wafPolicy -ResourceGroupName $rgname
4430+
4431+
# Check firewall policy
4432+
Assert-AreEqual $policy.CustomRules[0].Name $rule.Name
4433+
Assert-AreEqual $policy.CustomRules[0].RuleType $rule.RuleType
4434+
Assert-AreEqual $policy.CustomRules[0].Action $rule.Action
4435+
Assert-AreEqual $policy.CustomRules[0].Priority $rule.Priority
4436+
Assert-AreEqual $policy.CustomRules[0].MatchConditions[0].OperatorProperty $rule.MatchConditions[0].OperatorProperty
4437+
Assert-AreEqual $policy.CustomRules[0].MatchConditions[0].Transforms[0] $rule.MatchConditions[0].Transforms[0]
4438+
Assert-AreEqual $policy.CustomRules[0].MatchConditions[0].NegationConditon $rule.MatchConditions[0].NegationConditon
4439+
Assert-AreEqual $policy.CustomRules[0].MatchConditions[0].MatchValues[0] $rule.MatchConditions[0].MatchValues[0]
4440+
Assert-AreEqual $policy.CustomRules[0].MatchConditions[0].MatchVariables[0].VariableName $rule.MatchConditions[0].MatchVariables[0].VariableName
4441+
Assert-AreEqual $policy.CustomRules[0].MatchConditions[0].MatchVariables[0].Selector $rule.MatchConditions[0].MatchVariables[0].Selector
4442+
Assert-AreEqual $policy.PolicySettings.FileUploadLimitInMb $policySettings.FileUploadLimitInMb
4443+
Assert-AreEqual $policy.PolicySettings.MaxRequestBodySizeInKb $policySettings.MaxRequestBodySizeInKb
4444+
Assert-AreEqual $policy.PolicySettings.RequestBodyCheck $policySettings.RequestBodyCheck
4445+
Assert-AreEqual $policy.PolicySettings.Mode $policySettings.Mode
4446+
Assert-AreEqual $policy.PolicySettings.State $policySettings.State
4447+
Assert-AreEqual $False $policySettings.RequestBodyEnforcement
4448+
Assert-AreEqual $policy.PolicySettings.RequestBodyInspectLimitInKB $policySettings.RequestBodyInspectLimitInKB
4449+
Assert-AreEqual $False $policySettings.FileUploadEnforcement
4450+
}
4451+
finally
4452+
{
4453+
# Cleanup
4454+
Clean-ResourceGroup $rgname
4455+
}
4456+
}
4457+
44044458
function Test-ApplicationGatewayFirewallPolicyWithCustomBlockResponse
44054459
{
44064460
# Setup

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

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

src/Network/Network/ChangeLog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@
4545
- 'New-AzApplicationGatewayFirewallPolicyLogScrubbingRule',
4646
- Also updated cmdlet to add the property of LogScrubbing
4747
- `New-AzApplicationGatewayFirewallPolicySetting`
48+
* Updated cmdlet to add the property of DisableRequestBodyEnforcement, RequestBodyInspectLimitInKB and DisableFileUploadEnforcement
49+
- `New-AzApplicationGatewayFirewallPolicySetting`
50+
4851

4952

5053
## Version 5.6.0

src/Network/Network/FirewallPolicy/PolicySettings/AzureApplicationGatewayFirewallPolicySetting.cs

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,15 @@ public class AzureApplicationGatewayFirewallPolicySetting : NetworkBaseCmdlet
3333
[ValidateSet("Disabled", "Enabled", IgnoreCase = true)]
3434
[ValidateNotNullOrEmpty]
3535
public string State { get; set; }
36-
36+
37+
[Parameter(Mandatory = false, HelpMessage = "Disable request body enforcement limits for WAF.")]
38+
[ValidateNotNullOrEmpty]
39+
public bool? DisableRequestBodyEnforcement { get; set; }
40+
41+
[Parameter(Mandatory = false, HelpMessage = "Max inspection limit in KB for request body inspection.")]
42+
[ValidateNotNullOrEmpty]
43+
public int? RequestBodyInspectLimitInKB { get; set; }
44+
3745
[Parameter(
3846
HelpMessage = "Disable Request Body check.")]
3947
public SwitchParameter DisableRequestBodyCheck { get; set; }
@@ -43,6 +51,10 @@ public class AzureApplicationGatewayFirewallPolicySetting : NetworkBaseCmdlet
4351
[ValidateNotNullOrEmpty]
4452
public int MaxRequestBodySizeInKb { get; set; }
4553

54+
[Parameter(Mandatory = false, HelpMessage = "Disable file upload enforcement limits for WAF.")]
55+
[ValidateNotNullOrEmpty]
56+
public bool? DisableFileUploadEnforcement { get; set; }
57+
4658
[Parameter(
4759
HelpMessage = "Maximum fileUpload size in MB.")]
4860
[ValidateNotNullOrEmpty]
@@ -89,6 +101,21 @@ public override void ExecuteCmdlet()
89101
this.CustomBlockResponseStatusCode = (int?)null;
90102
}
91103

104+
if (!this.MyInvocation.BoundParameters.ContainsKey("RequestBodyInspectLimitInKB"))
105+
{
106+
this.RequestBodyInspectLimitInKB = (int?)null;
107+
}
108+
109+
if (!this.MyInvocation.BoundParameters.ContainsKey("DisableFileUploadEnforcement"))
110+
{
111+
this.DisableFileUploadEnforcement = (bool?)null;
112+
}
113+
114+
if (!this.MyInvocation.BoundParameters.ContainsKey("DisableRequestBodyEnforcement"))
115+
{
116+
this.DisableRequestBodyEnforcement = (bool?)null;
117+
}
118+
92119
if (this.MyInvocation.BoundParameters.ContainsKey("CustomBlockResponseBody"))
93120
{
94121
this.CustomBlockResponseBody = System.Convert.ToBase64String(Encoding.UTF8.GetBytes(CustomBlockResponseBody));
@@ -102,12 +129,34 @@ public override void ExecuteCmdlet()
102129

103130
protected PSApplicationGatewayFirewallPolicySettings NewObject()
104131
{
132+
bool? RequestBodyEnforcementVal = null;
133+
if (this.DisableRequestBodyEnforcement != null)
134+
{
135+
RequestBodyEnforcementVal = true;
136+
if (this.DisableRequestBodyEnforcement == true)
137+
{
138+
RequestBodyEnforcementVal = false;
139+
}
140+
}
141+
bool? FileUploadEnforcementVal = null;
142+
if (this.DisableFileUploadEnforcement != null)
143+
{
144+
FileUploadEnforcementVal = true;
145+
if (this.DisableFileUploadEnforcement == true)
146+
{
147+
FileUploadEnforcementVal = false;
148+
}
149+
}
150+
105151
return new PSApplicationGatewayFirewallPolicySettings()
106152
{
107153
Mode = this.Mode,
108154
State = this.State,
155+
RequestBodyEnforcement = RequestBodyEnforcementVal,
156+
RequestBodyInspectLimitInKB = this.RequestBodyInspectLimitInKB,
109157
RequestBodyCheck = this.DisableRequestBodyCheck.IsPresent ? false : true,
110158
MaxRequestBodySizeInKb = this.MaxRequestBodySizeInKb,
159+
FileUploadEnforcement = FileUploadEnforcementVal,
111160
FileUploadLimitInMb = this.MaxFileUploadInMb,
112161
CustomBlockResponseBody = this.CustomBlockResponseBody,
113162
CustomBlockResponseStatusCode = this.CustomBlockResponseStatusCode,

src/Network/Network/Models/PSApplicationGatewayFirewallPolicySettings.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,21 @@ public partial class PSApplicationGatewayFirewallPolicySettings
2828
[Ps1Xml(Target = ViewControl.Table)]
2929
public string Mode { get; set; }
3030

31+
[Ps1Xml(Target = ViewControl.Table)]
32+
public bool? RequestBodyEnforcement { get; set; }
33+
34+
[Ps1Xml(Target = ViewControl.Table)]
35+
public int? RequestBodyInspectLimitInKB { get; set; }
36+
3137
[Ps1Xml(Target = ViewControl.Table)]
3238
public bool RequestBodyCheck { get; set; }
3339

3440
[Ps1Xml(Target = ViewControl.Table)]
3541
public int MaxRequestBodySizeInKb { get; set; }
3642

43+
[Ps1Xml(Target = ViewControl.Table)]
44+
public bool? FileUploadEnforcement { get; set; }
45+
3746
[Ps1Xml(Target = ViewControl.Table)]
3847
public int FileUploadLimitInMb { get; set; }
3948

src/Network/Network/help/New-AzApplicationGatewayFirewallPolicySetting.md

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Creates a policy setting for the firewall policy
1313
## SYNTAX
1414

1515
```
16-
New-AzApplicationGatewayFirewallPolicySetting [-Mode <String>] [-State <String>] [-DisableRequestBodyCheck]
17-
[-MaxRequestBodySizeInKb <Int32>] [-MaxFileUploadInMb <Int32>] [-CustomBlockResponseStatusCode <Int32>]
16+
New-AzApplicationGatewayFirewallPolicySetting [-Mode <String>] [-State <String>] [-DisableRequestBodyEnforcement <Boolean>] [-RequestBodyInspectLimitInKB <Int32>] [-DisableRequestBodyCheck]
17+
[-MaxRequestBodySizeInKb <Int32>] [-MaxFileUploadInMb <Int32>] [-DisableFileUploadEnforcement <Boolean>] [-CustomBlockResponseStatusCode <Int32>]
1818
[-CustomBlockResponseBody <String>] [-LogScrubbing <PSApplicationGatewayFirewallPolicyLogScrubbingConfiguration>] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
1919
```
2020

@@ -39,8 +39,60 @@ $condition = New-AzApplicationGatewayFirewallPolicySetting -State $enabledState
3939
The command creates a policy setting with state as $enabledState, mode as $enabledMode, RequestBodyCheck as false, FileUploadLimitInMb as $fileUploadLimitInMb and MaxRequestBodySizeInKb as $$maxRequestBodySizeInKb with a scrubbing rule as $logScrubbingRuleConfig.
4040
The new policySettings is stored to $condition.
4141

42+
### Example 3
43+
```powershell
44+
$condition = New-AzApplicationGatewayFirewallPolicySetting -State $enabledState -Mode $enabledMode -DisableRequestBodyEnforcement true -RequestBodyInspectLimitInKB 2000 -DisableRequestBodyCheck -MaxFileUploadInMb $fileUploadLimitInMb -DisableFileUploadEnforcement true -MaxRequestBodySizeInKb $maxRequestBodySizeInKb
45+
```
46+
47+
The command creates a policy setting with state as $enabledState, mode as $enabledMode, RequestBodyEnforcement as false, RequestBodyInspectLimitInKB as 2000, RequestBodyCheck as false, FileUploadLimitInMb as $fileUploadLimitInMb, FileUploadEnforcement as false and MaxRequestBodySizeInKb as $$maxRequestBodySizeInKb.
48+
4249
## PARAMETERS
4350

51+
### -DisableRequestBodyEnforcement
52+
Disable request body enforcement limits for WAF.
53+
54+
```yaml
55+
Type: System.Nullable`1[System.Boolean]
56+
Parameter Sets: (All)
57+
Aliases:
58+
59+
Required: False
60+
Position: Named
61+
Default value: None
62+
Accept pipeline input: False
63+
Accept wildcard characters: False
64+
```
65+
66+
### -RequestBodyInspectLimitInKB
67+
Max inspection limit in KB for request body inspection.
68+
69+
```yaml
70+
Type: System.Nullable`1[System.Int32]
71+
Parameter Sets: (All)
72+
Aliases:
73+
74+
Required: False
75+
Position: Named
76+
Default value: None
77+
Accept pipeline input: False
78+
Accept wildcard characters: False
79+
```
80+
81+
### -DisableFileUploadEnforcement
82+
Disable file upload enforcement limits for WAF.
83+
84+
```yaml
85+
Type: System.Nullable`1[System.Boolean]
86+
Parameter Sets: (All)
87+
Aliases:
88+
89+
Required: False
90+
Position: Named
91+
Default value: None
92+
Accept pipeline input: False
93+
Accept wildcard characters: False
94+
```
95+
4496
### -CustomBlockResponseBody
4597
Custom Block Response Body in policy settings of the firewall policy.
4698
Binary file not shown.
Binary file not shown.

0 commit comments

Comments
 (0)