Skip to content

Azure Firewall Policy Commandlets #10204

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 65 commits into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
c293087
firewall policy progress
saisujithreddym Sep 23, 2019
195bd65
firewall policy progress
saisujithreddym Sep 23, 2019
317411d
firewall policy progress
saisujithreddym Sep 24, 2019
a702d9d
firewall policy changes
saisujithreddym Sep 27, 2019
63821d2
policy changes
saisujithreddym Sep 28, 2019
d85d916
policy progress
saisujithreddym Sep 28, 2019
367c9bd
powershell firewall policy changes
saisujithreddym Sep 28, 2019
818501b
help files
saisujithreddym Sep 28, 2019
c0a573e
help file changes
saisujithreddym Sep 28, 2019
7137794
set firewall policy changes
saisujithreddym Sep 29, 2019
8a747d5
policy changes
saisujithreddym Sep 29, 2019
891251b
policy changes
saisujithreddym Sep 30, 2019
5b1c03b
policy tests
saisujithreddym Sep 30, 2019
dba172f
rule group testing
saisujithreddym Oct 2, 2019
5b06ec7
parameter sets
saisujithreddym Oct 3, 2019
e987cf6
examples in the help files
saisujithreddym Oct 3, 2019
cb7e3d1
parameter set changes
saisujithreddym Oct 3, 2019
74cda5f
get rule group changes
saisujithreddym Oct 3, 2019
e93ca7f
new names for the cmdlets
saisujithreddym Oct 3, 2019
3f11614
name changes
saisujithreddym Oct 4, 2019
d4d8fa8
policy changes
saisujithreddym Oct 4, 2019
0dfc209
running tests
saisujithreddym Oct 7, 2019
b0051c7
clean up
saisujithreddym Oct 7, 2019
459cf04
base policy changes
saisujithreddym Oct 7, 2019
98b382f
seccion records
saisujithreddym Oct 7, 2019
f3f72d5
clean up
saisujithreddym Oct 7, 2019
1a38332
new help files
saisujithreddym Oct 7, 2019
3f5b0eb
example for rule collection group
saisujithreddym Oct 7, 2019
0b63468
new help example
saisujithreddym Oct 7, 2019
98eaeb7
changelog updated
saisujithreddym Oct 7, 2019
7099eb6
resolving merge conflicts
saisujithreddym Oct 7, 2019
a47e091
updating the help files
saisujithreddym Oct 7, 2019
58a359b
help file changes
saisujithreddym Oct 7, 2019
685c77d
Merge branch 'fpdebug' of https://github.com/saisujithreddym/azure-po…
saisujithreddym Oct 7, 2019
4eda5ff
updated help files
saisujithreddym Oct 8, 2019
1461788
Merge branch 'master' into azFirewallPolicy
markcowl Oct 8, 2019
339af86
resolving merge conflicts
saisujithreddym Oct 9, 2019
d7dfb37
Merge branch 'azFirewallPolicy' of https://github.com/saisujithreddym…
saisujithreddym Oct 9, 2019
9358880
fixed the help file
saisujithreddym Oct 9, 2019
2eb5702
addressing some comments
saisujithreddym Oct 10, 2019
67e868e
resolving comments
saisujithreddym Oct 11, 2019
df07be5
updating description in help files
saisujithreddym Oct 11, 2019
b1d098d
updated the help files
saisujithreddym Oct 11, 2019
1f34bce
addressing some comments
saisujithreddym Oct 13, 2019
c1619d3
addressing comments
saisujithreddym Oct 13, 2019
fecd13b
test fix
saisujithreddym Oct 13, 2019
f361b15
static analysis fix
saisujithreddym Oct 15, 2019
8fdefb0
updating Az.Network.md
saisujithreddym Oct 15, 2019
3594e0f
addressing comments
saisujithreddym Oct 15, 2019
e4c6521
addressing comments
saisujithreddym Oct 16, 2019
38eba2a
ability to create empty rulecollections and rulecollectionsgroups
saisujithreddym Oct 16, 2019
5b23ad3
adding the missing help file
saisujithreddym Oct 16, 2019
b55cc17
updated the online version
saisujithreddym Oct 16, 2019
1865b02
updated az.network md
saisujithreddym Oct 16, 2019
117508a
updated session records
saisujithreddym Oct 16, 2019
ac42fca
resolving the conflicts
saisujithreddym Oct 16, 2019
2ba1420
test case fix
saisujithreddym Oct 16, 2019
090f3a3
test fix
saisujithreddym Oct 16, 2019
8bd803d
name change for remove rule collection group
saisujithreddym Oct 16, 2019
160ff3e
updating help file
saisujithreddym Oct 16, 2019
41f9854
test pcase
saisujithreddym Oct 16, 2019
017a971
pascal case changes for firewall policy
saisujithreddym Oct 16, 2019
2f7ddc0
more changes for pascal case
saisujithreddym Oct 16, 2019
a6fc515
changes to trigger the build
saisujithreddym Oct 16, 2019
bddb179
trigger rebuild
saisujithreddym Oct 17, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/Network/Network.Test/ScenarioTests/AzureFirewallPolicyTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.Network.Test.ScenarioTests;
using Microsoft.WindowsAzure.Commands.ScenarioTest;
using Xunit;
using Xunit.Abstractions;

