Skip to content

Commit c1624b4

Browse files
authored
Merge pull request #1 from venkatsvpr/network-october
Per listener/site firewall policy and geo-match operator
2 parents 7032e9b + cc2c6b9 commit c1624b4

9 files changed

+397
-4
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,5 +113,13 @@ public void TestTopLevelWafResourceWithApplicationGateway()
113113
{
114114
TestRunner.RunTestScript(string.Format("Test-ApplicationGatewayTopLevelFirewallPolicy -baseDir '{0}'", AppDomain.CurrentDomain.BaseDirectory));
115115
}
116+
117+
[Fact]
118+
[Trait(Category.AcceptanceType, Category.CheckIn)]
119+
[Trait(Category.Owner, NrpTeamAlias.nvadev)]
120+
public void TestApplicationGatewayWithPerSiteFirewallPolicy()
121+
{
122+
TestRunner.RunTestScript(string.Format("Test-ApplicationGatewayHttpListenerFirewallPolicy -baseDir '{0}'", AppDomain.CurrentDomain.BaseDirectory));
123+
}
116124
}
117125
}

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

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

src/Network/Network/ApplicationGateway/HttpListener/AzureApplicationGatewayHttpListenerBase.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ public class AzureApplicationGatewayHttpListenerBase : NetworkBaseCmdlet
5858
[ValidateNotNullOrEmpty]
5959
public string SslCertificateId { get; set; }
6060

61+
[Parameter(
62+
ParameterSetName = "SetByResourceId",
63+
HelpMessage = "FirewallPolicyId")]
64+
public string FirewallPolicyId { get; set; }
65+
66+
[Parameter(
67+
ParameterSetName = "SetByResource",
68+
HelpMessage = "FirewallPolicy")]
69+
public PSApplicationGatewayWebApplicationFirewallPolicy FirewallPolicy { get; set; }
70+
6171
[Parameter(
6272
ParameterSetName = "SetByResource",
6373
HelpMessage = "Application gateway SslCertificate")]
@@ -97,14 +107,21 @@ public override void ExecuteCmdlet()
97107
{
98108
this.FrontendIPConfigurationId = this.FrontendIPConfiguration.Id;
99109
}
110+
100111
if (FrontendPort != null)
101112
{
102113
this.FrontendPortId = this.FrontendPort.Id;
103114
}
115+
104116
if (SslCertificate != null)
105117
{
106118
this.SslCertificateId = this.SslCertificate.Id;
107119
}
120+
121+
if (FirewallPolicy != null)
122+
{
123+
this.FirewallPolicyId = this.FirewallPolicy.Id;
124+
}
108125
}
109126
}
110127

@@ -147,6 +164,12 @@ public PSApplicationGatewayHttpListener NewObject()
147164
httpListener.SslCertificate.Id = this.SslCertificateId;
148165
}
149166

167+
if (!string.IsNullOrEmpty(this.FirewallPolicyId))
168+
{
169+
httpListener.FirewallPolicy = new PSResourceId();
170+
httpListener.FirewallPolicy.Id = this.FirewallPolicyId;
171+
}
172+
150173
if (this.CustomErrorConfiguration != null)
151174
{
152175
httpListener.CustomErrorConfigurations = this.CustomErrorConfiguration?.ToList();

src/Network/Network/ApplicationGateway/PathRule/AzureApplicationGatewayPathRuleConfigBase.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,17 @@ public class AzureApplicationGatewayPathRuleConfigBase : NetworkBaseCmdlet
8080
HelpMessage = "Application gateway RedirectConfiguration")]
8181
[ValidateNotNullOrEmpty]
8282
public PSApplicationGatewayRedirectConfiguration RedirectConfiguration { get; set; }
83+
84+
[Parameter(
85+
ParameterSetName = "SetByResourceId",
86+
HelpMessage = "FirewallPolicyId")]
87+
public string FirewallPolicyId { get; set; }
8388

