Skip to content

Commit da1f519

Browse files
authored
Merge pull request #9406 from Azure/waf-add-transforms
Add transforms to WAF match condition object (and other new auto-complete values)
2 parents 520232f + ab798d2 commit da1f519

File tree

10 files changed

+334
-282
lines changed

10 files changed

+334
-282
lines changed

src/FrontDoor/FrontDoor.Test/ScenarioTests/WebApplicationFireWallPolicyTests.ps1

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,15 @@ function Test-PolicyCrud
2222
$resourceGroup = TestSetup-CreateResourceGroup
2323
$resourceGroupName = $resourceGroup.ResourceGroupName
2424
$tags = @{"tag1" = "value1"; "tag2" = "value2"}
25-
$matchCondition1 = New-AzFrontDoorWafMatchConditionObject -MatchVariable RequestHeader -OperatorProperty Contains -Selector "UserAgent" -MatchValue "Windows"
25+
$matchCondition1 = New-AzFrontDoorWafMatchConditionObject -MatchVariable RequestHeader -OperatorProperty Contains -Selector "UserAgent" -MatchValue "WINDOWS" -Transform "Uppercase"
2626
$customRule1 = New-AzFrontDoorWafCustomRuleObject -Name "Rule1" -RuleType MatchRule -MatchCondition $matchCondition1 -Action Block -Priority 2
2727

2828
$ruleOverride = New-AzFrontDoorWafManagedRuleOverrideObject -RuleId "942100" -Action Log
2929
$override1 = New-AzFrontDoorWafRuleGroupOverrideObject -RuleGroupName SQLI -ManagedRuleOverride $ruleOverride
30-
$managedRule1 = New-AzFrontDoorWafManagedRuleObject -Type DefaultRuleSet -Version "preview-0.1" -RuleGroupOverride $override1
30+
$managedRule1 = New-AzFrontDoorWafManagedRuleObject -Type DefaultRuleSet -Version "1.0" -RuleGroupOverride $override1
31+
$managedRule2 = New-AzFrontDoorWafManagedRuleObject -Type BotProtection -Version "preview-0.1"
3132

32-
New-AzFrontDoorWafPolicy -Name $Name -ResourceGroupName $resourceGroupName -Customrule $customRule1 -ManagedRule $managedRule1 -EnabledState Enabled -Mode Prevention
33+
New-AzFrontDoorWafPolicy -Name $Name -ResourceGroupName $resourceGroupName -Customrule $customRule1 -ManagedRule $managedRule1,$managedRule2 -EnabledState Enabled -Mode Prevention
3334

3435
$retrievedPolicy = Get-AzFrontDoorWafPolicy -Name $Name -ResourceGroupName $resourceGroupName
3536
Assert-NotNull $retrievedPolicy
@@ -38,7 +39,16 @@ function Test-PolicyCrud
3839
Assert-AreEqual $customRule1.RuleType $retrievedPolicy.CustomRules[0].RuleType
3940
Assert-AreEqual $customRule1.Action $retrievedPolicy.CustomRules[0].Action
4041
Assert-AreEqual $customRule1.Priority $retrievedPolicy.CustomRules[0].Priority
42+
Assert-AreEqual $matchCondition1.MatchVariable $retrievedPolicy.CustomRules[0].MatchConditions[0].MatchVariable
43+
Assert-AreEqual $matchCondition1.Selector $retrievedPolicy.CustomRules[0].MatchConditions[0].Selector
44+
Assert-AreEqual $matchCondition1.OperatorProperty $retrievedPolicy.CustomRules[0].MatchConditions[0].OperatorProperty
45+
Assert-AreEqual $matchCondition1.MatchValue[0] $retrievedPolicy.CustomRules[0].MatchConditions[0].MatchValue[0]
46+
Assert-AreEqual $matchCondition1.Transform[0] $retrievedPolicy.CustomRules[0].MatchConditions[0].Transform[0]
4147
Assert-AreEqual $managedRule1.RuleGroupOverrides[0].ManagedRuleOverrides[0].Action $retrievedPolicy.ManagedRules[0].RuleGroupOverrides[0].ManagedRuleOverrides[0].Action
48+
Assert-AreEqual $managedRule1.RuleSetType $retrievedPolicy.ManagedRules[0].RuleSetType
49+
Assert-AreEqual $managedRule1.RuleSetVersion $retrievedPolicy.ManagedRules[0].RuleSetVersion
50+
Assert-AreEqual $managedRule2.RuleSetType $retrievedPolicy.ManagedRules[1].RuleSetType
51+
Assert-AreEqual $managedRule2.RuleSetVersion $retrievedPolicy.ManagedRules[1].RuleSetVersion
4252

