Skip to content

Commit 98eea5a

Browse files
Andrey Terentyevanton-evseev
authored andcommitted
Add Mssql value to Application Rule Type enum
1 parent 1ef4b32 commit 98eea5a

File tree

5 files changed

+66
-12
lines changed

5 files changed

+66
-12
lines changed

src/Network/Network.Test/ScenarioTests/AzureFirewallTests.ps1

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,13 @@ function Test-AzureFirewallCRUD
5858
$appRule2Port1 = 8080
5959
$appRule2ProtocolType1 = "http"
6060

61+
# AzureFirewallApplicationRule 3
62+
$appRule3Name = "appRule3"
63+
$appRule3Fqdn1 = "sql1.database.windows.net"
64+
$appRule3Protocol1 = "mssql:1433"
65+
$appRule3Port1 = 1433
66+
$appRule3ProtocolType1 = "mssql"
67+
6168
# AzureFirewallNetworkRuleCollection
6269
$networkRcName = "networkRc"
6370
$networkRcPriority = 200
@@ -160,11 +167,14 @@ function Test-AzureFirewallCRUD
160167

161168
$appRule2 = New-AzFirewallApplicationRule -Name $appRule2Name -Protocol $appRule2Protocol1 -TargetFqdn $appRule2Fqdn1
162169

170+
$appRule3 = New-AzFirewallApplicationRule -Name $appRule3Name -Protocol $appRule3Protocol1 -TargetFqdn $appRule3Fqdn1
171+
163172
# Create Application Rule Collection with 1 rule
164173
$appRc = New-AzFirewallApplicationRuleCollection -Name $appRcName -Priority $appRcPriority -Rule $appRule -ActionType $appRcActionType
165174

166175
# Add a rule to the rule collection using AddRule method
167176
$appRc.AddRule($appRule2)
177+
$appRc.AddRule($appRule3)
168178

169179
# Create a second Application Rule Collection with 1 rule
170180
$appRc2 = New-AzFirewallApplicationRuleCollection -Name $appRc2Name -Priority $appRc2Priority -Rule $appRule -ActionType $appRc2ActionType
@@ -233,7 +243,7 @@ function Test-AzureFirewallCRUD
233243

234244
# Check rule collections
235245
Assert-AreEqual 2 @($getAzureFirewall.ApplicationRuleCollections).Count
236-
Assert-AreEqual 2 @($getAzureFirewall.ApplicationRuleCollections[0].Rules).Count
246+
Assert-AreEqual 3 @($getAzureFirewall.ApplicationRuleCollections[0].Rules).Count
237247
Assert-AreEqual 1 @($getAzureFirewall.ApplicationRuleCollections[1].Rules).Count
238248

239249
Assert-AreEqual 1 @($getAzureFirewall.NatRuleCollections).Count
@@ -245,6 +255,7 @@ function Test-AzureFirewallCRUD
245255
$appRc = $getAzureFirewall.GetApplicationRuleCollectionByName($appRcName)
246256
$appRule = $appRc.GetRuleByName($appRule1Name)
247257
$appRule2 = $appRc.GetRuleByName($appRule2Name)
258+
$appRule3 = $appRc.GetRuleByName($appRule3Name)
248259

249260
# Verify application rule collection 1
250261
Assert-AreEqual $appRcName $appRc.Name
@@ -281,6 +292,19 @@ function Test-AzureFirewallCRUD
281292
Assert-AreEqual 1 $appRule2.TargetFqdns.Count
282293
Assert-AreEqual $appRule2Fqdn1 $appRule2.TargetFqdns[0]
283294

295+
# Verify application rule 3
296+
Assert-AreEqual $appRule3Name $appRule3.Name
297+
Assert-Null $appRule3.Description
298+
299+
Assert-AreEqual 0 $appRule3.SourceAddresses.Count
300+
301+
Assert-AreEqual 1 $appRule3.Protocols.Count
302+
Assert-AreEqual $appRule3ProtocolType1 $appRule3.Protocols[0].ProtocolType
303+
Assert-AreEqual $appRule3Port1 $appRule3.Protocols[0].Port
304+
305+
Assert-AreEqual 1 $appRule3.TargetFqdns.Count
306+
Assert-AreEqual $appRule3Fqdn1 $appRule3.TargetFqdns[0]
307+
284308
# Verify application rule collection 2
285309
$appRc2 = $getAzureFirewall.GetApplicationRuleCollectionByName($appRc2Name)
286310

@@ -505,16 +529,16 @@ function Test-AzureFirewallCRUDWithZones
505529
Assert-AreEqual @($list[0].NetworkRuleCollections).Count @($getAzureFirewall.NetworkRuleCollections).Count
506530

507531
# list all Azure Firewalls under subscription
508-
$listAll = Get-AzureRmFirewall
532+
$listAll = Get-AzFirewall
509533
Assert-NotNull $listAll
510534

511-
$listAll = Get-AzureRmFirewall -Name "*"
535+
$listAll = Get-AzFirewall -Name "*"
512536
Assert-NotNull $listAll
513537

514-
$listAll = Get-AzureRmFirewall -ResourceGroupName "*"
538+
$listAll = Get-AzFirewall -ResourceGroupName "*"
515539
Assert-NotNull $listAll
516540

517-
$listAll = Get-AzureRmFirewall -ResourceGroupName "*" -Name "*"
541+
$listAll = Get-AzFirewall -ResourceGroupName "*" -Name "*"
518542
Assert-NotNull $listAll
519543