89+
[Parameter(
90+
ParameterSetName = "SetByResource",
91+
HelpMessage = "FirewallPolicy")]
92+
public PSApplicationGatewayWebApplicationFirewallPolicy FirewallPolicy { get; set; }
93+
8494
public override void ExecuteCmdlet()
8595
{
8696
base.ExecuteCmdlet();
@@ -91,18 +101,26 @@ public override void ExecuteCmdlet()
91101
{
92102
this.BackendAddressPoolId = this.BackendAddressPool.Id;
93103
}
104+
94105
if (BackendHttpSettings != null)
95106
{
96107
this.BackendHttpSettingsId = this.BackendHttpSettings.Id;
97108
}
109+
98110
if (RewriteRuleSet != null)
99111
{
100112
this.RewriteRuleSetId = this.RewriteRuleSet.Id;
101113
}
114+
102115
if (RedirectConfiguration != null)
103116
{
104117
this.RedirectConfigurationId = this.RedirectConfiguration.Id;
105118
}
119+
120+
if (FirewallPolicy != null)
121+
{
122+
this.FirewallPolicyId = this.FirewallPolicy.Id;
123+
}
106124
}
107125
}
108126

@@ -136,6 +154,12 @@ public PSApplicationGatewayPathRule NewObject()
136154
pathRule.RedirectConfiguration = new PSResourceId();
137155
pathRule.RedirectConfiguration.Id = this.RedirectConfigurationId;
138156
}
157+
158+
if (!string.IsNullOrEmpty(this.FirewallPolicyId))
159+
{
160+
pathRule.FirewallPolicy = new PSResourceId();
161+
pathRule.FirewallPolicy.Id = this.FirewallPolicyId;
162+
}
139163

140164
return pathRule;
141165
}

src/Network/Network/FirewallPolicy/FirewallCondition/AzureApplicationGatewayFirewallConditionBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public class AzureApplicationGatewayFirewallConditionBase : NetworkBaseCmdlet
3131
[Parameter(
3232
Mandatory = true,
3333
HelpMessage = "Describes operator to be matched.")]
34-
[ValidateSet("IPMatch", "Equal", "Contains", "LessThan", "GreaterThan", "LessThanOrEqual", "GreaterThanOrEqual", "BeginsWith", "EndsWith", "Regex", IgnoreCase = true)]
34+
[ValidateSet("IPMatch", "Equal", "Contains", "LessThan", "GreaterThan", "LessThanOrEqual", "GreaterThanOrEqual", "BeginsWith", "EndsWith", "Regex", "GeoMatch", IgnoreCase = true)]
3535
[ValidateNotNullOrEmpty]
3636
public string Operator { get; set; }
3737

src/Network/Network/Models/PSApplicationGatewayHttpListener.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public class PSApplicationGatewayHttpListener : PSChildResource
3434
public string ProvisioningState { get; set; }
3535
public string Type { get; set; }
3636
public List<PSApplicationGatewayCustomError> CustomErrorConfigurations { get; set; }
37+
public PSResourceId FirewallPolicy { get; set; }
3738

