AWS WAF 标签匹配示例 - AWS WAFAWS Firewall Manager、和 AWS Shield Advanced

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

AWS WAF 标签匹配示例

本节提供标签匹配规则语句的匹配规范示例。

注意

这些 JSON 列表是在控制台中创建的,方法是向 Web ACL 添加一条带有标签匹配规范的规则,然后编辑规则并切换到规则 JSON 编辑器。您还可以通过 API 或命令行界面获取规则组或 Web ACL 的 JSON。

与本地标签匹配

以下 JSON 列表显示了与本规则上下文相同的标签匹配语句,该标签添加了到本地 Web 请求中。

Rule: { Name: "match_rule", Statement: { LabelMatchStatement: { Scope: "LABEL", Key: "header:encoding:utf8" } }, RuleLabels: [ ...generate_more_labels... ], Action: { Block: {} } }

如果您在账户 111122223333 中使用此匹配语句,则在为 Web ACL testWebACL 定义的规则中,它将匹配以下标签。

awswaf:111122223333:webacl:testWebACL:header:encoding:utf8
awswaf:111122223333:webacl:testWebACL:testNS1:testNS2:header:encoding:utf8

它与以下标签不匹配,因为标签字符串不完全匹配。

awswaf:111122223333:webacl:testWebACL:header:encoding2:utf8

它与以下标签不匹配,因为上下文不一样,因此前缀不匹配。即使您将规则组 productionRules 添加到定义规则的 Web ACL testWebACL 中,也是如此。

awswaf:111122223333:rulegroup:productionRules:header:encoding:utf8

与来自其他上下文的标签进行匹配

以下 JSON 列表显示了一条标签匹配规则,该规则与用户创建的规则组内规则的标签相匹配。对于 Web ACL 中运行的所有规则(不属于已命名规则组),规范中都要求使用前缀。此示例标签规范仅匹配确切的标签。

Rule: { Name: "match_rule", Statement: { LabelMatchStatement: { Scope: "LABEL", Key: "awswaf:111122223333:rulegroup:testRules:header:encoding:utf8" } }, RuleLabels: [ ...generate_more_labels... ], Action: { Block: {} } }

与托管规则组标签匹配

这是一种特殊情况,即与来自另一种上下文的标签进行匹配,而不是与匹配规则的上下文进行匹配。以下 JSON 列表显示了托管规则组标签的标签匹配语句。这仅匹配标签匹配语句的键设置中指定的确切标签。

Rule: { Name: "match_rule", Statement: { LabelMatchStatement: { Scope: "LABEL", Key: "awswaf:managed:aws:managed-rule-set:header:encoding:utf8" } }, RuleLabels: [ ...generate_more_labels... ], Action: { Block: {} } }

与本地命名空间匹配

以下 JSON 列表显示了本地命名空间的标签匹配语句。

Rule: { Name: "match_rule", Statement: { LabelMatchStatement: { Scope: "NAMESPACE", Key: "header:encoding:" } }, Labels: [ ...generate_more_labels... ], Action: { Block: {} } }

与本地 Label 匹配类似,如果您在账户 111122223333 中使用此语句,在为 Web ACL testWebACL 定义的规则中,它将匹配以下标签。

awswaf:111122223333:webacl:testWebACL:header:encoding:utf8

它与以下标签不匹配,因为账户不一样,因此前缀不匹配。

awswaf:444455556666:webacl:testWebACL:header:encoding:utf8

该前缀也与托管规则组应用的任何标签都不匹配,如下所示。

awswaf:managed:aws:managed-rule-set:header:encoding:utf8

与托管规则组命名空间匹配

以下 JSON 列表显示了托管规则组命名空间的标签匹配语句。对于您拥有的规则组,您还需要提供前缀,以便匹配规则上下文之外的命名空间。

Rule: { Name: "match_rule", Statement: { LabelMatchStatement: { Scope: "NAMESPACE", Key: "awswaf:managed:aws:managed-rule-set:header:" } }, RuleLabels: [ ...generate_more_labels... ], Action: { Block: {} } }

此规范与以下示例标签相匹配。

awswaf:managed:aws:managed-rule-set:header:encoding:utf8
awswaf:managed:aws:managed-rule-set:header:encoding:unicode

它与以下标签不匹配。

awswaf:managed:aws:managed-rule-set:query:badstring