4353
$customRule2 = New-AzFrontDoorWafCustomRuleObject -Name "Rule2" -RuleType MatchRule -MatchCondition $matchCondition1 -Action Log -Priority 2
4454
$updatedPolicy = Update-AzFrontDoorWafPolicy -Name $Name -ResourceGroupName $resourceGroupName -Customrule $customRule2
@@ -64,14 +74,15 @@ function Test-PolicyCrudWithPiping
6474
$resourceGroup = TestSetup-CreateResourceGroup
6575
$resourceGroupName = $resourceGroup.ResourceGroupName
6676
$tag = @{"tag1" = "value1"; "tag2" = "value2"}
67-
$matchCondition1 = New-AzFrontDoorWafMatchConditionObject -MatchVariable RequestHeader -OperatorProperty Contains -Selector "UserAgent" -MatchValue "Windows"
77+
$matchCondition1 = New-AzFrontDoorWafMatchConditionObject -MatchVariable RequestHeader -OperatorProperty Contains -Selector "UserAgent" -MatchValue "WINDOWS" -Transform "Uppercase"
6878
$customRule1 = New-AzFrontDoorWafCustomRuleObject -Name "Rule1" -RuleType MatchRule -MatchCondition $matchCondition1 -Action Block -Priority 2
6979

7080
$ruleOverride = New-AzFrontDoorWafManagedRuleOverrideObject -RuleId "942100" -Action Log
7181
$override1 = New-AzFrontDoorWafRuleGroupOverrideObject -RuleGroupName SQLI -ManagedRuleOverride $ruleOverride
72-
$managedRule1 = New-AzFrontDoorWafManagedRuleObject -Type DefaultRuleSet -Version "preview-0.1" -RuleGroupOverride $override1
82+
$managedRule1 = New-AzFrontDoorWafManagedRuleObject -Type DefaultRuleSet -Version "1.0" -RuleGroupOverride $override1
83+
$managedRule2 = New-AzFrontDoorWafManagedRuleObject -Type BotProtection -Version "preview-0.1"
7384

74-
New-AzFrontDoorWafPolicy -Name $Name -ResourceGroupName $resourceGroupName -Customrule $customRule1 -ManagedRule $managedRule1 -EnabledState Enabled -Mode Prevention
85+
New-AzFrontDoorWafPolicy -Name $Name -ResourceGroupName $resourceGroupName -Customrule $customRule1 -ManagedRule $managedRule1,$managedRule2 -EnabledState Enabled -Mode Prevention
7586

7687
$customRule2 = New-AzFrontDoorWafCustomRuleObject -Name "Rule2" -RuleType MatchRule -MatchCondition $matchCondition1 -Action Log -Priority 2
7788
$updatedPolicy = Get-AzFrontDoorWafPolicy -Name $Name -ResourceGroupName $resourceGroupName | Update-AzFrontDoorWafPolicy -Customrule $customRule2

src/FrontDoor/FrontDoor.Test/SessionRecords/Microsoft.Azure.Commands.FrontDoor.Test.ScenarioTests.ScenarioTest.WebApplicationFireWallPolicyTests/TestPolicyCrud.json

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

src/FrontDoor/FrontDoor.Test/SessionRecords/Microsoft.Azure.Commands.FrontDoor.Test.ScenarioTests.ScenarioTest.WebApplicationFireWallPolicyTests/TestPolicyCrudWithPiping.json

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

src/FrontDoor/FrontDoor/ChangeLog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
- Additional information about change #1
1919
-->
2020
## Upcoming Release
21+
* New-AzFrontDoorWafMatchConditionObject
22+
- Add transforms support and new operator auto-complete value (RegEx)
23+
* New-AzFrontDoorWafManagedRuleObject
24+
- Add new auto-complete values
2125

