community.aws.waf_condition 模块 – 创建和删除 WAF 条件

注意

此模块是 community.aws 集合(版本 9.0.0)的一部分。

如果您正在使用 ansible 包,您可能已经安装了此集合。它不包含在 ansible-core 中。要检查是否已安装,请运行 ansible-galaxy collection list

要安装它,请使用:ansible-galaxy collection install community.aws。您需要进一步的要求才能使用此模块,请参阅 要求 获取详细信息。

要在剧本中使用它,请指定:community.aws.waf_condition

community.aws 1.0.0 中的新增功能

概要

别名:aws_waf_condition

要求

执行此模块的主机需要满足以下要求。

  • python >= 3.6

  • boto3 >= 1.28.0

  • botocore >= 1.31.0

参数

参数

注释

access_key

别名:aws_access_key_id, aws_access_key, ec2_access_key

字符串

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_IDAWS_ACCESS_KEYEC2_ACCESS_KEY 环境变量。

aws_access_keyprofile 选项是互斥的。

aws_access_key_id 别名在 5.1.0 版本中添加,以便与 AWS botocore SDK 保持一致。

ec2_access_key 别名已弃用,将在 2024-12-01 之后的版本中删除。

EC2_ACCESS_KEY 环境变量的支持已弃用,将在 2024-12-01 之后的版本中删除。

aws_ca_bundle

路径

用于验证 SSL 证书的 CA 捆绑包的位置。

也可以使用 AWS_CA_BUNDLE 环境变量。

aws_config

字典

用于修改 botocore 配置的字典。

参数可以在 AWS 文档中找到 https://botocore.amazonaws.com/v1/documentation/api/latest/reference/config.html#botocore.config.Config

debug_botocore_endpoint_logs

布尔值

使用 botocore.endpoint 记录器来解析在任务期间进行的唯一(而非总计)"资源:操作" API 调用,将该集合输出到任务结果中的 resource_actions 键。使用 aws_resource_action 回调输出到在剧本期间制作的总列表。

也可以使用 ANSIBLE_DEBUG_BOTOCORE_LOGS 环境变量。

选项

  • false ← (默认)

  • true

endpoint_url

别名:ec2_url, aws_endpoint_url, s3_url

字符串

连接到的 URL,而不是默认的 AWS 端点。虽然这可以用于连接到其他 AWS 兼容的服务,但 amazon.aws 和 community.aws 集合仅针对 AWS 进行测试。

也可以按优先级递减的顺序使用 AWS_URLEC2_URL 环境变量。

ec2_urls3_url 别名已弃用,将在 2024-12-01 之后的版本中删除。

EC2_URL 环境变量的支持已弃用,将在 2024-12-01 之后的版本中删除。

filters

列表 / 元素=字典

要匹配的过滤器列表。

对于 type=byte,有效的键是 field_to_matchpositionheadertransformationtarget_string

对于 type=geo,唯一有效的键是 country

对于 type=ip,唯一有效的键是 ip_address

对于 type=regex,有效的键为 field_to_matchtransformationregex_pattern

对于 type=size,有效的键为 field_to_matchtransformationcomparisonsize

对于 type=sql,有效的键为 field_to_matchtransformation

对于 type=xss,有效的键为 field_to_matchtransformation

state=present 时为必需项。

comparison

字符串

要执行的比较类型。

仅当 type=size 时为有效键。

选项

  • "EQ"

  • "NE"

  • "LE"

  • "LT"

  • "GE"

  • "GT"

country

字符串

地理约束的值(通常为两位字母的国家/地区代码)。

type=geo 时,唯一的有效键。

field_to_match

字符串

要执行匹配的字段。

type=bytetype=regextype=sqltype=xss 时有效。

选项

  • "uri"

  • "query_string"

  • "header"

  • "method"

  • "body"

header

字符串

应匹配的特定标头。

field_to_match=header 时为必需项。

type=byte 时有效。

ip_address

字符串

要匹配的 IP 地址或 CIDR。

type=ip 时,唯一的有效键。

position

字符串

匹配需要在字段中出现的位置。

仅当 type=byte 时有效。

选项

  • "exactly"

  • "starts_with"

  • "ends_with"

  • "contains"

  • "contains_word"

regex_pattern

字典

描述用于执行匹配的正则表达式的字典。

仅当 type=regex 时有效。

name

字符串

用于描述模式集的名称。

regex_strings

list / elements=string

要匹配的正则表达式列表。

size

integer

字段的大小(以字节为单位)。

仅当 type=size 时为有效键。

target_string

字符串

要搜索的字符串。

最多 50 个字节。

type=byte 时有效。

transformation

字符串

在执行匹配之前应用于字段的转换。

type=bytetype=regextype=sqltype=xss 时有效。

选项

  • "none"

  • "compress_white_space"

  • "html_entity_decode"

  • "lowercase"

  • "cmd_line"

  • "url_decode"

name

string / required

要管理的 Web 应用程序防火墙条件的名称。

profile

别名: aws_profile

字符串

用于身份验证的命名 AWS 配置文件。

