Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,12 @@ public void TestPolicyCrudWithPiping()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-PolicyCrudWithPiping");
}

[Fact]
[Trait(Category.AcceptanceType, Category.CheckIn)]
public void TestManagedRuleSetDefinitions()
{
TestController.NewInstance.RunPowerShellTest(_logger, "Test-ManagedRuleSetDefinition");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,29 @@ function Test-PolicyCrudWithPiping
$removed = Get-AzFrontDoorWafPolicy -Name $Name -ResourceGroupName $resourceGroupName | Remove-AzFrontDoorWafPolicy -PassThru
Assert-True { $removed }
Assert-ThrowsContains { Get-AzFrontDoorWafPolicy -Name $Name -ResourceGroupName $resourceGroupName } "does not exist."
}
}

<#
.SYNOPSIS
WAF managed rule set definitions retrieval
#>
function Test-ManagedRuleSetDefinition
{
$definitions = Get-AzFrontDoorWafManagedRuleSetDefinition
Assert-AreEqual $definitions.Count 4
Assert-AreEqual $definitions[0].RuleSetType "DefaultRuleSet"
Assert-AreEqual $definitions[0].RuleSetVersion "1.0"
Assert-AreEqual $definitions[0].RuleGroups.Count 9

Assert-AreEqual $definitions[1].RuleSetType "Microsoft_BotManagerRuleSet"
Assert-AreEqual $definitions[1].RuleSetVersion "1.0"
Assert-AreEqual $definitions[1].RuleGroups.Count 3

Assert-AreEqual $definitions[2].RuleSetType "DefaultRuleSet"
Assert-AreEqual $definitions[2].RuleSetVersion "preview-0.1"
Assert-AreEqual $definitions[2].RuleGroups.Count 8

Assert-AreEqual $definitions[3].RuleSetType "BotProtection"
Assert-AreEqual $definitions[3].RuleSetVersion "preview-0.1"
Assert-AreEqual $definitions[3].RuleGroups.Count 1
}

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/FrontDoor/FrontDoor/Az.FrontDoor.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ CmdletsToExport = 'New-AzFrontDoor', 'Get-AzFrontDoor', 'Set-AzFrontDoor',
'New-AzFrontDoorWafCustomRuleObject',
'New-AzFrontDoorWafManagedRuleObject', 'New-AzFrontDoorWafPolicy',
'Get-AzFrontDoorWafPolicy', 'Update-AzFrontDoorWafPolicy',
'Get-AzFrontDoorWafManagedRuleSetDefinition',
'Remove-AzFrontDoorWafPolicy',
'New-AzFrontDoorWafRuleGroupOverrideObject',
'Remove-AzFrontDoorContent', 'Enable-AzFrontDoorCustomDomainHttps',
Expand Down
1 change: 1 addition & 0 deletions src/FrontDoor/FrontDoor/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
- Additional information about change #1
-->
## Upcoming Release
* Add cmdlet to get managed rule definitions that can be used in WAF

## Version 1.3.0
* Update references in .psd1 to use relative path
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// ----------------------------------------------------------------------------------
//
// 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.FrontDoor.Common;
using Microsoft.Azure.Commands.FrontDoor.Helpers;
using Microsoft.Azure.Commands.FrontDoor.Models;
using Microsoft.Azure.Management.FrontDoor.Models;
using Microsoft.Rest.Azure;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;

