首页信息安全带有CloudformationWAFRegional的SAMAPI网关

带有CloudformationWAFRegional的SAMAPI网关

admin 10-30 10:42 238次浏览

为了保护我们的API,我正在尝试使用RateBasedRule部署WAFRegional。API网关位于SAM模板中,其中我还有一个嵌套堆栈,用于存放WAFRegional配置的子模板。下面提供了WAFRegional配置的子模板。在ExecuteChangeSet阶段将发生以下情况:

    CamerasIpSet已创建

    创建了CamerasRateRule

    WAFCamerasWebACL CREATE_FAILED:引用的项目不存在。(服务:AWSWAFRegional;状态代码:400;错误代码:WAFNonexistentItemException

我发现大约2个月前的以下帖子,其中有人在使用Serverless时遇到相同的问题:https : //forum.serverless /t/dependon-api-gateway-deployment/7792

我在这里错过了什么?

AWSTemplateFormatVersion: '2010-09-09'
Description: 'Template for WAF Configuration'
Parameters:
  CamerasApi:
    Description: "Arn of the Cameras Api"
    Type: String
    Default: cameras-api-dev
  StageName:
    Description: "Stage name of the Cameras Api"
    Type: String
    Default: v
  Blocking:
    Description: "Number of calls per 5 minutes for WAF IP blocking."
    Type: Number
    Default: 2000
  EnvironmentType:
    Type: String
    Default: "dev"
    Description: "Type of environment: dev, staging or prod."


Resources:
  WAFCamerasWebACL:
    Type: AWS::WAFRegional::WebACL
    DependsOn: CamerasRateRule
    Properties:
      DefaultAction:
        Type: ALLOW
      MetricName: !Join ['', ['IPBlockingMetric', !Ref EnvironmentType]]
      Name: !Join ['', ['IPBlockingACL', !Ref EnvironmentType]]
      Rules:
        -
          Action:
            Type: "BLOCK"
          Priority: 1
          RuleId: !Ref CamerasRateRule

  CamerasRateRule:
    Type: AWS::WAFRegional::RateBasedRule
    Properties:
      MetricName: UnallowedAccessCount
      Name: FiveMinuteRule
      RateKey: IP
      RateLimit: !Ref Blocking
      MatchPredicates:
      -
        DataId: !Ref CamerasIpSet
        Negated: false
        Type: "IPMatch"

  CamerasIpSet:
    Type: AWS::WAFRegional::IPSet
    Properties:
      Name: !Join ['-', ['IpBlacklist', !Ref EnvironmentType]]


  MyWebACLAssociation:
    Type: AWS::WAFRegional::WebACLAssociation
    Properties:
      ResourceArn: !Sub arn:aws:apigateway:${AWS::Region}::/restapis/${CamerasApi}/stages/${StageName}
      WebACLId: !Ref WAFCamerasWebACL

Outputs:
  WebACL:
    Description: Name of the web ACL
    Value: !Ref WAFCamerasWebACL


MartinaW.. 8

我终于在AWS客户服务的帮助下解决了这个问题。当处理AWS :: WAFRegional :: RateBasedRule时,这是CloudFormation的限制。

尽管CloudFormation支持创建基于WAF区域费率的规则,但当前不支持将它们与Web ACL关联。如果您观察下面的链接[1],您将意识到:“要将通过CloudFormation创建的基于费率的规则添加到Web ACL,请使用AWS WAF控制台,API或命令行界面(CLI)。”

[1] AWS :: WAFRegional :: RateBasedRule:https ://docs.aws.amazon /AWSCloudFormation/latest/UserGuide/aws-resource-wafregional-ratebasedrule.html

我使用Cloudformation模板生成了WebACL,RateBasedRule以及WebACL与我的APIGW的关联。现在,在我们的CI / CD管道中使用CodeBuild,我现在使用CLI命令将RateBasedRule添加到WebACL aws waf-regional update-web-acl


1> MartinaW..:

我终于在AWS客户服务的帮助下解决了这个问题。当处理AWS :: WAFRegional :: RateBasedRule时,这是CloudFormation的限制。

尽管CloudFormation支持创建基于WAF区域费率的规则,但当前不支持将它们与Web ACL关联。如果您观察下面的链接[1],您将意识到:“要将通过CloudFormation创建的基于费率的规则添加到Web ACL,请使用AWS WAF控制台,API或命令行界面(CLI)。”

[1] AWS :: WAFRegional :: RateBasedRule:https ://docs.aws.amazon /AWSCloudFormation/latest/UserGuide/aws-resource-wafregional-ratebasedrule.html

我使用Cloudformation模板生成了WebACL,RateBasedRule以及WebACL与我的APIGW的关联。现在,在我们的CI / CD管道中使用CodeBuild,我现在使用CLI命令将RateBasedRule添加到WebACL aws waf-regional update-web-acl

带有CloudformationWAFRegional的SAMAPI网关
磁盘快照服务 操作指南 USnap RocketMQ 消息失败重试 解析——图解、源码级解析
相关内容