【问题标题】:How to allow certain IP set resource with my WAF v2 via cloudformation?如何通过 cloudformation 使用我的 WAF v2 允许某些 IP 集资源?
【发布时间】:2021-11-10 03:36:35
【问题描述】:

为此问题设计的示例,基于 aws 文档,我使用 WAF 定义了 WAFv2 资源类型、规则和 IP 集列表。以下工作,它阻止了我指定的 IP,但是如何允许某些 IP 列表并阻止所有其他 IP?

Resources:
  
  WebAcl:
    Type: AWS::WAFv2::WebACL
    Properties:
      Name: sample-acl
      Scope: REGIONAL
      Description: sample ACL.
      DefaultAction:
        Allow: {}
      VisibilityConfig:
        SampledRequestsEnabled: true
        CloudWatchMetricsEnabled: true
        MetricName: sample-acl
      Rules:
      - Name: blockIPList
        Priority: 4
        Action:
          Block: {}
        VisibilityConfig:
          SampledRequestsEnabled: true
          CloudWatchMetricsEnabled: true
          MetricName: IPListMetric
        Statement:
          IPSetReferenceStatement:
            Arn: !GetAtt myIPSet.Arn
 myIPSet:
    Type: 'AWS::WAFv2::IPSet'
    Properties:
      Name: sampleIPlistIPv4
      Scope: REGIONAL
      IPAddressVersion: IPV4
      Addresses:
        - 70.25.14.172/32

  

【问题讨论】:

  • 你能提供你关注的文档的链接吗?此外,您想要做什么也不是很清楚。你能详细说明一下吗?
  • @Marcin - 谢谢。我想通过 WAF 阻止/允许 IP 列表。我按照 WAF v2 上的 aws 文档创建了一个 WAF 资源,现在我想定义一个规则来阻止/允许 IP 列表。

标签: amazon-cloudformation amazon-waf


【解决方案1】:

在 CloudFront 分配上启用它

CloudFront:
Type: AWS::CloudFront::Distribution
Properties:
  DistributionConfig:
    WebACLId: !GetAtt ExampleWebACL.Arn

或者对于 ALB 或 API 网关,您可以使用 https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-resource-wafv2-webaclassociation.html

Type: AWS::WAFv2::WebACLAssociation
Properties: 
  ResourceArn: String
  WebACLArn: String

编辑: 您的意思是如何在您的规则组中启用 IPSet?

RuleGroup:
Type: 'AWS::WAFv2::RuleGroup'
Properties:
  Name: SampleRuleGroup
  Scope: REGIONAL
  Description: SampleRuleGroup
  VisibilityConfig:
    SampledRequestsEnabled: true
    CloudWatchMetricsEnabled: true
    MetricName: SampleRuleGroupMetrics
  Rules:
    - Name: ip-whitelist
      Priority: 0
      Action:
        Allow: { }
      VisibilityConfig:
        SampledRequestsEnabled: true
        CloudWatchMetricsEnabled: true
        MetricName: ip-whitelist-metric
      Statement:
        IPSetReferenceStatement:
          Arn: !GetAtt SampleIPSet.Arn

【讨论】:

  • 谢谢。是否有使用 waf 阻止 sql 注入或 xss 攻击的标准模板,类似于我们用于阻止 IP 集的模板?如果您知道示例,请告诉我
  • 是的,AWS 为此提供了一些托管规则。您可以通过控制台下的 WebACL 规则找到它们,只需单击添加规则,然后单击“添加托管规则组”并查看 AWS 托管规则组。您可能可以在市场上找到更多规则组。在此处阅读更多信息docs.aws.amazon.com/waf/latest/developerguide/…
  • 我必须做的另一件事是 WAF -> 默认操作:阻止 {},然后根据允许 ip 集的单独规则,我设置操作:允许{} .我理解的方式是,默认情况下它将阻止所有请求,但只允许我将其置于允许规则下的请求。试图确保这是正确的方法。
  • 好吧,这一切都取决于您的用例,如果您只想允许 IPSet 中的几个特定 IP 并阻止其他所有内容,那么可以,您告诉 waf 默认阻止所有内容,然后告诉ipset 以允许来自您的 ip 的流量。
猜你喜欢
  • 1970-01-01
  • 2017-06-12
  • 2021-12-18
  • 2020-01-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多