namespace Microsoft.Azure.Commands.FrontDoor.Cmdlets
{
/// <summary>
/// Defines the Get-AzFrontDoorWafManagedRuleSetDefinition cmdlet.
/// </summary>
[Cmdlet("Get", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "FrontDoorWafManagedRuleSetDefinition"), OutputType(typeof(PSManagedRuleSetDefinition))]
public class GetAzureRmFrontDoorWafManagedRuleSetDefinition : AzureFrontDoorCmdletBase
{
public override void ExecuteCmdlet()
{
AzureOperationResponse<IPage<ManagedRuleSetDefinition>> managedSets = FrontDoorManagementClient.ManagedRuleSets.ListWithHttpMessagesAsync().GetAwaiter().GetResult();
List<PSManagedRuleSetDefinition> managedRuleSetDefinitions = managedSets.Body?.Select(managedRuleSetDefinition => managedRuleSetDefinition.ToPSManagedRuleSetDefinition()).ToList();
string nextLink = managedSets.Body.NextPageLink;
while (nextLink != null)
{
var nextLinkSets = FrontDoorManagementClient.ManagedRuleSets.ListNextWithHttpMessagesAsync(nextLink).GetAwaiter().GetResult();
managedRuleSetDefinitions.AddRange(nextLinkSets.Body?.Select(managedRuleSetDefinition => managedRuleSetDefinition.ToPSManagedRuleSetDefinition()));
nextLink = nextLinkSets.Body.NextPageLink;
}

WriteObject(managedRuleSetDefinitions.ToArray(), true);
}
}
}
35 changes: 35 additions & 0 deletions src/FrontDoor/FrontDoor/Helpers/ModelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@
using SdkHttpsConfig = Microsoft.Azure.Management.FrontDoor.Models.CustomHttpsConfiguration;
using SdkLoadBalancingSetting = Microsoft.Azure.Management.FrontDoor.Models.LoadBalancingSettingsModel;
using SdkManagedRule = Microsoft.Azure.Management.FrontDoor.Models.ManagedRuleSet;
using SdkManagedRuleDefinition = Microsoft.Azure.Management.FrontDoor.Models.ManagedRuleDefinition;
using SdkManagedRuleGroupDefinition = Microsoft.Azure.Management.FrontDoor.Models.ManagedRuleGroupDefinition;
using SdkManagedRuleList = Microsoft.Azure.Management.FrontDoor.Models.ManagedRuleSetList;
using SdkManagedRuleSetDefinition = Microsoft.Azure.Management.FrontDoor.Models.ManagedRuleSetDefinition;
using sdkMatchCondition = Microsoft.Azure.Management.FrontDoor.Models.MatchCondition;
using sdkPolicySetting = Microsoft.Azure.Management.FrontDoor.Models.PolicySettings;
using SdkRedirectConfiguration = Microsoft.Azure.Management.FrontDoor.Models.RedirectConfiguration;
Expand Down Expand Up @@ -431,6 +434,38 @@ public static PSPolicy ToPSPolicy(this SdkFirewallPolicy sdkPolicy)
};
}

public static PSManagedRuleSetDefinition ToPSManagedRuleSetDefinition(this SdkManagedRuleSetDefinition sdkManagedRuleSetDefinition)
{
return new PSManagedRuleSetDefinition
{
ProvisioningState = sdkManagedRuleSetDefinition.ProvisioningState,
RuleSetType = sdkManagedRuleSetDefinition.RuleSetType,
RuleSetVersion = sdkManagedRuleSetDefinition.RuleSetVersion,
RuleGroups = sdkManagedRuleSetDefinition.RuleGroups?.Select(ruleGroup => ruleGroup.ToPSManagedRuleGroupDefinition()).ToList()
};
}

public static PSManagedRuleGroupDefinition ToPSManagedRuleGroupDefinition(this SdkManagedRuleGroupDefinition sdkManagedRuleGroupDefinition)
{
return new PSManagedRuleGroupDefinition
{
RuleGroupName = sdkManagedRuleGroupDefinition.RuleGroupName,
Description = sdkManagedRuleGroupDefinition.Description,
Rules = sdkManagedRuleGroupDefinition.Rules?.Select(rule => rule.ToPSManagedRuleDefinition()).ToList()
};
}

public static PSManagedRuleDefinition ToPSManagedRuleDefinition(this SdkManagedRuleDefinition sdkManagedRuleDefinition)
{
return new PSManagedRuleDefinition
{
RuleId = sdkManagedRuleDefinition.RuleId,
DefaultAction = sdkManagedRuleDefinition.DefaultAction,
DefaultState = sdkManagedRuleDefinition.DefaultState,
Description = sdkManagedRuleDefinition.Description
};
}