有关命名配置文件的详细信息,请参阅 AWS 文档 https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-profiles.html

也可以使用 AWS_PROFILE 环境变量。

profile 选项与 aws_access_keyaws_secret_keysecurity_token 选项互斥。

purge_filters

布尔值

是否从条件中删除未在 filters 中传递的现有过滤器。

选项

  • false ← (默认)

  • true

region

别名: aws_region, ec2_region

字符串

要使用的 AWS 区域。

对于 IAM、Route53 和 CloudFront 等全局服务,将忽略 region

也可以使用 AWS_REGIONEC2_REGION 环境变量。

有关详细信息,请参阅 Amazon AWS 文档 http://docs.aws.amazon.com/general/latest/gr/rande.html#ec2_region

ec2_region 别名已弃用,将在 2024-12-01 之后的版本中删除

EC2_REGION 环境变量的支持已弃用,将在 2024-12-01 之后的版本中删除。

secret_key

别名: aws_secret_access_key, aws_secret_key, ec2_secret_key

字符串

AWS 私有访问密钥。

有关访问令牌的更多信息,请参阅 AWS 文档 https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys

也可以按优先级降序使用 AWS_SECRET_ACCESS_KEYAWS_SECRET_KEYEC2_SECRET_KEY 环境变量。

secret_keyprofile 选项互斥。

aws_secret_access_key 别名在 5.1.0 版本中添加,以与 AWS botocore SDK 保持一致。

ec2_secret_key 别名已弃用,将在 2024-12-01 之后的版本中删除。

EC2_SECRET_KEY 环境变量的支持已弃用,将在 2024-12-01 之后的版本中删除。

session_token

别名: aws_session_token, security_token, aws_security_token, access_token

字符串

用于临时凭证的 AWS STS 会话令牌。

有关访问令牌的更多信息,请参阅 AWS 文档 https://docs.aws.amazon.com/general/latest/gr/aws-sec-cred-types.html#access-keys-and-secret-access-keys

也可以按优先级降序使用 AWS_SESSION_TOKENAWS_SECURITY_TOKENEC2_SECURITY_TOKEN 环境变量。

security_tokenprofile 选项互斥。

别名 aws_session_tokensession_token 在 3.2.0 版本中添加,参数在 6.0.0 版本中从 security_token 重命名为 session_token

security_tokenaws_security_tokenaccess_token 别名已弃用,将在 2024-12-01 之后的版本中删除。

EC2_SECRET_KEYAWS_SECURITY_TOKEN 环境变量的支持已弃用,将在 2024-12-01 之后的版本中删除。

state

字符串

条件应为 presentabsent

选项

  • "present" ← (默认)

  • "absent"

type

string / required

要执行的匹配类型。

选项

  • "byte"

  • "geo"

  • "ip"

  • "regex"

  • "size"

  • "sql"

  • "xss"

validate_certs

布尔值

当设置为 false 时,将不会验证与 AWS API 通信的 SSL 证书。

强烈建议不要设置 validate_certs=false,作为替代方案,请考虑设置 aws_ca_bundle

选项

  • false

  • true ← (默认)

waf_regional

布尔值

是否使用 waf-regional 模块。

选项

  • false ← (默认)

  • true

备注

注意

  • 注意: 对于模块,环境变量和配置文件是从 Ansible “主机” 上下文读取的,而不是从“控制器” 上下文读取的。因此,可能需要将文件显式复制到“主机”。对于查找和连接插件,环境变量和配置文件是从 Ansible “控制器” 上下文读取的,而不是从“主机” 上下文读取的。

  • Ansible 使用的 AWS SDK (boto3) 也可能从其在 Ansible “主机” 上下文中的配置文件(通常为 ~/.aws/credentials)读取凭证和其他设置(例如区域)的默认值。有关详细信息,请参阅 https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html

示例

- name: create WAF byte condition
  community.aws.waf_condition:
    name: my_byte_condition
    filters:
      - field_to_match: header
        position: STARTS_WITH
        target_string: Hello
        header: Content-type
    type: byte

- name: create WAF geo condition
  community.aws.waf_condition:
    name: my_geo_condition
    filters:
      - country: US
      - country: AU
      - country: AT
    type: geo

- name: create IP address condition
  community.aws.waf_condition:
    name: "{{ resource_prefix }}_ip_condition"
    filters:
      - ip_address: "10.0.0.0/8"
      - ip_address: "192.168.0.0/24"
    type: ip

- name: create WAF regex condition
  community.aws.waf_condition:
    name: my_regex_condition
    filters:
      - field_to_match: query_string
        regex_pattern:
          name: greetings
          regex_strings:
            - '[hH]ello'
            - '^Hi there'
            - '.*Good Day to You'
    type: regex

- name: create WAF size condition
  community.aws.waf_condition:
    name: my_size_condition
    filters:
      - field_to_match: query_string
        size: 300
        comparison: GT
    type: size

- name: create WAF sql injection condition
  community.aws.waf_condition:
    name: my_sql_condition
    filters:
      - field_to_match: query_string
        transformation: url_decode
    type: sql

