Share via


設定 Web 應用程式防火牆 的 Bot 保護

適用於 Front Door 的 Azure WAF Web 應用程式防火牆 (WAF) 提供 Bot 規則來識別良好的 Bot,並防範不良的 Bot。 如需 Bot 保護規則集的詳細資訊,請參閱 Bot 保護規則集

本文說明如何在 Azure Front Door 進階層上啟用 Bot 保護規則。

必要條件

遵循使用 Azure 入口網站建立 Azure Front Door 的 WAF 原則中所述的指示,建立 Front Door 的基本 WAF 原則。

啟用 Bot 保護規則集

  1. 在 Azure 入口網站中,瀏覽至 WAF 原則。

  2. 選取 [受控規則],然後選取 [指派]

    Screenshot of the Azure portal showing the WAF policy's managed rules configuration, and the Assign button highlighted.

  3. 在 [其他規則集] 下拉式清單中,選取您想要使用的 Bot 保護規則集版本。 使用最新版的規則集通常是很好的作法。

    Screenshot of the Azure portal showing the managed rules assignment page, with the 'Additional rule set' drop-down field highlighted.

  4. 選取 [儲存]。

取得 WAF 原則的目前設定

使用 Get-AzFrontDoorWafPolicy Cmdlet 來擷取 WAF 原則的目前設定。 請確定您針對您自己的環境使用正確的資源群組名稱和 WAF 原則名稱。

$frontDoorWafPolicy = Get-AzFrontDoorWafPolicy `
  -ResourceGroupName 'FrontDoorWafPolicy' `
  -Name 'WafPolicy'

新增 Bot 保護規則集

使用 New-AzFrontDoorWafManagedRuleObject Cmdlet 來選取 Bot 保護規則集,包括規則集的版本。 然後,將規則集新增至 WAF 的設定。

下列範例會將 Bot 保護規則集 1.0 版新增至 WAF 的設定。

$botProtectionRuleSet = New-AzFrontDoorWafManagedRuleObject `
  -Type 'Microsoft_BotManagerRuleSet' `
  -Version '1.0'

$frontDoorWafPolicy.ManagedRules.Add($botProtectionRuleSet)

套用設定

使用 Update-AzFrontDoorWafPolicy Cmdlet 來更新 WAF 原則,以包括您先前建立的設定。

$frontDoorWafPolicy | Update-AzFrontDoorWafPolicy

啟用 Bot 保護規則集

使用 az network front-door waf-policy managed-rules add 命令來更新 WAF 原則以新增 Bot 保護規則集。

下列範例會將 Bot 保護規則的 1.0 版新增至 WAF。 請確定您針對您自己的環境使用正確的資源群組名稱和 WAF 原則名稱。

az network front-door waf-policy managed-rules add \
  --resource-group FrontDoorWafPolicy \
  --policy-name WafPolicy \
  --type Microsoft_BotManagerRuleSet \
  --version 1.0

下列範例 Bicep 檔案會示範如何執行下列步驟:

  • 建立 Front Door WAF 原則。
  • 啟用 Bot 保護規則集 1.0 版。
param wafPolicyName string = 'WafPolicy'

@description('The mode that the WAF should be deployed using. In "Prevention" mode, the WAF will block requests it detects as malicious. In "Detection" mode, the WAF will not block requests and will simply log the request.')
@allowed([
  'Detection'
  'Prevention'
])
param wafMode string = 'Prevention'

resource wafPolicy 'Microsoft.Network/frontDoorWebApplicationFirewallPolicies@2022-05-01' = {
  name: wafPolicyName
  location: 'Global'
  sku: {
    name: 'Premium_AzureFrontDoor'
  }
  properties: {
    policySettings: {
      enabledState: 'Enabled'
      mode: wafMode
    }
    managedRules: {
      managedRuleSets: [
        {
          ruleSetType: 'Microsoft_BotManagerRuleSet'
          ruleSetVersion: '1.0'
        }
      ]
    }
  }
}

下一步