本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
Label 匹配示例
本节提供标签匹配规则语句的匹配规范示例。
这些 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 ACLtestWebACL,在其中定义规则的。
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