最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

c# - Unable to add custom rule programmatically for Azure Front Door WAF policy - Stack Overflow

programmeradmin4浏览0评论

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);
发布评论

评论列表(0)

  1. 暂无评论