使用Cloudformation创建多个规则的AWS WAF规则集

0

【以下的问题经过翻译处理】 我正在尝试使用Cloudformation配置AWS WAF WebACL。我已成功创建了一个包含在AWS :: WAFv2 :: WebACL规则语句中定义的单个规则的WebACL,但是一旦我尝试定义两个或多个规则,只有块中的最后一个规则会被创建。没有错误,但我只得到块中的最后一个规则。有没有人有一个部署多个规则的WebACL的示例?

所需的规则集是:

  1. 使用优先级0的IP拒绝规则和引用的IP集
  2. 使用优先级1的IP允许规则和引用的IP集
  3. 地理位置规则以限制为GB和允许

示例代码块:

“Rules”:[
            {
                “Name”:“IPSetDeny”,
                “Priority”:0,
                “Statement”:{
                    “IPSetReferenceStatement”:{“ARN”:{“Fn :: GetAtt”:[“SampleIPSetDeny”,“Arn”]}}
                },
                “Action”:{
                    “Block”:{}
                },
                “VisibilityConfig”:{
                    “SampledRequestsEnabled”:true,
                    “CloudWatchMetricsEnabled”:true,
                    “MetricName”:“aws-waf-logs-dev-inf”
                },
                “Name”:“IPSetAllow”,
                “Priority”:1,
                “Statement”:{
                    “IPSetReferenceStatement”:{“ARN”:{“Fn :: GetAtt”:[“SampleIPSetAllow”,“Arn”]}}
                },
                “Action”:{
                    “Allow”:{}
                },
                “VisibilityConfig”:{
                    “SampledRequestsEnabled”:true,
                    “CloudWatchMetricsEnabled”:true,
                    “MetricName”:“aws-waf-logs-dev-inf”
                },
                “Name”:“restrict-country”,
                “Priority”:2,
                “Statement”:{
                    “GeoMatchStatement”:{
                        “CountryCodes”:[
                          “GB”
                        ]
                    }
                },
                “Action”:{
profile picture
EXPERTE
gefragt vor 6 Monaten21 Aufrufe
1 Antwort
0

【以下的回答经过翻译处理】 你的描述仅描述了规则中的一个规则对象。尽管我们无法确定CloudFormation如何解释它,但最后一个块可能已经将其覆盖。

我认为你应该像下面这样在规则中编写多个规则数组。

"Rules": [
     {
         "Name": "IPSetDeny",
         "Priority": 0,
         "Statement": {
             "IPSetReferenceStatement": {
                 "ARN": {
                     "Fn::GetAtt": [
                         "SampleIPSetDeny",
                         "Arn"
                     ]
                 }
             }
         },
         "Action": {
             "Block": {}
         },
         "VisibilityConfig": {
             "SampledRequestsEnabled": true,
             "CloudWatchMetricsEnabled": true,
             "MetricName": "aws-waf-logs-dev-inf"
         }
     },
     {
         "Name": "IPSetAllow",
         "Priority": 1,
         "Statement": {
             "IPSetReferenceStatement": {
                 "ARN": {
                     "Fn::GetAtt": [
                         "SampleIPSetAllow",
                         "Arn"
                     ]
                 }
             }
         },
         "Action": {
             "Allow": {}
         },
         "VisibilityConfig": {
             "SampledRequestsEnabled": true,
             "CloudWatchMetricsEnabled": true,
             "MetricName": "aws-waf-logs-dev-inf"
         }
     },
     {
         "Name": "restrict-country",
         "Priority": 2,
         "Statement": {
             "GeoMatchStatement": {
                 "CountryCodes": [
                     "GB"
                 ]
             }
         },
         "Action": {
             "Allow": {}
         },
         "VisibilityConfig": {
             "SampledRequestsEnabled": true,
             "CloudWatchMetricsEnabled": true,
             "MetricName": "aws-waf-logs-dev-inf"
         }
     }
 ]
profile picture
EXPERTE
beantwortet vor 6 Monaten

Du bist nicht angemeldet. Anmelden um eine Antwort zu veröffentlichen.

Eine gute Antwort beantwortet die Frage klar, gibt konstruktives Feedback und fördert die berufliche Weiterentwicklung des Fragenstellers.

Richtlinien für die Beantwortung von Fragen