- name: create WAF xss condition
  community.aws.waf_condition:
    name: my_xss_condition
    filters:
      - field_to_match: query_string
        transformation: url_decode
    type: xss

返回值

常见返回值在此处 此处 记录,以下是此模块特有的字段

描述

condition

complex

操作返回的条件。

返回: 始终

byte_match_set_id

字符串

字节匹配集的 ID。

返回: 始终

示例: "c4882c96-837b-44a2-a762-4ea87dbf812b"

byte_match_tuples

complex

字节匹配元组的列表。

返回: 始终

field_to_match

complex

要匹配的字段。

返回: 始终

data

字符串

哪个特定标头(如果类型为标头)。

返回: 成功

示例: "content-type"

type

字符串

字段类型

返回: 成功

示例: "HEADER"

positional_constraint

字符串

字段中要匹配的位置。

返回: 成功

示例: "STARTS_WITH"

target_string

字符串

要查找的字符串。

返回: 成功

示例: "Hello"

text_transformation

字符串

在匹配之前应用于字段的转换。

返回: 成功

示例: "NONE"

condition_id

字符串

条件类型无关的 ID。

返回: 当状态为 present 时

示例: "dd74b1ff-8c06-4a4f-897a-6b23605de413"

geo_match_constraints

complex

地理约束列表。

返回: 当类型为 geo 且状态为 present 时

type

字符串

地理约束的类型。

返回: 成功

示例: "Country"

value

字符串

地理约束的值(通常为国家/地区代码)。

返回: 成功

示例: "AT"

geo_match_set_id

字符串

地理匹配集的 ID。

返回: 当类型为 geo 且状态为 present 时

示例: "dd74b1ff-8c06-4a4f-897a-6b23605de413"

ip_set_descriptors

complex

IP 地址过滤器列表

返回: 当类型为 ip 且状态为 present 时

type

字符串

IP 地址类型(IPV4 或 IPV6)。

返回: 始终

示例: "IPV4"

value

字符串

IP 地址。

返回: 始终

示例: "10.0.0.0/8"

ip_set_id

字符串

条件的 ID。

返回: 当类型为 ip 且状态为 present 时

示例: "78ad334a-3535-4036-85e6-8e11e745217b"

name

字符串

条件的名称。

返回: 当状态为 present 时

示例: "my_waf_condition"

regex_match_set_id

字符串

正则表达式匹配集的 ID。

返回:当类型为 regex 且状态为 present 时

示例: "5ea3f6a8-3cd3-488b-b637-17b79ce7089c"

regex_match_tuples

complex

正则表达式匹配列表。

返回:当类型为 regex 且状态为 present 时

field_to_match

complex

应用正则表达式匹配的字段。

返回: 成功

type

字符串

字段名称。

返回:当类型为 regex 且状态为 present 时

示例: "QUERY_STRING"

regex_pattern_set_id

字符串

正则表达式模式的 ID。

返回: 成功

示例: "6fdf7f2d-9091-445c-aef2-98f3c051ac9e"

text_transformation

字符串

匹配前应用于文本的转换

返回: 成功

示例: "NONE"

size_constraint_set_id

字符串

大小约束集的 ID。

返回:当类型为 size 且状态为 present 时

示例: "de84b4b3-578b-447e-a9a0-0db35c995656"

size_constraints

complex

要应用的大小约束列表。

返回:当类型为 size 且状态为 present 时

comparison_operator

字符串

要应用的比较运算符。

返回: 成功

示例: "GT"

field_to_match

complex

应用大小约束的字段。

返回: 成功

type

字符串

字段名称。

返回: 成功

示例: "QUERY_STRING"

size

integer

与字段进行比较的大小。

返回: 成功

示例: 300

text_transformation

字符串

匹配前应用于文本的转换。

返回: 成功

示例: "NONE"

sql_injection_match_set_id

字符串

SQL 注入匹配集的 ID。

返回:当类型为 sql 且状态为 present 时

示例: "de84b4b3-578b-447e-a9a0-0db35c995656"

sql_injection_match_tuples

complex

SQL 注入匹配集列表。

返回:当类型为 sql 且状态为 present 时

field_to_match

complex

应用 SQL 注入匹配的字段。

返回: 成功

type

字符串

字段名称。

返回: 成功

示例: "QUERY_STRING"

text_transformation

字符串

匹配前应用于文本的转换。

返回: 成功

示例: "URL_DECODE"

xss_match_set_id

字符串

XSS 匹配集的 ID。

返回:当类型为 xss 且状态为 present 时

示例: "de84b4b3-578b-447e-a9a0-0db35c995656"

xss_match_tuples

complex

XSS 匹配集列表。

返回:当类型为 xss 且状态为 present 时

field_to_match

complex

应用 XSS 匹配的字段。

返回: 成功

type

字符串

字段名称

返回: 成功

示例: "QUERY_STRING"

text_transformation

字符串

匹配前应用于文本的转换。

返回: 成功

示例: "URL_DECODE"

作者

  • Will Thames (@willthames)

  • Mike Mochan (@mmochan)