2226
## Version 1.0.0
2327
* Rename WAF cmdlets to include 'Waf'

src/FrontDoor/FrontDoor/Cmdlets/NewAzureRmFrontDoorWafManagedRuleObject.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,14 @@ public class NewAzureRmFrontDoorWafManagedRuleObject : AzureFrontDoorCmdletBase
3030
/// Type of the ruleset (e.g.: DefaultRuleSet)
3131
/// </summary>
3232
[Parameter(Mandatory = true, HelpMessage = "Type of the ruleset")]
33-
[PSArgumentCompleter("DefaultRuleSet")]
33+
[PSArgumentCompleter("BotProtection", "DefaultRuleSet")]
3434
public string Type { get; set; }
3535

3636
/// <summary>
3737
/// Version of the ruleset (e.g.: preview-0.1)
3838
/// </summary>
3939
[Parameter(Mandatory = true, HelpMessage = "Version of the ruleset")]
40-
[PSArgumentCompleter("preview-0.1")]
40+
[PSArgumentCompleter("1.0", "preview-0.1")]
4141
public string Version { get; set; }
4242

4343
/// <summary>

src/FrontDoor/FrontDoor/Cmdlets/NewAzureRmFrontDoorWafMatchConditionObject.cs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ public class NewAzureRmFrontDoorWafMatchConditionObject : AzureFrontDoorCmdletBa
4343
/// 'Contains', 'LessThan', 'GreaterThan', 'LessThanOrEqual',
4444
/// 'GreaterThanOrEqual', 'BeginsWith', 'EndsWith'
4545
/// </summary>
46-
[Parameter(Mandatory = true, HelpMessage = "Describes operator to be matched. Possible values include: 'Any', 'IPMatch', 'GeoMatch', 'Equal', 'Contains', 'LessThan', 'GreaterThan', 'LessThanOrEqual', 'GreaterThanOrEqual', 'BeginsWith', 'EndsWith''")]
47-
[PSArgumentCompleter("Any", "IPMatch", "GeoMatch", "Equal", "Contains", "LessThan", "GreaterThan", "LessThanOrEqual", "GreaterThanOrEqual", "BeginsWith", "EndsWith")]
46+
[Parameter(Mandatory = true, HelpMessage = "Describes operator to be matched. Possible values include: 'Any', 'IPMatch', 'GeoMatch', 'Equal', 'Contains', 'LessThan', 'GreaterThan', 'LessThanOrEqual', 'GreaterThanOrEqual', 'BeginsWith', 'EndsWith', 'RegEx'")]
47+
[PSArgumentCompleter("Any", "IPMatch", "GeoMatch", "Equal", "Contains", "LessThan", "GreaterThan", "LessThanOrEqual", "GreaterThanOrEqual", "BeginsWith", "EndsWith", "RegEx")]
4848
public string OperatorProperty { get; set; }
4949

5050
/// <summary>
@@ -65,6 +65,13 @@ public class NewAzureRmFrontDoorWafMatchConditionObject : AzureFrontDoorCmdletBa
6565
[Parameter(Mandatory = false, HelpMessage = "Describes if this is negate condition or not. Default value is false")]
6666
public bool NegateCondition { get; set; }
6767

68+
/// <summary>
69+
/// Tranforms value.
70+
/// </summary>
71+
[Parameter(Mandatory = false, HelpMessage = "Transforms to apply. Possible values include: 'Lowercase', 'Uppercase', 'Trim', 'UrlDecode', 'UrlEncode', 'RemoveNulls'.")]
72+
[PSArgumentCompleter("Lowercase", "Uppercase", "Trim", "UrlDecode", "UrlEncode", "RemoveNulls")]
73+
public string[] Transform { get; set; }
74+
6875
public override void ExecuteCmdlet()
6976
{
7077
ValidateArguments();
@@ -75,7 +82,8 @@ public override void ExecuteCmdlet()
7582
MatchValue = MatchValue?.ToList(),
7683
NegateCondition = !this.IsParameterBound(c => c.NegateCondition) ? false : NegateCondition,
7784
OperatorProperty = OperatorProperty,
78-
Selector = Selector
85+
Selector = Selector,
86+
Transform = Transform?.ToList()
7987
};
8088
WriteObject(matchCondition);
8189
}

