Hinweis
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, sich anzumelden oder das Verzeichnis zu wechseln.
Für den Zugriff auf diese Seite ist eine Autorisierung erforderlich. Sie können versuchen, das Verzeichnis zu wechseln.
Dieses Skript erleichtert den Übergang von einer WAF-Konfiguration oder einer benutzerdefinierten WAF-Richtlinie, die nur Regeln enthält, zu einer vollständigen WAF-Richtlinie. Möglicherweise wird im Portal eine Warnung angezeigt, die besagt, dass ein Upgrade zu einer WAF-Richtlinie erforderlich ist. Oder Sie möchten die neuen WAF-Funktionen nutzen, wie beispielsweise benutzerdefinierte Geomatch-Regeln, WAF-Richtlinien auf Standortebene, WAF-Richtlinien auf URI-Ebene oder den Regelsatz zur Bot-Abwehr. Um eines dieser Features verwenden zu können, benötigen Sie eine vollständige WAF-Richtlinie, die Ihrem Application Gateway zugeordnet ist.
Weitere Informationen zum Erstellen einer neuen WAF-Richtlinie finden Sie unter Erstellen von Web Application Firewall-Richtlinien für Application Gateway. Weitere Informationen zum Migrieren finden Sie unter Upgrade auf WAF-Richtlinie.
So führen Sie ein Upgrade auf eine WAF-Richtlinie mithilfe des Migrationsskripts durch
Führen Sie die folgenden Schritte aus, um das Migrationsskript auszuführen:
- Öffnen Sie das folgende Cloud Shell-Fenster, oder öffnen Sie ein Fenster im Portal.
- Kopieren Sie das Skript in das Cloud Shell-Fenster, und führen Sie es aus.
- Das Skript fragt nach der Abonnement-ID, dem Namen der Ressourcengruppe, dem Namen des Application Gateways, dem die WAF-Konfiguration zugeordnet ist, und dem Namen der neuen WAF-Richtlinie, die Sie erstellen. Nachdem Sie diese Eingaben eingegeben haben, wird das Skript ausgeführt und Ihre neue WAF-Richtlinie erstellt
- Stellen Sie sicher, dass die neue WAF-Richtlinie Ihrem Application Gateway zugeordnet ist. Wechseln Sie im Portal zur WAF-Richtlinie, und wählen Sie die Registerkarte Zugeordnete Application Gateways aus. Stellen Sie sicher, dass Application Gateway der WAF-Richtlinie zugeordnet ist.
Hinweis
Das Skript schließt eine Migration nicht ab, wenn die folgenden Bedingungen erfüllt sind:
- Ein gesamter Regelsatz ist deaktiviert. Um eine Migration abzuschließen, stellen Sie sicher, dass nicht die gesamte Regelgruppe deaktiviert ist.
Weitere Informationen finden Sie unter der ValidateInput-Funktion im Skript.
<#PSScriptInfo
.DESCRIPTION
Will be used to upgrade to the application-gateway to a top level waf policy experience.
.VERSION 1.0
.GUID b6fedd43-ebd0-41ed-9847-4f1c1c43be22
.AUTHOR Venkat.Krishnan
.PARAMETER subscriptionId
Subscription Id of where the resources are present.
.PARAMETER resourceGroupName
Resource-group where the resources are present.
.PARAMETER applicationGatewayName
Application-Gateway name
.PARAMETER wafPolicyName
Name of the web application firewall policy
.EXAMPLE
./migrateToWafPolicy.ps1 -subscriptionId <your-subscription-id> -applicationGatewayName <your-appgw-name> -resourceGroupName <your-resource-group-name> -wafPolicyName <new-waf-policy-name>
#>
param(
[Parameter(Mandatory=$true)]
[string] $subscriptionId,
[Parameter(Mandatory=$true)]
[string] $resourceGroupName,
[Parameter(Mandatory=$true)]
[string] $applicationGatewayName,
[Parameter(Mandatory=$true)]
[string] $wafPolicyName
)
function ValidateInput ($appgwName, $resourceGroupName) {
# Obtain the application-gateway
$appgw = Get-AzApplicationGateway -Name $applicationGatewayName -ResourceGroupName $resourceGroupName
if (-not $appgw) {
Write-Error "ApplicationGateway: $applicationGatewayName is not present in ResourceGroup: $resourceGroupName"
return $false
}
# Check if already have a global firewall policy
if ($appgw.FirewallPolicy) {
$fp = Get-AzResource -ResourceId $appgw.FirewallPolicy.Id
if ($fp.PolicySettings) {
Write-Error "ApplicationGateway: $applicationGatewayName already has a global firewall policy: $fp.Name. Please use portal for changing the policy."
return $false
}
}
if ($appgw.WebApplicationFirewallConfiguration) {
# Throw an error, since ruleGroup disabled case can't be migrated now.
if ($appgw.WebApplicationFirewallConfiguration.DisabledRuleGroups) {
foreach ($disabled in $appgw.WebApplicationFirewallConfiguration.DisabledRuleGroups) {
if ($disabled.Rules.Count -eq 0) {
$ruleGroupName = $disabled.RuleGroupName
Write-Error "The ruleGroup '$ruleGroupName' is disabled. Currently we can't upgrade to a firewall policy when an entire ruleGroup is disabled. This feature will be delivered shortly. To continue, kindly ensure the entire rulegroups are not disabled. "
return $false
}
}
}
}
if ($appgw.Sku.Name -ne "WAF_v2" -or $appgw.Sku.Tier -ne "WAF_v2") {
Write-Error " Cannot associate a firewall policy to application gateway :$applicationGatewayName since the Sku is not on WAF_v2"
return $false
}
return $true
}
function Login() {
$context = Get-AzContext
if ($null -eq $context -or $null -eq $context.Account) {
Login-AzAccount
}
}
function createNewTopLevelWafPolicy ($subscriptionId, $resourceGroupName, $applicationGatewayName, $wafPolicyName) {
Select-AzSubscription -Subscription $subscriptionId
$retVal = ValidateInput -appgwName $applicationGatewayName -resourceGroupName $resourceGroupName
if (!$retVal) {
return
}
$appgw = Get-AzApplicationGateway -Name $applicationGatewayName -ResourceGroupName $resourceGroupName
# Get the managedRule and PolicySettings
$managedRule = New-AzApplicationGatewayFirewallPolicyManagedRule
$policySetting = New-AzApplicationGatewayFirewallPolicySetting
if ($appgw.WebApplicationFirewallConfiguration) {
$ruleGroupOverrides = [System.Collections.ArrayList]@()
if ($appgw.WebApplicationFirewallConfiguration.DisabledRuleGroups) {
foreach ($disabled in $appgw.WebApplicationFirewallConfiguration.DisabledRuleGroups) {
$rules = [System.Collections.ArrayList]@()
if ($disabled.Rules.Count -gt 0) {
foreach ($rule in $disabled.Rules) {
$ruleOverride = New-AzApplicationGatewayFirewallPolicyManagedRuleOverride -RuleId $rule
$_ = $rules.Add($ruleOverride)
}
}
$ruleGroupOverride = New-AzApplicationGatewayFirewallPolicyManagedRuleGroupOverride -RuleGroupName $disabled.RuleGroupName -Rule $rules
$_ = $ruleGroupOverrides.Add($ruleGroupOverride)
}
}
$managedRuleSet = New-AzApplicationGatewayFirewallPolicyManagedRuleSet -RuleSetType $appgw.WebApplicationFirewallConfiguration.RuleSetType -RuleSetVersion $appgw.WebApplicationFirewallConfiguration.RuleSetVersion
if ($ruleGroupOverrides.Count -ne 0) {
$managedRuleSet = New-AzApplicationGatewayFirewallPolicyManagedRuleSet -RuleSetType $appgw.WebApplicationFirewallConfiguration.RuleSetType -RuleSetVersion $appgw.WebApplicationFirewallConfiguration.RuleSetVersion -RuleGroupOverride $ruleGroupOverrides
}
$exclusions = [System.Collections.ArrayList]@()
if ($appgw.WebApplicationFirewallConfiguration.Exclusions) {
foreach ($excl in $appgw.WebApplicationFirewallConfiguration.Exclusions) {
if ($excl.MatchVariable -and $excl.SelectorMatchOperator -and $excl.Selector) {
$exclusionEntry = New-AzApplicationGatewayFirewallPolicyExclusion -MatchVariable $excl.MatchVariable -SelectorMatchOperator $excl.SelectorMatchOperator -Selector $excl.Selector
$_ = $exclusions.Add($exclusionEntry)
}
if ($excl.MatchVariable -and !$excl.SelectorMatchOperator -and !$excl.Selecto) {
# Equals Any exclusion
$exclusionEntry = New-AzApplicationGatewayFirewallPolicyExclusion -MatchVariable $excl.MatchVariable -SelectorMatchOperator "EqualsAny" -Selector "*"
$_ = $exclusions.Add($exclusionEntry)
}
}
}
$managedRule = New-AzApplicationGatewayFirewallPolicyManagedRule -ManagedRuleSet $managedRuleSet
$exclCount = $exclusions.Count
if ($exclCount -ne 0) {
$managedRule = New-AzApplicationGatewayFirewallPolicyManagedRule -ManagedRuleSet $managedRuleSet -Exclusion $exclusions
}
$policySetting = New-AzApplicationGatewayFirewallPolicySetting -MaxFileUploadInMb $appgw.WebApplicationFirewallConfiguration.FileUploadLimitInMb -MaxRequestBodySizeInKb $appgw.WebApplicationFirewallConfiguration.MaxRequestBodySizeInKb -Mode Detection -State Disabled
if ($appgw.WebApplicationFirewallConfiguration.FirewallMode -eq "Prevention") {
$policySetting.Mode = "Prevention"
}
if ($appgw.WebApplicationFirewallConfiguration.Enabled) {
$policySetting.State = "Enabled"
}
$policySetting.RequestBodyCheck = $appgw.WebApplicationFirewallConfiguration.RequestBodyCheck;
}
if ($appgw.FirewallPolicy) {
$customRulePolicyId = $appgw.FirewallPolicy.Id
$rg = Get-AzResourceGroup -Name $resourceGroupName
$crPolicyName = $customRulePolicyId.Substring($customRulePolicyId.LastIndexOf("/") + 1)
$customRulePolicy = Get-AzApplicationGatewayFirewallPolicy -ResourceGroupName $rg.ResourceGroupName -Name $crPolicyName
$wafPolicy = New-AzApplicationGatewayFirewallPolicy -ResourceGroupName $rg.ResourceGroupName -Name $wafPolicyName -CustomRule $customRulePolicy.CustomRules -ManagedRule $managedRule -PolicySetting $policySetting -Location $appgw.Location
} else {
$wafPolicy = New-AzApplicationGatewayFirewallPolicy -Name $wafPolicyName -ResourceGroupName $resourceGroupName -PolicySetting $policySetting -ManagedRule $managedRule -Location $appgw.Location
}
if (!$wafPolicy) {
return
}
$appgw.WebApplicationFirewallConfiguration = $null
$appgw.FirewallPolicy = $wafPolicy
$appgw = Set-AzApplicationGateway -ApplicationGateway $appgw
Write-Host " firewallPolicy: $wafPolicyName has been created/updated successfully and applied to applicationGateway: $applicationGatewayName!"
return $wafPolicy
}
function Main() {
Login
$policy = createNewTopLevelWafPolicy -subscriptionId $subscriptionId -resourceGroupName $resourceGroupName -applicationGatewayName $applicationGatewayName -wafPolicyName $wafPolicyName
return $policy
}
Main
Nächste Schritte
Erfahren Sie mehr über CRS-Regelgruppen und -Regeln von Web Application Firewall.