3839
[JsonIgnore]
3940
public string FrontendIpConfigurationText
@@ -52,5 +53,11 @@ public string SslCertificateText
5253
{
5354
get { return JsonConvert.SerializeObject(SslCertificate, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
5455
}
56+
57+
[JsonIgnore]
58+
public string FirewallPolicyText
59+
{
60+
get { return JsonConvert.SerializeObject(FirewallPolicy, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
61+
}
5562
}
5663
}

src/Network/Network/Models/PSApplicationGatewayPathRule.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public class PSApplicationGatewayPathRule : PSChildResource
2424
public PSResourceId BackendHttpSettings { get; set; }
2525
public PSResourceId RewriteRuleSet { get; set; }
2626
public PSResourceId RedirectConfiguration { get; set; }
27+
public PSResourceId FirewallPolicy { get; set; }
28+
2729
public string Type { get; set; }
2830

2931
[JsonIgnore]
@@ -55,5 +57,11 @@ public string RewriteRuleSetText
5557
{
5658
get { return JsonConvert.SerializeObject(RewriteRuleSet, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
5759
}
60+
61+
[JsonIgnore]
62+
public string FirewallPolicyText
63+
{
64+
get { return JsonConvert.SerializeObject(FirewallPolicy, Formatting.Indented, new JsonSerializerSettings() { NullValueHandling = NullValueHandling.Ignore }); }
65+
}
5866
}
5967
}

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

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ New-AzApplicationGatewayHttpListener -Name <String> [-FrontendIPConfigurationId
1919
[-FrontendPortId <String>] [-SslCertificateId <String>] [-HostName <String>]
2020
[-RequireServerNameIndication <String>] -Protocol <String>
2121
[-CustomErrorConfiguration <PSApplicationGatewayCustomError[]>] [-DefaultProfile <IAzureContextContainer>]
22+
[-FirewallPolicyId <String>]
2223
[<CommonParameters>]
2324
```
2425

@@ -27,6 +28,7 @@ New-AzApplicationGatewayHttpListener -Name <String> [-FrontendIPConfigurationId
2728
New-AzApplicationGatewayHttpListener -Name <String>
2829
[-FrontendIPConfiguration <PSApplicationGatewayFrontendIPConfiguration>]
2930
[-FrontendPort <PSApplicationGatewayFrontendPort>] [-SslCertificate <PSApplicationGatewaySslCertificate>]
31+
[-FirewallPolicy <PSApplicationGatewayWebApplicationFirewallPolicy>]
3032
[-HostName <String>] [-RequireServerNameIndication <String>] -Protocol <String>
3133
[-CustomErrorConfiguration <PSApplicationGatewayCustomError[]>] [-DefaultProfile <IAzureContextContainer>]
3234
[<CommonParameters>]
@@ -52,6 +54,13 @@ PS C:\>$Listener = New-AzApplicationGatewayHttpListener -Name "Listener01" -Prot
5254
This command creates an HTTP listener that uses SSL offload and provides the SSL certificate in the $SSLCert01 variable.
5355
The command stores the result in the variable named $Listener.
5456

57+
### Example 3: Create an HTTP listener with firewall-policy
58+
```
59+
PS C:\>$Listener = New-AzApplicationGatewayHttpListener -Name "Listener01" -Protocol "Http" -FrontendIpConfiguration $FIp01 -FrontendPort $FP01 -FirewallPolicy $firewallPolicy
60+
```
61+
62+
This command creates an HTTP listener named Listener01, FirewallPolicy as $firewallPolicy and stores the result in the variable named $Listener.
63+
5564
## PARAMETERS
5665

5766
### -CustomErrorConfiguration
@@ -234,6 +243,43 @@ Accept pipeline input: False
234243
Accept wildcard characters: False
235244
```
236245
246+
### -FirewallPolicy
247+
Specifies the object reference to a top-level firewall policy.
248+
The object reference can be created by using New-AzApplicationGatewayWebApplicationFirewallPolicy cmdlet.
249+
$firewallPolicy = New-AzApplicationGatewayFirewallPolicy -Name "wafPolicy1" -ResourceGroup "rgName"
250+
A firewall policy created using the above commandlet can be referred at a path-rule level.
251+
he above command would create a default policy settings and managed rules.
252+
Instead of the default values, users can specify PolicySettings, ManagedRules by using New-AzApplicationGatewayFirewallPolicySettings and New-AzApplicationGatewayFirewallPolicyManagedRules respectively.
253+
254+
```yaml
255+
Type: Microsoft.Azure.Commands.Network.Models.PSApplicationGatewayWebApplicationFirewallPolicy
256+
Aliases:
257+
258+
Required: False
259+
Position: Named
260+
Default value: None
261+
Accept pipeline input: False
262+
Accept wildcard characters: False
263+
```
264+
265+
### -FirewallPolicyId
266+
Specifies the ID of an existing top-level web application firewall resource.
267+
Firewall policy IDs can be returned by using the Get-AzApplicationGatewayWebApplicationFirewallPolicy cmdlet.
268+
After we have the ID you can use *FirewallPolicyId* parameter instead of *FirewallPolicy* parameter.
269+
For instance:
270+
-FirewallPolicyId “/subscriptions/<subscription-id>/resourceGroups/<resource-group-id>/providers/Microsoft.Network/ApplicationGatewayWebApplicationFirewallPolicies/<firewallPolicyName>”
271+
272+
```yaml
273+
Type: Microsoft.Azure.Commands.Network.Models.PSApplicationGatewayWebApplicationFirewallPolicy
274+
Aliases:
275+
276+
Required: False
277+
Position: Named
278+
Default value: None
279+
Accept pipeline input: False
280+
Accept wildcard characters: False
281+
```
282+
237283
### CommonParameters
238284
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).
239285

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

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Creates an application gateway path rule.
1717
```
1818
New-AzApplicationGatewayPathRuleConfig -Name <String> -Paths <String[]> [-BackendAddressPoolId <String>]
1919
[-BackendHttpSettingsId <String>] [-RewriteRuleSetId <String>] [-RedirectConfigurationId <String>]
20-
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
20+
[-FirewallPolicyId <String>] [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
2121
```
2222

2323
### SetByResource
@@ -26,6 +26,7 @@ New-AzApplicationGatewayPathRuleConfig -Name <String> -Paths <String[]>
2626
[-BackendAddressPool <PSApplicationGatewayBackendAddressPool>]
2727
[-BackendHttpSettings <PSApplicationGatewayBackendHttpSettings>]
2828
[-RewriteRuleSet <PSApplicationGatewayRewriteRuleSet>]
29+
[-FirewallPolicy <PSApplicationGatewayWebApplicationFirewallPolicy>]
2930
[-RedirectConfiguration <PSApplicationGatewayRedirectConfiguration>]
3031
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
3132
```
@@ -53,6 +54,13 @@ The next two commands create a backend address pool and a backend HTTP settings
5354
The fourth command creates the path rule object and is stored in a variable named $PathRuleConfig.
5455
The fifth command uses **Add-AzApplicationGatewayUrlPathMapConfig** to add the configuration settings and the new path rule contained within those settings to ContosoApplicationGateway.
5556

57+
### Example 2
58+
```
59+
PS C:\> $PathRuleConfig = New-AzApplicationGatewayPathRuleConfig -Name "base" -Paths "/base" -BackendAddressPool $AddressPool -BackendHttpSettings $HttpSettings -FirewallPolicy $firewallPolicy
60+
```
61+
62+
These command creates a path-rule with the Name as "base", Paths as "/base", BackendAddressPool as $AddressPool, BackendHttpSettings as $HttpSettings and FirewallPolicy as $firewallPolicy.ngs and the new path rule contained within those settings to ContosoApplicationGateway.
63+
5664
## PARAMETERS
5765

5866
### -BackendAddressPool
@@ -141,6 +149,43 @@ Accept pipeline input: False
141149
Accept wildcard characters: False
142150
```
143151
152+
### -FirewallPolicy
153+
Specifies the object reference to a top-level firewall policy.
154+
The object reference can be created by using New-AzApplicationGatewayWebApplicationFirewallPolicy cmdlet.
155+
$firewallPolicy = New-AzApplicationGatewayFirewallPolicy -Name "wafPolicy1" -ResourceGroup "rgName"
156+
A firewall policy created using the above commandlet can be referred at a path-rule level.
157+
he above command would create a default policy settings and managed rules.
158+
Instead of the default values, users can specify PolicySettings, ManagedRules by using New-AzApplicationGatewayFirewallPolicySettings and New-AzApplicationGatewayFirewallPolicyManagedRules respectively.
159+
160+
```yaml
161+
Type: Microsoft.Azure.Commands.Network.Models.PSApplicationGatewayWebApplicationFirewallPolicy
162+
Aliases:
163+
164+
Required: False
165+
Position: Named
166+
Default value: None
167+
Accept pipeline input: False
168+
Accept wildcard characters: False
169+
```
170+
171+
### -FirewallPolicyId
172+
Specifies the ID of an existing top-level web application firewall resource.
173+
Firewall policy IDs can be returned by using the Get-AzApplicationGatewayWebApplicationFirewallPolicy cmdlet.
174+
After we have the ID you can use *FirewallPolicyId* parameter instead of *FirewallPolicy* parameter.
175+
For instance:
176+
-FirewallPolicyId "/subscriptions/<subscription-id>/resourceGroups/<resource-group-id>/providers/Microsoft.Network/ApplicationGatewayWebApplicationFirewallPolicies/<firewallPolicyName>"
177+
178+
```yaml
179+
Type: Microsoft.Azure.Commands.Network.Models.PSApplicationGatewayWebApplicationFirewallPolicy
180+
Aliases:
181+
182+
Required: False
183+
Position: Named
184+
Default value: None
185+
Accept pipeline input: False
186+
Accept wildcard characters: False
187+
```
188+
144189
### -DefaultProfile
145190
The credentials, account, tenant, and subscription used for communication with azure.
146191

0 commit comments

Comments
 (0)