Skip to content

Azure Firewall Packet Capture Cmdlet Update [public preview feature] #28163

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

Open
wants to merge 9 commits into
base: release-network-2024-10-01
Choose a base branch
from
132 changes: 66 additions & 66 deletions src/Network/Network.Management.Sdk/README.md

Large diffs are not rendered by default.

24 changes: 20 additions & 4 deletions src/Network/Network.Test/ScenarioTests/AzureFirewallTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -2159,8 +2159,9 @@ function Test-InvokeAzureFirewallPacketCapture {
$mgmtSubnet = Get-AzVirtualNetworkSubnetConfig -VirtualNetwork $vnet -Name $mgmtSubnetName

# Create public ips
$publicip1 = New-AzPublicIpAddress -ResourceGroupName $rgname -name $publicIp1Name -location $location -AllocationMethod Static -Sku Standard
$mgmtPublicIp = New-AzPublicIpAddress -ResourceGroupName $rgname -name $mgmtPublicIpName -location $location -AllocationMethod Static -Sku Standard
$tag = New-AzPublicIpTag -IpTagType "FirstPartyUsage" -Tag "/NonProd"
$publicip1 = New-AzPublicIpAddress -ResourceGroupName $rgname -name $publicIp1Name -location $location -AllocationMethod Static -Sku Standard -IpTag $tag
$mgmtPublicIp = New-AzPublicIpAddress -ResourceGroupName $rgname -name $mgmtPublicIpName -location $location -AllocationMethod Static -Sku Standard -IpTag $tag

# Create AzureFirewall with a management IP
$azureFirewall = New-AzFirewall -Name $azureFirewallName -ResourceGroupName $rgname -Location $location -VirtualNetwork $vnet -PublicIpAddress $publicip1 -ManagementPublicIpAddress $mgmtPublicIp
Expand All @@ -2175,12 +2176,27 @@ function Test-InvokeAzureFirewallPacketCapture {
$filter2 = New-AzFirewallPacketCaptureRule -Source "10.0.0.5" -Destination "172.20.10.2" -DestinationPort "80","443"

# Create the firewall packet capture parameters
$Params = New-AzFirewallPacketCaptureParameter -DurationInSeconds 30 -NumberOfPackets 500 -SASUrl $sasurl -Filename "AzFwPowershellPacketCapture" -Flag "Syn","Ack" -Protocol "Any" -Filter $Filter1, $Filter2
$Params = New-AzFirewallPacketCaptureParameter -DurationInSeconds 1200 -NumberOfPackets 20000 -SASUrl $sasurl -Filename "AzFwPowershellPacketCapture" -Flag "Syn","Ack" -Protocol "Any" -Filter $Filter1, $Filter2 -Operation "Start"
Start-Sleep -Seconds 120

# Invoke a firewall packet capture
$response = Invoke-AzFirewallPacketCapture -AzureFirewall $azureFirewall -Parameter $Params
Assert-NotNull $response
Assert-AreEqual "AzureFirewallPacketCaptureStartSucceeded" $response.StatusCode
Assert-AreEqual "Packet Capture Started" $response.Message

$Params = New-AzFirewallPacketCaptureParameter -Operation "Status"
$response = Invoke-AzFirewallPacketCapture -AzureFirewall $azureFirewall -Parameter $Params
Assert-NotNull $response
Assert-AreEqual "Microsoft.Azure.Management.Network.Models.AzureFirewallsPacketCaptureHeaders" $response.GetType().fullname
Assert-AreEqual "AzureFirewallPacketCaptureInProgress" $response.StatusCode
Assert-AreEqual "Packet capture in progress. Please wait till it is finished or stop the current capture before starting another." $response.Message

$Params = New-AzFirewallPacketCaptureParameter -Operation "Stop"
$response = Invoke-AzFirewallPacketCapture -AzureFirewall $azureFirewall -Parameter $Params
Assert-NotNull $response
Assert-AreEqual "AzureFirewallPacketCaptureStopSucceeded" $response.StatusCode
Assert-AreEqual "Packet capture stopped successfully. Ready to start a new packet capture." $response.Message

}
finally {
# Cleanup
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

namespace Microsoft.Azure.Commands.Network
{
[Cmdlet("Invoke", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "FirewallPacketCapture", SupportsShouldProcess = true), OutputType(typeof(PSAzureFirewallPacketCaptureParameters))]
[Cmdlet("Invoke", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "FirewallPacketCapture", SupportsShouldProcess = true), OutputType(typeof(PSAzureFirewallPacketCaptureResponse))]
public class InvokeAzureFirewallPacketCaptureCommand : AzureFirewallBaseCmdlet
{
[Parameter(
Expand Down Expand Up @@ -58,9 +58,15 @@ public override void Execute()


// Execute the PUT AzureFirewall call
var headers = this.AzureFirewallClient.PacketCapture(this.AzureFirewall.ResourceGroupName, this.AzureFirewall.Name, secureGwParamsModel);
var azureFirewallPacketCaptureResponse = this.AzureFirewallClient.PacketCaptureOperation(this.AzureFirewall.ResourceGroupName, this.AzureFirewall.Name, secureGwParamsModel);

WriteObject(headers);
var resp = new PSAzureFirewallPacketCaptureResponse();
if (azureFirewallPacketCaptureResponse != null)
{
resp = NetworkResourceManagerProfile.Mapper.Map<PSAzureFirewallPacketCaptureResponse>(azureFirewallPacketCaptureResponse);
}

WriteObject(resp);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,25 @@ namespace Microsoft.Azure.Commands.Network.AzureFirewall.PacketCapture
public class NewAzureFirewallPacketCaptureParametersCommand : NetworkBaseCmdlet
{
[Parameter(
Mandatory = true,
Mandatory = false,
HelpMessage = "The intended durations of packet capture in seconds")]
[ValidateRange(30,1800)]
public uint DurationInSeconds { get; set; }
[ValidateRange(30, 1800)]
public uint? DurationInSeconds { get; set; } = 60;

[Parameter(
Mandatory = true,
Mandatory = false,
HelpMessage = "The intended number of packets to capture")]
[ValidateRange(100,90000)]
public uint NumberOfPacketsToCapture { get; set; }
[ValidateRange(100, 90000)]
public uint? NumberOfPacketsToCapture { get; set; } = 1000;

[Parameter(
Mandatory = true,
Mandatory = false,
HelpMessage = "Upload capture storage container SASURL with write and delete permissions")]
[ValidateNotNullOrEmpty]
public virtual string SasUrl { get; set; }

[Parameter(
Mandatory = true,
Mandatory = false,
HelpMessage = "Name of packet capture file")]
[ValidateNotNullOrEmpty]
public virtual string FileName { get; set; }
Expand All @@ -54,11 +54,21 @@ public class NewAzureFirewallPacketCaptureParametersCommand : NetworkBaseCmdlet
public string[] Flag { get; set; }

[Parameter(
Mandatory = true,
Mandatory = false,
HelpMessage = "The list of filters to capture")]
[ValidateNotNullOrEmpty]
public PSAzureFirewallPacketCaptureRule[] Filter { get; set; }

[Parameter(
Mandatory = true,
HelpMessage = "The packet capture operation to run")]
[ValidateSet(
MNM.AzureFirewallPacketCaptureOperationType.Start,
MNM.AzureFirewallPacketCaptureOperationType.Status,
MNM.AzureFirewallPacketCaptureOperationType.Stop,
IgnoreCase = false)]
public string Operation { get; set; }

public override void Execute()
{
base.Execute();
Expand All @@ -71,20 +81,20 @@ public override void Execute()
{
PSFlags.Add(PSAzureFirewallPacketCaptureFlags.MapUserInputToPacketCaptureFlag(flag));
}
}
}
PSAzureFirewallPacketCaptureParameters packetCaptureParameters;

var packetCaptureParameters = new PSAzureFirewallPacketCaptureParameters
packetCaptureParameters = new PSAzureFirewallPacketCaptureParameters
{
DurationInSeconds = this.DurationInSeconds,
NumberOfPacketsToCapture = this.NumberOfPacketsToCapture,
DurationInSeconds = (uint)this.DurationInSeconds,
NumberOfPacketsToCapture = (uint)this.NumberOfPacketsToCapture,
SasUrl = this.SasUrl,
FileName = this.FileName,
Protocol = this.Protocol,
Flags = PSFlags,
Filters = this.Filter?.ToList(),

Operation = this.Operation,
};

WriteObject(packetCaptureParameters);
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/Network/Network/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
--->

## Upcoming Release
* Updated cmdlet response object to 'PSAzureFirewallPacketCaptureResponse' to provide expected responses for Azure Firewall Packet Capture Operations. Updated corresponding cmdlets.
- `Invoke-AzFirewallPacketCapture`
* Updated cmdlet to add the mandatory property of 'Operation' and made all other properties not mandatory for Azure Firewall Packet Capture Parameters. Updated corresponding cmdlets.
- `New-AzFirewallPacketCaptureParameter`
* Onboarded Application Gateway WAF Exceptions cmdlet.
- `New-AzApplicationGatewayFirewallPolicyException`
* Added properties 'DedicatedBackendConnection', 'ValidateCertChainAndExpiry', 'ValidateSNI', and 'SniName' to Application Gateway Backend HTTP Settings, as well as support for them in the following cmdlets:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2000,6 +2000,7 @@ private static void Initialize()
cfg.CreateMap<CNM.PSAzureFirewallPacketCaptureRule, MNM.AzureFirewallPacketCaptureRule>();
cfg.CreateMap<CNM.PSAzureFirewallPacketCaptureParameters, MNM.FirewallPacketCaptureParameters>();
cfg.CreateMap<CNM.PSAzureFirewallAutoscaleConfiguration, MNM.AzureFirewallAutoscaleConfiguration>();
cfg.CreateMap<CNM.PSAzureFirewallPacketCaptureResponse, MNM.AzureFirewallPacketCaptureResponse>();

// MNM to CNM
cfg.CreateMap<MNM.AzureFirewall, CNM.PSAzureFirewall>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ public class PSAzureFirewallPacketCaptureParameters

public List<PSAzureFirewallPacketCaptureRule> Filters { get; set; }

public string Operation { get; set; }

[JsonIgnore]
public string FlagsText
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Text;

namespace Microsoft.Azure.Commands.Network.Models
{
public class PSAzureFirewallPacketCaptureResponse
{
[JsonProperty(Order = 1)]
public string StatusCode { get; set; }

[JsonProperty(Order = 2)]
public string Message { get; set; }
}
}

2 changes: 1 addition & 1 deletion src/Network/Network/help/Az.Network.md
Original file line number Diff line number Diff line change
Expand Up @@ -871,7 +871,7 @@ This is an RM representation of customer branches that are uploaded to Azure for
Get IKE Security Associations of VPN Site Link Connections

### [Invoke-AzFirewallPacketCapture](Invoke-AzFirewallPacketCapture.md)
Invoke Packet Capture on Azure Firewall
Invoke Packet Capture Operation on Azure Firewall

### [Invoke-AzNetworkWatcherNetworkConfigurationDiagnostic](Invoke-AzNetworkWatcherNetworkConfigurationDiagnostic.md)
Invoke network configuration diagnostic session for specified network profiles on target resource.
Expand Down
73 changes: 52 additions & 21 deletions src/Network/Network/help/Invoke-AzFirewallPacketCapture.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ schema: 2.0.0
# Invoke-AzFirewallPacketCapture

## SYNOPSIS
Invoke Packet Capture on Azure Firewall
Invoke Packet Capture Operations on Azure Firewall

## SYNTAX

Expand All @@ -19,11 +19,11 @@ Invoke-AzFirewallPacketCapture -AzureFirewall <PSAzureFirewall>
```

## DESCRIPTION
Invokes a packet capture request on Azure Firewall
Invokes a Start/Status/Stop packet capture request on Azure Firewall

## EXAMPLES

### Example 1: Invokes a packet capture request on Azure Firewall
### Example 1: Invokes a start packet capture operation on Azure Firewall
```
$azureFirewall = New-AzFirewall -Name $azureFirewallName -ResourceGroupName $rgname -Location $location

Expand All @@ -32,15 +32,46 @@ $azFirewall = Get-AzFirewall -Name $azureFirewallName -ResourceGroupName $rgname
# Create a filter rules
$filter1 = New-AzFirewallPacketCaptureRule -Source "10.0.0.2","192.123.12.1" -Destination "172.32.1.2" -DestinationPort "80","443"
$filter2 = New-AzFirewallPacketCaptureRule -Source "10.0.0.5" -Destination "172.20.10.2" -DestinationPort "80","443"

# Create the firewall packet capture parameters
$Params = New-AzFirewallPacketCaptureParameter -DurationInSeconds 1200 -NumberOfPackets 20000 -SASUrl $sasurl -Filename "AzFwPowershellPacketCapture" -Flag "Syn","Ack" -Protocol "Any" -Filter $Filter1, $Filter2 -Operation "Start"

# Invoke a firewall packet capture
Invoke-AzFirewallPacketCapture -AzureFirewall $azureFirewall -Parameter $Params
```

This example invokes a start packet capture request on azure firewall with the parameters mentioned.

### Example 2: Invokes a check status packet capture operation on Azure Firewall
```
$azureFirewall = New-AzFirewall -Name $azureFirewallName -ResourceGroupName $rgname -Location $location

$azFirewall = Get-AzFirewall -Name $azureFirewallName -ResourceGroupName $rgname

# Create the firewall packet capture parameters
$Params = New-AzFirewallPacketCaptureParameter -Operation "Status"

# Invoke a firewall packet capture
Invoke-AzFirewallPacketCapture -AzureFirewall $azureFirewall -Parameter $Params
```

This example invokes a check status packet capture request on azure firewall with the parameters mentioned.

### Example 3: Invokes a stop packet capture operation on Azure Firewall
```
$azureFirewall = New-AzFirewall -Name $azureFirewallName -ResourceGroupName $rgname -Location $location

$azFirewall = Get-AzFirewall -Name $azureFirewallName -ResourceGroupName $rgname

# Create the firewall packet capture parameters
$Params = New-AzFirewallPacketCaptureParameter -DurationInSeconds 300 -NumberOfPacketsToCapture 5000 -SASUrl "ValidSasUrl" -Filename "AzFwPacketCapture" -Flag "Syn","Ack" -Protocol "Any" -Filter $Filter1, $Filter2
$Params = New-AzFirewallPacketCaptureParameter -Operation "Stop"

# Invoke a firewall packet capture
Invoke-AzFirewallPacketCapture -AzureFirewall $azureFirewall -Parameter $Params
```

This example invokes packet capture request on azure firewall with the parameters mentioned.
This example invokes a stop packet capture request on azure firewall with the parameters mentioned.


## PARAMETERS

Expand Down Expand Up @@ -74,6 +105,21 @@ Accept pipeline input: True (ByValue)
Accept wildcard characters: False
```

### -Confirm
Prompts you for confirmation before running the cmdlet.

```yaml
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases: cf

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -DefaultProfile
The credentials, account, tenant, and subscription used for communication with Azure.

Expand Down Expand Up @@ -104,21 +150,6 @@ Accept pipeline input: True (ByValue)
Accept wildcard characters: False
```

### -Confirm
Prompts you for confirmation before running the cmdlet.

```yaml
Type: System.Management.Automation.SwitchParameter
Parameter Sets: (All)
Aliases: cf

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -WhatIf
Shows what would happen if the cmdlet runs.
The cmdlet is not run.
Expand Down Expand Up @@ -146,7 +177,7 @@ This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable

## OUTPUTS

### Microsoft.Azure.Commands.Network.Models.PSAzureFirewallPacketCaptureParameters
### Microsoft.Azure.Commands.Network.Models.PSAzureFirewallPacketCaptureResponse

## NOTES

Expand Down
Loading
Loading