src/FrontDoor/FrontDoor/Helpers/ModelExtensions.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,7 @@ public static PSMatchCondition ToPSMatchCondition(this sdkMatchCondition sdkMatc
393393
OperatorProperty = sdkMatchCondition.OperatorProperty,
394394
Selector = sdkMatchCondition.Selector,
395395
NegateCondition = sdkMatchCondition.NegateCondition,
396+
Transform = sdkMatchCondition.Transforms?.ToList()
396397
};
397398
}
398399

@@ -432,7 +433,8 @@ public static sdkMatchCondition ToSdkMatchCondition(this PSMatchCondition psMatc
432433
MatchVariable = psMatchCondition.MatchVariable,
433434
NegateCondition = psMatchCondition.NegateCondition,
434435
Selector = psMatchCondition.Selector,
435-
OperatorProperty = psMatchCondition.OperatorProperty
436+
OperatorProperty = psMatchCondition.OperatorProperty,
437+
Transforms = psMatchCondition.Transform
436438
};
437439
}
438440

src/FrontDoor/FrontDoor/Models/PSMatchCondition.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,5 +28,7 @@ public class PSMatchCondition
2828
public string Selector { get; set; }
2929

3030
public bool? NegateCondition { get; set; }
31+
32+
public List<string> Transform { get; set; }
3133
}
3234
}

src/FrontDoor/FrontDoor/help/Az.FrontDoor.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ Enable HTTPS for a custom domain using Front Door managed certificate or using o
2020
### [Get-AzFrontDoor](Get-AzFrontDoor.md)
2121
Get Front Door load balancer
2222

23-
### [Get-AzFrontDoorWafPolicy](Get-AzFrontDoorWafPolicy.md)
24-
Get WAF policy
25-
2623
### [Get-AzFrontDoorFrontendEndpoint](Get-AzFrontDoorFrontendEndpoint.md)
2724
Get a front door frontend endpoint.
2825

26+
### [Get-AzFrontDoorWafPolicy](Get-AzFrontDoorWafPolicy.md)
27+
Get WAF policy
28+
2929
### [New-AzFrontDoor](New-AzFrontDoor.md)
3030
Create a new Azure Front Door load balancer
3131

@@ -35,12 +35,6 @@ Create a PSBackend object
3535
### [New-AzFrontDoorBackendPoolObject](New-AzFrontDoorBackendPoolObject.md)
3636
Create a PSBackendPool object for Front Door creation
3737

38-
### [New-AzFrontDoorWafCustomRuleObject](New-AzFrontDoorWafCustomRuleObject.md)
39-
Create CustomRule Object for WAF policy creation
40-
41-
### [New-AzFrontDoorWafPolicy](New-AzFrontDoorWafPolicy.md)
42-
Create WAF policy
43-
4438
### [New-AzFrontDoorFrontendEndpointObject](New-AzFrontDoorFrontendEndpointObject.md)
4539
Create a PSFrontendEndpoint Object for Front Door creation
4640

@@ -50,6 +44,12 @@ Create a PSHealthProbeSetting object for Front Door creation
5044
### [New-AzFrontDoorLoadBalancingSettingObject](New-AzFrontDoorLoadBalancingSettingObject.md)
5145
Create a PSLoadBalancingSetting object for Front Door creation
5246

47+
### [New-AzFrontDoorRoutingRuleObject](New-AzFrontDoorRoutingRuleObject.md)
48+
Create a PSRoutingRuleObject for Front Door creation
49+
50+
### [New-AzFrontDoorWafCustomRuleObject](New-AzFrontDoorWafCustomRuleObject.md)
51+
Create CustomRule Object for WAF policy creation
52+
5353
### [New-AzFrontDoorWafManagedRuleObject](New-AzFrontDoorWafManagedRuleObject.md)
5454
Create ManagedRule Object for WAF policy creation
5555

@@ -59,8 +59,8 @@ Create managed rule override object
5959
### [New-AzFrontDoorWafMatchConditionObject](New-AzFrontDoorWafMatchConditionObject.md)
6060
Create MatchCondition Object for WAF policy creation
6161