namespace Commands.Network.Test.ScenarioTests
{
public class AzureFirewallPolicyTests : NetworkTestRunner
{
public AzureFirewallPolicyTests(ITestOutputHelper output)
: base(output)
{
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
[Trait(Category.Owner, NrpTeamAlias.azurefirewall)]
public void TestAzureFirewallPolicyCRUD()
{
TestRunner.RunTestScript("Test-AzureFirewallPolicyCRUD");
}
}
}
217 changes: 217 additions & 0 deletions src/Network/Network.Test/ScenarioTests/AzureFirewallPolicyTests.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,217 @@
# ----------------------------------------------------------------------------------
#
# Copyright Microsoft Corporation
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ----------------------------------------------------------------------------------

<#
.SYNOPSIS
Tests AzureFirewallPolicyCRUD.
#>
function Test-AzureFirewallPolicyCRUD {
# Setup
$rgname = Get-ResourceGroupName
$azureFirewallPolicyName = Get-ResourceName
$azureFirewallPolicyAsJobName = Get-ResourceName
$resourceTypeParent = "Microsoft.Network/FirewallPolicies"
$location = "westcentralus"

$ruleGroupName = Get-ResourceName

# AzureFirewallPolicyApplicationRuleCollection
$appRcName = "appRc"
$appRcPriority = 400
$appRcActionType = "Allow"

$pipelineRcPriority = 154

# AzureFirewallPolicyApplicationRuleCollection 2
$appRc2Name = "appRc2"
$appRc2Priority = 300
$appRc2ActionType = "Deny"

# AzureFirewallPolicyApplicationRule 1
$appRule1Name = "appRule"
$appRule1Desc = "desc1"
$appRule1Fqdn1 = "*google.com"
$appRule1Fqdn2 = "*microsoft.com"
$appRule1Protocol1 = "http:80"
$appRule1Port1 = 80
$appRule1ProtocolType1 = "http"
$appRule1Protocol2 = "https:443"
$appRule1Port2 = 443
$appRule1ProtocolType2 = "https"
$appRule1SourceAddress1 = "192.168.0.0/16"

# AzureFirewallPolicyApplicationRule 2
$appRule2Name = "appRule2"
$appRule2Fqdn1 = "*bing.com"
$appRule2Protocol1 = "http:8080"
$appRule2Protocol2 = "https:443"
$appRule2Port1 = 8080
$appRule2ProtocolType1 = "http"
$appRule2SourceAddress1 = "192.168.0.0/16"

# AzureFirewallPolicyNetworkRuleCollection
$networkRcName = "networkRc"
$networkRcPriority = 200
$networkRcActionType = "Deny"

# AzureFirewallPolicyNetworkRule 1
$networkRule1Name = "networkRule"
$networkRule1Desc = "desc1"
$networkRule1SourceAddress1 = "10.0.0.0"
$networkRule1SourceAddress2 = "111.1.0.0/24"
$networkRule1DestinationAddress1 = "*"
$networkRule1Protocol1 = "UDP"
$networkRule1Protocol2 = "TCP"
$networkRule1Protocol3 = "ICMP"
$networkRule1DestinationPort1 = "90"

# AzureFirewallPolicyNatRuleCollection
$natRcName = "natRc"
$natRcPriority = 200
$natRcActionType = "Dnat"

# AzureFirewallPolicyNatRule 1
$natRule1Name = "natRule"
$natRule1Desc = "desc1"
$natRule1SourceAddress1 = "10.0.0.0"
$natRule1SourceAddress2 = "111.1.0.0/24"
$natRule1DestinationAddress1 = "1.2.3.4"
$natRule1Protocol1 = "UDP"
$natRule1Protocol2 = "TCP"
$natRule1DestinationPort1 = "90"
$natRule1TranslatedAddress = "10.1.2.3"
$natRule1TranslatedPort = "91"

try {
# Create the resource group
$resourceGroup = New-AzResourceGroup -Name $rgname -Location $location -Tags @{ testtag = "testval" }

# Create AzureFirewallPolicy (with no rules, ThreatIntel is in Alert mode by default)
$azureFirewallPolicy = New-AzFirewallPolicy -Name $azureFirewallPolicyName -ResourceGroupName $rgname -Location $location

# Get AzureFirewallPolicy
$getAzureFirewallPolicy = Get-AzFirewallPolicy -Name $azureFirewallPolicyName -ResourceGroupName $rgname

#verification
Assert-AreEqual $rgName $getAzureFirewallPolicy.ResourceGroupName
Assert-AreEqual $azureFirewallPolicyName $getAzureFirewallPolicy.Name
Assert-NotNull $getAzureFirewallPolicy.Location
Assert-AreEqual (Normalize-Location $location) $getAzureFirewallPolicy.Location
Assert-AreEqual "Alert" $getAzureFirewallPolicy.ThreatIntelMode


#Create Application Rules
$appRule = New-AzFirewallPolicyApplicationRule -Name $appRule1Name -Description $appRule1Desc -Protocol $appRule1Protocol1, $appRule1Protocol2 -TargetFqdn $appRule1Fqdn1, $appRule1Fqdn2 -SourceAddress $appRule1SourceAddress1
$appRule2 = New-AzFirewallPolicyApplicationRule -Name $appRule2Name -Description $appRule1Desc -Protocol $appRule2Protocol1, $appRule2Protocol2 -TargetFqdn $appRule2Fqdn1 -SourceAddress $appRule2SourceAddress1

# Create Network Rule Condition
$networkRule = New-AzFirewallPolicyNetworkRule -Name $networkRule1Name -Description $networkRule1Desc -Protocol $networkRule1Protocol1, $networkRule1Protocol2 -SourceAddress $networkRule1SourceAddress1, $networkRule1SourceAddress2 -DestinationAddress $networkRule1DestinationAddress1 -DestinationPort $networkRule1DestinationPort1

# Create Filter Rule with 2 rules
$appRc = New-AzFirewallPolicyFilterRuleCollection -Name $appRcName -Priority $appRcPriority -Rule $appRule, $appRule2 -ActionType $appRcActionType
# Create a second Filter Rule Collection with 1 rule
$appRc2 = New-AzFirewallPolicyFilterRuleCollection -Name $appRc2Name -Priority $appRc2Priority -Rule $networkRule -ActionType $appRc2ActionType

# Create a NAT rule
$natRc = New-AzFirewallPolicyNatRuleCollection -Name $networkRcName -Priority $natRcPriority -Rule $networkRule -TranslatedAddress $natRule1TranslatedAddress -TranslatedPort $natRule1TranslatedPort -ActionType $natRcActionType

New-AzFirewallPolicyRuleCollectionGroup -Name $ruleGroupName -Priority 100 -RuleCollection $appRc, $appRc2, $natRc -FirewallPolicyObject $azureFirewallPolicy


# # Update ThreatIntel mode
$azureFirewallPolicy.ThreatIntelMode = "Deny"
# Set AzureFirewallPolicy
Set-AzFirewallPolicy -InputObject $azureFirewallPolicy
# Get AzureFirewallPolicy
$getAzureFirewallPolicy = Get-AzFirewallPolicy -Name $azureFirewallPolicyName -ResourceGroupName $rgName

# #verification
Assert-AreEqual $rgName $getAzureFirewallPolicy.ResourceGroupName
Assert-AreEqual $azureFirewallPolicyName $getAzureFirewallPolicy.Name
Assert-NotNull $getAzureFirewallPolicy.Location
Assert-AreEqual $location $getAzureFirewallPolicy.Location
Assert-AreEqual "Deny" $getAzureFirewallPolicy.ThreatIntelMode

# # Check rule groups count
Assert-AreEqual 1 @($getAzureFirewallPolicy.RuleCollectionGroups).Count

$getRg = Get-AzFirewallPolicyRuleCollectionGroup -Name $ruleGroupName -AzureFirewallPolicy $getAzureFirewallPolicy

Assert-AreEqual 3 @($getRg.properties.ruleCollection).Count

$filterRuleCollection1 = $getRg.Properties.GetRuleCollectionByName($appRcName)
$natRuleCollection = $getRg.Properties.GetRuleCollectionByName($networkRcName)

# Verify filter Rule1
Assert-AreEqual $appRcName $filterRuleCollection1.Name
Assert-AreEqual $appRcPriority $filterRuleCollection1.Priority
Assert-AreEqual $appRcActionType $filterRuleCollection1.Action.Type
Assert-AreEqual 2 $filterRuleCollection1.Rules.Count

$appRule = $filterRuleCollection1.GetRuleByName($appRule1Name)
# Verify application rule 1
Assert-AreEqual $appRule1Name $appRule.Name

Assert-AreEqual 1 $appRule.SourceAddresses.Count
Assert-AreEqual $appRule1SourceAddress1 $appRule.SourceAddresses[0]

Assert-AreEqual 2 $appRule.Protocols.Count
Assert-AreEqual $appRule1ProtocolType1 $appRule.Protocols[0].ProtocolType
Assert-AreEqual $appRule1ProtocolType2 $appRule.Protocols[1].ProtocolType
Assert-AreEqual $appRule1Port1 $appRule.Protocols[0].Port
Assert-AreEqual $appRule1Port2 $appRule.Protocols[1].Port

Assert-AreEqual 2 $appRule.TargetFqdns.Count
Assert-AreEqual $appRule1Fqdn1 $appRule.TargetFqdns[0]
Assert-AreEqual $appRule1Fqdn2 $appRule.TargetFqdns[1]

# Verify NAT rule collection and NAT rule)
$natRule = $natRuleCollection.GetRuleByName($networkRcName)

Assert-AreEqual $networkRcName $natRuleCollection.Name
Assert-AreEqual $natRcPriority $natRuleCollection.Priority

Assert-AreEqual $networkRule1Name $natRule.Name

Assert-AreEqual 2 $natRule.SourceAddresses.Count
Assert-AreEqual $natRule1SourceAddress1 $natRule.SourceAddresses[0]
Assert-AreEqual $natRule1SourceAddress2 $natRule.SourceAddresses[1]

Assert-AreEqual 1 $natRule.DestinationAddresses.Count

Assert-AreEqual 2 $natRule.Protocols.Count
Assert-AreEqual $networkRule1Protocol1 $natRule.Protocols[0]
Assert-AreEqual $networkRule1Protocol2 $natRule.Protocols[1]

Assert-AreEqual 1 $natRule.DestinationPorts.Count
Assert-AreEqual $natRule1DestinationPort1 $natRule.DestinationPorts[0]

Assert-AreEqual $natRule1TranslatedAddress $natRuleCollection.TranslatedAddress
Assert-AreEqual $natRule1TranslatedPort $natRuleCollection.TranslatedPort


$testPipelineRg = Get-AzFirewallPolicyRuleCollectionGroup -Name $ruleGroupName -AzureFirewallPolicyName $getAzureFirewallPolicy.Name -ResourceGroupName $rgname
$testPipelineRg|Set-AzFirewallPolicyRuleCollectionGroup -Priority $pipelineRcPriority
$testPipelineRg = Get-AzFirewallPolicyRuleCollectionGroup -Name $ruleGroupName -AzureFirewallPolicyName $getAzureFirewallPolicy.Name -ResourceGroupName $rgname
Assert-AreEqual $pipelineRcPriority $testPipelineRg.properties.Priority

$azureFirewallPolicyAsJob = New-AzFirewallPolicy -Name $azureFirewallPolicyAsJobName -ResourceGroupName $rgname -Location $location -AsJob
$result = $azureFirewallPolicyAsJob | Wait-Job
Assert-AreEqual "Completed" $result.State;
}
finally {
# Cleanup
Clean-ResourceGroup $rgname
}
}
Loading