520544
# Create Application Rules

src/Network/Network/AzureFirewall/ApplicationRule/NewAzureFirewallApplicationRuleCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public override void Execute()
7373

7474
if (FqdnTag != null)
7575
{
76-
this.Protocol = new string[] { "http", "https" };
76+
this.Protocol = PSAzureFirewallApplicationRuleProtocol.AllProtocols().ToArray();
7777
FqdnTag = AzureFirewallFqdnTagHelper.MapUserInputToAllowedFqdnTags(FqdnTag, this.AzureFirewallFqdnTagClient).ToArray();
7878
}
7979

src/Network/Network/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
- Added property 'PrivateEndpoint' as type of PSResourceId to PSNetworkInterface
3030
- Added property 'PrivateLinkConnectionProperties' as type of PSIpConfigurationConnectivityInformation to PSNetworkInterfaceIPConfiguration
3131
- Added new model class PSIpConfigurationConnectivityInformation
32+
* Added new ApplicationRuleProtocolType "mssql" for Azure Firewall resource
3233
* MultiLink support in Virtual WAN
3334
- New cmdlets
3435
- New-AzVpnSiteLink

src/Network/Network/Models/AzureFirewall/PSAzureFirewallApplicationRuleProtocol.cs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,26 +26,42 @@ public class PSAzureFirewallApplicationRuleProtocol
2626
public string ProtocolType { get; set; }
2727
public uint Port { get; set; }
2828

29+
public static List<string> AllProtocols()
30+
{
31+
return new List<string> {
32+
MNM.AzureFirewallApplicationRuleProtocolType.Http,
33+
MNM.AzureFirewallApplicationRuleProtocolType.Https,
34+
MNM.AzureFirewallApplicationRuleProtocolType.Mssql,
35+
};
36+
}
37+
2938
public static PSAzureFirewallApplicationRuleProtocol MapUserInputToApplicationRuleProtocol(string userInput)
3039
{
31-
var protocolRegEx = new Regex("^[hH][tT][tT][pP][sS]?(:[1-9][0-9]*)?$");
40+
var portRegEx = new Regex("^[1-9][0-9]*$");
3241

3342
var supportedProtocolsAndTheirDefaultPorts = new List<PSAzureFirewallApplicationRuleProtocol>
3443
{
3544
new PSAzureFirewallApplicationRuleProtocol { ProtocolType = MNM.AzureFirewallApplicationRuleProtocolType.Http, Port = 80 },
36-
new PSAzureFirewallApplicationRuleProtocol { ProtocolType = MNM.AzureFirewallApplicationRuleProtocolType.Https, Port = 443 }
45+
new PSAzureFirewallApplicationRuleProtocol { ProtocolType = MNM.AzureFirewallApplicationRuleProtocolType.Https, Port = 443 },
46+
new PSAzureFirewallApplicationRuleProtocol { ProtocolType = MNM.AzureFirewallApplicationRuleProtocolType.Mssql, Port = 1433 }
3747
};
3848

3949
//The actual validation is performed in NRP. Here we are just trying to map user info to our model
40-
if (!protocolRegEx.IsMatch(userInput))
41-
{
42-
throw new ArgumentException($"Invalid protocol {userInput}");
43-
}
4450

4551
var userParts = userInput.Split(':');
4652
var userProtocolText = userParts[0];
4753
var userPortText = userParts.Length == 2 ? userParts[1] : null;
4854

55+
if (!AllProtocols().Contains(userProtocolText, StringComparer.OrdinalIgnoreCase))
56+
{
57+
throw new ArgumentException($"Invalid protocol {userProtocolText}");
58+
}
59+
60+
if (userPortText != null && !portRegEx.IsMatch(userPortText))
61+
{
62+
throw new ArgumentException($"Invalid port {userPortText}");
63+
}
64+
4965
PSAzureFirewallApplicationRuleProtocol supportedProtocol;
5066
try
5167
{

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,19 @@ New-AzFirewall -Name "azFw" -ResourceGroupName $rgName -Location centralus -Virt
131131

132132
This example creates a Firewall attached to virtual network "vnet" with two public IP addresses.
133133

134+
### 8: Create a Firewall which allows MSSQL traffic to specific SQL database
135+
```
136+
$rgName = "resourceGroupName"
137+
$vnet = Get-AzVirtualNetwork -ResourceGroupName $rgName -Name "vnet"
138+
$pip = Get-AzPublicIpAddress -ResourceGroupName $rgName -Name "publicIpName"
139+
140+
$rule = New-AzFirewallApplicationRule -Name R1 -Protocol "mssql:1433" -TargetFqdn "sql1.database.windows.net"
141+
$ruleCollection = New-AzFirewallApplicationRuleCollection -Name RC1 -Priority 100 -Rule $rule -ActionType "Allow"
142+
New-AzFirewall -Name "azFw" -ResourceGroupName $rgName -Location centralus -VirtualNetwork $vnet -PublicIpAddress $pip -ApplicationRuleCollection $ruleCollection -ThreatIntelMode Deny
143+
```
144+
145+
This example creates a Firewall which allows MSSQL traffic on standard port 1433 to SQL database sql1.database.windows.net.
146+
134147
## PARAMETERS
135148

136149
### -ApplicationRuleCollection

0 commit comments

Comments
 (0)