I am using following code add the custom rule. I am getting success message. But, custom rule is not being added to the policy. Please let me know if I miss something.
I see that there is no documentation for adding custom rules for the WAF policy. It would be great if it is added.
Thanks in advance.
// Authenticate using ClientSecretCredential
var credential = new ClientSecretCredential(_configuration["AzureAd:TenantId"], _configuration["WAFPolicy:ClientId"], _configuration["WAFPolicy:ClientSecret"]);
var client = new ArmClient(credential);
// Get the subscription resource
var subscription = client.GetSubscriptionResource(new ResourceIdentifier($"/subscriptions/{_configuration["WAFPolicy:SubscriptionId"]}"));
// Get the resource group
var resourceGroup = await subscription.GetResourceGroups().GetAsync(_configuration["WAFPolicy:ResourceGroupName"]);
_wafPolicyResource = await resourceGroup.Value.GetFrontDoorWebApplicationFirewallPolicies().GetAsync(_configuration["WAFPolicy:Name"]);
var ruleMatchCondition = new WebApplicationRuleMatchCondition
(
WebApplicationRuleMatchVariable.RemoteAddr,
WebApplicationRuleMatchOperator.Contains,
firewallRule.Values
);
var customRule = new WebApplicationCustomRule(
firewallRule.Priority,
WebApplicationRuleType.MatchRule,
new[] { ruleMatchCondition },
RuleMatchActionType.Allow
)
{
Name = "Test"
};
_wafPolicyResource.Data.Rules.Add(customRule);
FrontDoorWebApplicationFirewallPolicyPatch patch = new FrontDoorWebApplicationFirewallPolicyPatch
{
Tags =
{
["key1"] = "value1",
["key2"] = "value2"
}
};
ArmOperation<FrontDoorWebApplicationFirewallPolicyResource> lro = await _wafPolicyResource.UpdateAsync(Azure.WaitUntil.Completed, patch);