community.aws.wafv2_web_acl 模块 – 创建和删除 WAF Web ACL
注意
此模块是 community.aws 集合 (版本 9.0.0) 的一部分。
如果您正在使用 ansible 包,则可能已安装此集合。它不包含在 ansible-core 中。要检查它是否已安装,请运行 ansible-galaxy collection list。
要安装它,请使用: ansible-galaxy collection install community.aws。您需要其他要求才能使用此模块,有关详细信息,请参见 要求。
要在 playbook 中使用它,请指定: community.aws.wafv2_web_acl。
community.aws 1.5.0 中的新增功能
概要
- 创建、修改或删除 AWS WAF v2 web ACL(不适用于经典 WAF)。 
- 请参见文档 https://docs.aws.amazon.com/waf/latest/developerguide/waf-chapter.html 
要求
执行此模块的主机需要以下要求。
- python >= 3.6 
- boto3 >= 1.28.0 
- botocore >= 1.31.0 
参数
| 参数 | 注释 | 
|---|---|
| AWS 访问密钥 ID。 有关访问令牌的更多信息,请参见 AWS 文档 https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys。 还可以按优先级递减顺序使用  aws_access_key 和 profile 选项是互斥的。 为了与 AWS botocore SDK 保持一致,aws_access_key_id 别名是在 5.1.0 版本中添加的。 ec2_access_key 别名已弃用,将在 2024-12-01 之后的一个版本中移除。 
 | |
| 验证 SSL 证书时使用的 CA 证书包的位置。 还可以使用  | |
| 用于修改 botocore 配置的字典。 可以在 AWS 文档中找到参数 https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html#botocore.config.Config。 | |
| 为 wafv2 web acl 启用 cloudwatch 指标。 选项 
 | |
| 自定义响应键和内容体的映射。在此处定义响应体,并通过提供 主体字典元素的键在规则中引用它们。 每个元素必须具有唯一的字典键,并且在字典中具有content_type和content两个键。 | |
| 使用  还可以使用  选项 
 | |
| wafv2 web acl 的默认操作。 选项 
 | |
| WAFv2 Web ACL 的描述。 | |
| 连接到AWS端点的URL,而不是默认的AWS端点。虽然这可以用于连接到其他兼容AWS的服务,但amazon.aws和community.aws集合只针对AWS进行了测试。 也可以使用 ec2_url和s3_url别名已弃用,将在2024-12-01之后的一个版本中移除。 对 | |
| CloudWatch 指标的名称。 如果未指定且启用了cloudwatch_metrics,则将使用Web ACL本身的名称。 | |
| Web ACL 的名称。 | |
| 用于身份验证的命名AWS配置文件。 有关命名配置文件的更多信息,请参阅AWS文档 https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html。 也可以使用 profile选项与aws_access_key、aws_secret_key和security_token选项互斥。 | |
| 设置为 选项 
 | |
| 如果 如果未设置 以 选项 
 | |
| 要使用的AWS区域。 对于IAM、Route53和CloudFront等全局服务,将忽略region。 也可以使用 有关更多信息,请参阅Amazon AWS文档 http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region。 ec2_region别名已弃用,将在2024-12-01之后的一个版本中移除。 对 | |
| 用于标识要允许、阻止或计数的Web请求的规则语句。 有关托管规则的列表,请参阅 https://docs.aws.amazon.com/waf/latest/developerguide/aws-managed-rule-groups-list.html。 | |
| 规则是被阻止、允许还是计数。 | |
| WAFv2规则的名称 | |
| 规则优先级 | |
| 规则配置。 | |
| 单个WAFv2规则的可见性。 | |
| 是否存储Web请求样本,true或false。 选项 
 | |
| Web ACL 的地理范围。 选项 
 | |
| AWS 密钥访问密钥。 有关访问令牌的更多信息,请参见 AWS 文档 https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys。 也可以使用 secret_key和profile选项互斥。 为了与AWS botocore SDK保持一致,在5.1.0版本中添加了aws_secret_access_key别名。 ec2_secret_key别名已弃用,将在2024-12-01之后的一个版本中移除。 对 | |
| 与临时凭据一起使用的AWS STS会话令牌。 有关访问令牌的更多信息,请参见 AWS 文档 https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys。 也可以使用 security_token和profile选项互斥。 在3.2.0版本中添加了aws_session_token和session_token别名,在6.0.0版本中将参数名称从security_token重命名为session_token。 security_token、aws_security_token和access_token别名已弃用,将在2024-12-01之后的一个版本中移除。 对 | |
| 规则是否存在。 选项 
 | |
| 表示要应用于资源的标签的字典。 如果未设置 | |
| 设置为 强烈建议不要设置validate_certs=false,可以考虑改用aws_ca_bundle。 选项 
 | 