public static PSMatchCondition ToPSMatchCondition(this sdkMatchCondition sdkMatchCondition)
{
return new PSMatchCondition
Expand Down
29 changes: 29 additions & 0 deletions src/FrontDoor/FrontDoor/Models/PSManagedRuleDefinition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// ----------------------------------------------------------------------------------
//
// 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 System.Collections.Generic;

namespace Microsoft.Azure.Commands.FrontDoor.Models
{
public class PSManagedRuleDefinition
{
public string RuleId { get; set; }

public string DefaultState { get; set; }

public string DefaultAction { get; set; }

public string Description { get; set; }
}
}
27 changes: 27 additions & 0 deletions src/FrontDoor/FrontDoor/Models/PSManagedRuleGroupDefinition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// ----------------------------------------------------------------------------------
//
// 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 System.Collections.Generic;

namespace Microsoft.Azure.Commands.FrontDoor.Models
{
public class PSManagedRuleGroupDefinition
{
public string RuleGroupName { get; set; }

public string Description { get; set; }

public IList<PSManagedRuleDefinition> Rules { get; set; }
}
}
29 changes: 29 additions & 0 deletions src/FrontDoor/FrontDoor/Models/PSManagedRuleSetDefinition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// ----------------------------------------------------------------------------------
//
// 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 System.Collections.Generic;

namespace Microsoft.Azure.Commands.FrontDoor.Models
{
public class PSManagedRuleSetDefinition
{
public string ProvisioningState { get; set; }

public string RuleSetType { get; set; }

public string RuleSetVersion { get; set; }

public IList<PSManagedRuleGroupDefinition> RuleGroups { get; set; }
}
}
3 changes: 3 additions & 0 deletions src/FrontDoor/FrontDoor/help/Az.FrontDoor.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ Get Front Door load balancer
### [Get-AzFrontDoorFrontendEndpoint](Get-AzFrontDoorFrontendEndpoint.md)
Get a front door frontend endpoint.

### [Get-AzFrontDoorWafManagedRuleSetDefinition](Get-AzFrontDoorWafManagedRuleSetDefinition.md)
Get WAF managed rule set definitions

### [Get-AzFrontDoorWafPolicy](Get-AzFrontDoorWafPolicy.md)
Get WAF policy

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
---
external help file: Microsoft.Azure.PowerShell.Cmdlets.FrontDoor.dll-Help.xml
Module Name: Az.FrontDoor
online version: https://docs.microsoft.com/en-us/powershell/module/az.frontdoor/get-azfrontdoorwafmanagedrulesetdefinition
schema: 2.0.0
---

# Get-AzFrontDoorWafManagedRuleSetDefinition

## SYNOPSIS
Get WAF managed rule set definitions

## SYNTAX

```
Get-AzFrontDoorWafManagedRuleSetDefinition [-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
```

## DESCRIPTION
Gets the list of WAF managed rule set definitions to use as reference

## EXAMPLES

### Example 1
```powershell
PS C:> Get-AzFrontDoorWafManagedRuleSetDefinition

ProvisioningState RuleSetType RuleSetVersion RuleGroups
----------------- ----------- -------------- ----------
Succeeded DefaultRuleSet 1.0 {PROTOCOL-ATTACK, LFI, RFI, RCE...}
Succeeded Microsoft_BotManagerRuleSet 1.0 {BadBots, GoodBots, UnknownBots}
Succeeded DefaultRuleSet preview-0.1 {LFI, RFI, RCE, PHP...}
Succeeded BotProtection preview-0.1 {KnownBadBots}
```

{{ Add example description here }}

## PARAMETERS

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

```yaml
Type: Microsoft.Azure.Commands.Common.Authentication.Abstractions.Core.IAzureContextContainer
Parameter Sets: (All)
Aliases: AzContext, AzureRmContext, AzureCredential

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

### CommonParameters
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).

## INPUTS

### None

## OUTPUTS

### Microsoft.Azure.Commands.FrontDoor.Models.PSManagedRuleSetDefinition

## NOTES

## RELATED LINKS

[New-AzFrontDoorWafManagedRuleObject](./New-AzFrontDoorWafManagedRuleObject.md)
[New-AzFrontDoorWafManagedRuleOverrideObject](./New-AzFrontDoorWafManagedRuleOverrideObject.md)
[New-AzFrontDoorWafRuleGroupOverrideObject](./New-AzFrontDoorWafRuleGroupOverrideObject.md)