标注分类 - Amazon WAF、Amazon Firewall Manager 和 Amazon Shield Advanced
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

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

标注分类

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

注意

这些 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