62-
### [New-AzFrontDoorRoutingRuleObject](New-AzFrontDoorRoutingRuleObject.md)
63-
Create a PSRoutingRuleObject for Front Door creation
62+
### [New-AzFrontDoorWafPolicy](New-AzFrontDoorWafPolicy.md)
63+
Create WAF policy
6464

6565
### [New-AzFrontDoorWafRuleGroupOverrideObject](New-AzFrontDoorWafRuleGroupOverrideObject.md)
6666
Create RuleGroupOverride Object for WAF policy creation

src/FrontDoor/FrontDoor/help/New-AzFrontDoorWafMatchConditionObject.md

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ Create MatchCondition Object for WAF policy creation
1313
## SYNTAX
1414

1515
```
16-
New-AzFrontDoorWafMatchConditionObject -MatchVariable <String> -OperatorProperty <String> [-MatchValue <String[]>]
17-
[-Selector <String>] [-NegateCondition <Boolean>] [-DefaultProfile <IAzureContextContainer>]
18-
[<CommonParameters>]
16+
New-AzFrontDoorWafMatchConditionObject -MatchVariable <String> -OperatorProperty <String>
17+
[-MatchValue <String[]>] [-Selector <String>] [-NegateCondition <Boolean>] [-Transform <String[]>]
18+
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
1919
```
2020

2121
## DESCRIPTION
@@ -28,9 +28,19 @@ Create MatchCondition Object for WAF policy creation
2828
PS C:\> New-AzFrontDoorWafMatchConditionObject -MatchVariable RequestHeader -OperatorProperty Contains -Selector "User-Agent" -MatchValue "Windows"
2929
3030
31-
MatchVariable OperatorProperty MatchValue Selector NegateCondition
32-
------------- ---------------- ---------- -------- ---------------
33-
RequestHeader Contains {Windows} User-Agent False
31+
MatchVariable OperatorProperty MatchValue Selector NegateCondition Transform
32+
------------- ---------------- ---------- -------- --------------- ---------
33+
RequestHeader Contains {Windows} User-Agent False
34+
```
35+
36+
### Example 2
37+
```powershell
38+
PS C:\> New-AzFrontDoorWafMatchConditionObject -MatchVariable RequestHeader -OperatorProperty Contains -Selector "User-Agent" -MatchValue "WINDOWS" -Transform Uppercase
39+
40+
41+
MatchVariable OperatorProperty MatchValue Selector NegateCondition Transform
42+
------------- ---------------- ---------- -------- --------------- ---------
43+
RequestHeader Contains {WINDOWS} User-Agent False {Uppercase}
3444
```
3545

3646
Create a MatchCondition object
@@ -101,7 +111,7 @@ Accept wildcard characters: False
101111
102112
### -OperatorProperty
103113
Describes operator to be matched.
104-
Possible values include: 'Any', 'IPMatch', 'GeoMatch', 'Equal', 'Contains', 'LessThan', 'GreaterThan', 'LessThanOrEqual', 'GreaterThanOrEqual', 'BeginsWith', 'EndsWith''
114+
Possible values include: 'Any', 'IPMatch', 'GeoMatch', 'Equal', 'Contains', 'LessThan', 'GreaterThan', 'LessThanOrEqual', 'GreaterThanOrEqual', 'BeginsWith', 'EndsWith', 'RegEx'
105115
106116
```yaml
107117
Type: System.String
@@ -130,6 +140,21 @@ Accept pipeline input: False
130140
Accept wildcard characters: False
131141
```
132142
143+
### -Transform
144+
Transforms to apply. Possible values include: 'Lowercase', 'Uppercase', 'Trim', 'UrlDecode', 'UrlEncode', 'RemoveNulls'.
145+
146+
```yaml
147+
Type: System.String[]
148+
Parameter Sets: (All)
149+
Aliases:
150+
151+
Required: False
152+
Position: Named
153+
Default value: None
154+
Accept pipeline input: False
155+
Accept wildcard characters: False
156+
```
157+
133158
### CommonParameters
134159
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).
135160

0 commit comments

Comments
 (0)