备注
注意
- 在4.0.0版本中添加了对purge_tags参数的支持。 
- 注意:对于模块,环境变量和配置文件是从Ansible的“主机”上下文读取的,而不是“控制器”上下文。因此,可能需要将文件显式复制到“主机”。对于查找和连接插件,环境变量和配置文件是从Ansible的“控制器”上下文读取的,而不是“主机”上下文。 
- Ansible使用的AWS SDK (boto3)也可能从其在Ansible“主机”上下文中的配置文件(通常为 - ~/.aws/credentials)读取凭据和其他设置的默认值,例如区域。有关更多信息,请参阅 https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html。
示例
- name: Create test web acl
  community.aws.wafv2_web_acl:
    name: test05
    description: hallo eins
    scope: REGIONAL
    default_action: Allow
    sampled_requests: false
    cloudwatch_metrics: true
    metric_name: test05-acl-metric
    rules:
      - name: zwei
        priority: 0
        action:
          block: {}
        visibility_config:
          sampled_requests_enabled: true
          cloud_watch_metrics_enabled: true
          metric_name: ddos
        statement:
          xss_match_statement:
            field_to_match:
              body: {}
            text_transformations:
              - type: NONE
                priority: 0
      - name: admin_protect
        priority: 1
        override_action:
          none: {}
        visibility_config:
          sampled_requests_enabled: true
          cloud_watch_metrics_enabled: true
          metric_name: fsd
        statement:
          managed_rule_group_statement:
            vendor_name: AWS
            name: AWSManagedRulesAdminProtectionRuleSet
      # AWS Managed Bad Input Rule Set
      # but allow PROPFIND_METHOD used e.g. by webdav
      - name: bad_input_protect_whitelist_webdav
        priority: 2
        override_action:
          none: {}
        visibility_config:
          sampled_requests_enabled: true
          cloud_watch_metrics_enabled: true
          metric_name: bad_input_protect
        statement:
          managed_rule_group_statement:
            vendor_name: AWS
            name: AWSManagedRulesKnownBadInputsRuleSet
            excluded_rules:
              - name: PROPFIND_METHOD
      # Rate Limit example. 1500 req/5min
      # counted for two domains via or_statement. login.mydomain.tld and api.mydomain.tld
      - name: rate_limit_example
        priority: 3
        action:
          block: {}
        visibility_config:
          sampled_requests_enabled: true
          cloud_watch_metrics_enabled: true
          metric_name: mydomain-ratelimit
        statement:
          rate_based_statement:
            limit: 1500
            aggregate_key_type: IP
            scope_down_statement:
              or_statement:
                statements:
                  - byte_match_statement:
                      search_string: login.mydomain.tld
                      positional_constraint: CONTAINS
                      field_to_match:
                        single_header:
                          name: host
                      text_transformations:
                        - type: LOWERCASE
                          priority: 0
                  - byte_match_dtatement:
                      search_string: api.mydomain.tld
                      positional_constraint: CONTAINS
                      field_to_match:
                        single_header:
                          name: host
                      text_transformations:
                        - type: LOWERCASE
                          priority: 0
    purge_rules: true
    tags:
      A: B
      C: D
    state: present
- name: Create IP filtering web ACL
  community.aws.wafv2_web_acl:
    name: ip-filtering-traffic
    description: ACL that filters web traffic based on rate limits and whitelists some IPs
    scope: REGIONAL
    default_action: Allow
    sampled_requests: true
    cloudwatch_metrics: true
    metric_name: ip-filtering-traffic
    rules:
      - name: whitelist-own-IPs
        priority: 0
        action:
          allow: {}
        statement:
          ip_set_reference_statement:
            arn: 'arn:aws:wafv2:us-east-1:123456789012:regional/ipset/own-public-ips/1c4bdfc4-0f77-3b23-5222-123123123'
        visibility_config:
          sampled_requests_enabled: true
          cloud_watch_metrics_enabled: true
          metric_name: waf-acl-rule-whitelist-own-IPs
      - name: rate-limit-per-IP
        priority: 1
        action:
          block:
            custom_response:
              response_code: 429
              custom_response_body_key: too_many_requests
        statement:
          rate_based_statement:
            limit: 5000
            aggregate_key_type: IP
        visibility_config:
          sampled_requests_enabled: true
          cloud_watch_metrics_enabled: true
          metric_name: waf-acl-rule-rate-limit-per-IP
        purge_rules: true
    custom_response_bodies:
      too_many_requests:
        content_type: APPLICATION_JSON
        content: '{ message: "Your request has been blocked due to too many HTTP requests coming from your IP" }'
    region: us-east-1
    state: present
返回值
常见的返回值已在 此处 记录,以下是此模块特有的字段
| 键 | 描述 | 
|---|---|
| Web ACL ARN 返回:只要Web ACL存在,就会始终返回。 示例: | |
| Web ACL 的当前容量 返回:只要Web ACL存在,就会始终返回。 示例: | |
| 要在规则中使用的自定义响应正文配置 返回:只要Web ACL存在,就会始终返回。 示例: | |
| ACL 的默认操作 返回:只要Web ACL存在,就会始终返回。 示例: | |
| Web ACL 的描述 返回:只要Web ACL存在,就会始终返回。 示例: | |
| Web ACL 名称 返回:只要Web ACL存在,就会始终返回。 示例: | |
| Web ACL 的当前规则 返回:只要Web ACL存在,就会始终返回。 示例: | |
| Web ACL 的可见性配置 返回:只要Web ACL存在,就会始终返回。 示例:  | 
