繁体   English   中英

创建地理匹配的AWS WAF条件/规则,然后使用CloudFormation将其连接到现有的CloudFront分配

[英]Create a geomatching AWS WAF condition/rule and connect it to an existing CloudFront distribution using CloudFormation

简而言之,我要完成的工作如下:

  • 我想创建WAF条件/规则组合以阻止不在国家白名单中的流量。
  • 我想使用CloudFormation,以便可以对其进行版本控制并轻松将其部署到不同的环境。
  • 我想将其与现有的CloudFront发行版关联(这在环境之间是不同的)。 理想情况下,无需重建CloudFront发行版。

这似乎足够简单,可以在Web控制台中进行设置,但是CloudFormation API似乎更受限制吗?

我能够WebACL部署“ WAFRegional” GeoMatchSetRuleWebACL 然后,当尝试将其与现有的CloudFront分布关联时,似乎我要使用的不是“ WAFRegional”类型,而只是“ WAF”类型。 但是,没有针对“ WAF”的GeoMatchSet API吗?

AWSTemplateFormatVersion: 2010-09-09
Resources:
  # Match Sets
  GeoMatchSetWhitelist:
    Type: "AWS::WAFRegional::GeoMatchSet"
    Properties:
      Name: "GeoMatchSet for whitelist countries"
      GeoMatchConstraints:
        -
          Type: "Country"
          Value: "CA"
        -
          Type: "Country"
          Value: "US"
  ByteMatchSetLoginURIs:
    Type: "AWS::WAFRegional::ByteMatchSet"
    Properties:
      Name: "ByteMatchSet for Login URIs"
      ByteMatchTuples:
        -
          FieldToMatch:
            Type: "URI"
          TargetString: "/my/uri"
          TextTransformation: "NONE"
          PositionalConstraint: "EXACTLY"

  # Rules
  WhitelistRule:
    Type: "AWS::WAFRegional::Rule"
    Properties:
      Name: "WhitelistRule"
      MetricName: "WhitelistRule"
      Predicates:
        -
          DataId:
            Ref: "GeoMatchSetWhitelist"
          # True here means match everying NOT in this match set
          Negated: true
          Type: "GeoMatch"
        -
          DataId:
            Ref: "ByteMatchSetLoginURIs"
          Negated: false
          Type: "ByteMatch"

  # Web Access Control Lists
  WebACL:
    Type: "AWS::WAFRegional::WebACL"
    Properties:
      Name: "WhitelistWebACL"
      DefaultAction:
        Type: "ALLOW"
      MetricName: "WebACL"
      Rules:
        -
          Action:
            Type: "BLOCK"
          Priority: 2
          RuleId:
            Ref: "WhitelistRule"

  # Web ACL Association
  WebACLAssociation:
    Type: "AWS::WAF::WebACLAssociation"
    Properties:
      ResourceArn:
        Ref: "arn:aws:cloudfront::999999999999:distribution/AAAAAAAAAAAA"
      WebACLId:
        Ref: "WebACL"

运行上面的代码给我An error occurred (ValidationError) when calling the CreateChangeSet operation: Template format error: Unresolved resource dependencies [arn:aws:cloudfront::999999999999:distribution/AAAAAAAAAAAA] in the Resources block of the template

最后,是否可以将GeoMatchSetGeoMatchSetByteMatchSet和现有的CloudFront发行版一起使用?

上次检查时,对于区域区域存在对GeoMatchSet的CloudFormation支持,但对于全局区域(CloudFront)不存在。 不幸的是,CloudFormation以功能丰富的功能而闻名,尽管它逐渐变得越来越好...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM