| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
|
| 4 |
# Copyright: Ansible Project |
| 5 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 6 |
|
| 7 |
DOCUMENTATION = r""" |
| 8 |
module: networkfirewall_rule_group |
| 9 |
short_description: create, delete and modify AWS Network Firewall rule groups |
| 10 |
version_added: 4.0.0 |
| 11 |
description: |
| 12 |
- A module for managing AWS Network Firewall rule groups. |
| 13 |
- U(https://docs.aws.amazon.com/network-firewall/latest/developerguide/index.html) |
| 14 |
- Currently only supports C(stateful) firewall groups. |
| 15 |
options: |
| 16 |
arn: |
| 17 |
description: |
| 18 |
- The ARN of the Network Firewall rule group. |
| 19 |
- Exactly one of I(arn) and I(name) must be provided. |
| 20 |
required: false |
| 21 |
type: str |
| 22 |
name: |
| 23 |
description: |
| 24 |
- The name of the Network Firewall rule group. |
| 25 |
- When I(name) is set, I(rule_type) must also be set. |
| 26 |
required: false |
| 27 |
type: str |
| 28 |
rule_type: |
| 29 |
description: |
| 30 |
- Indicates whether the rule group is stateless or stateful. |
| 31 |
- Stateless rulesets are currently not supported. |
| 32 |
- Required if I(name) is set. |
| 33 |
required: false |
| 34 |
aliases: ['type' ] |
| 35 |
choices: ['stateful'] |
| 36 |
# choices: ['stateful', 'stateless'] |
| 37 |
type: str |
| 38 |
state: |
| 39 |
description: |
| 40 |
- Create or remove the Network Firewall rule group. |
| 41 |
required: false |
| 42 |
choices: ['present', 'absent'] |
| 43 |
default: 'present' |
| 44 |
type: str |
| 45 |
capacity: |
| 46 |
description: |
| 47 |
- The maximum operating resources that this rule group can use. |
| 48 |
- Once a rule group is created this parameter is immutable. |
| 49 |
- See also the AWS documentation about how capacityis calculated |
| 50 |
U(https://docs.aws.amazon.com/network-firewall/latest/developerguide/nwfw-rule-group-capacity.html) |
| 51 |
- This option is mandatory when creating a new rule group. |
| 52 |
type: int |
| 53 |
required: false |
| 54 |
rule_order: |
| 55 |
description: |
| 56 |
- Indicates how to manage the order of the rule evaluation for the rule group. |
| 57 |
- Once a rule group is created this parameter is immutable. |
| 58 |
- Mutually exclusive with I(rule_type=stateless). |
| 59 |
- For more information on how rules are evaluated read the AWS documentation |
| 60 |
U(https://docs.aws.amazon.com/network-firewall/latest/developerguide/suricata-rule-evaluation-order.html). |
| 61 |
type: str |
| 62 |
required: false |
| 63 |
choices: ['default', 'strict'] |
| 64 |
aliases: ['stateful_rule_order'] |
| 65 |
description: |
| 66 |
description: |
| 67 |
- A description of the AWS Network Firewall rule group. |
| 68 |
type: str |
| 69 |
ip_variables: |
| 70 |
description: |
| 71 |
- A dictionary mapping variable names to a list of IP addresses and address ranges, in CIDR notation. |
| 72 |
- For example C({EXAMPLE_HOSTS:["192.0.2.0/24", "203.0.113.42"]}). |
| 73 |
- Mutually exclusive with I(domain_list). |
| 74 |
type: dict |
| 75 |
required: false |
| 76 |
aliases: ['ip_set_variables'] |
| 77 |
purge_ip_variables: |
| 78 |
description: |
| 79 |
- Whether to purge variable names not mentioned in the I(ip_variables) |
| 80 |
dictionary. |
| 81 |
- To remove all IP Set Variables it is necessary to explicitly set I(ip_variables={}) |
| 82 |
and I(purge_port_variables=true). |
| 83 |
type: bool |
| 84 |
default: true |
| 85 |
required: false |
| 86 |
aliases: ['purge_ip_set_variables'] |
| 87 |
port_variables: |
| 88 |
description: |
| 89 |
- A dictionary mapping variable names to a list of ports. |
| 90 |
- For example C({SECURE_PORTS:["22", "443"]}). |
| 91 |
type: dict |
| 92 |
required: false |
| 93 |
aliases: ['port_set_variables'] |
| 94 |
purge_port_variables: |
| 95 |
description: |
| 96 |
- Whether to purge variable names not mentioned in the I(port_variables) |
| 97 |
dictionary. |
| 98 |
- To remove all Port Set Variables it is necessary to explicitly set I(port_variables={}) |
| 99 |
and I(purge_port_variables=true). |
| 100 |
type: bool |
| 101 |
required: false |
| 102 |
default: true |
| 103 |
aliases: ['purge_port_set_variables'] |
| 104 |
rule_strings: |
| 105 |
description: |
| 106 |
- Rules in Suricata format. |
| 107 |
- If I(rule_strings) is specified, it must include at least one entry. |
| 108 |
- For more information read the AWS documentation |
| 109 |
U(https://docs.aws.amazon.com/network-firewall/latest/developerguide/suricata-limitations-caveats.html) |
| 110 |
and the Suricata documentation |
| 111 |
U(https://suricata.readthedocs.io/en/suricata-6.0.0/rules/intro.html). |
| 112 |
- Mutually exclusive with I(rule_type=stateless). |
| 113 |
- Mutually exclusive with I(domain_list) and I(rule_list). |
| 114 |
- Exactly one of I(rule_strings), I(domain_list) or I(rule_list) must be |
| 115 |
specified at creation time. |
| 116 |
type: list |
| 117 |
elements: str |
| 118 |
required: false |
| 119 |
domain_list: |
| 120 |
description: |
| 121 |
- Inspection criteria for a domain list rule group. |
| 122 |
- When set overwrites all Domain List settings with the new configuration. |
| 123 |
- For more information about domain name based filtering |
| 124 |
read the AWS documentation |
| 125 |
U(https://docs.aws.amazon.com/network-firewall/latest/developerguide/stateful-rule-groups-domain-names.html). |
| 126 |
- Mutually exclusive with I(rule_type=stateless). |
| 127 |
- Mutually exclusive with I(ip_variables), I(rule_list) and I(rule_strings). |
| 128 |
- Exactly one of I(rule_strings), I(domain_list) or I(rule_list) must be |
| 129 |
specified at creation time. |
| 130 |
type: dict |
| 131 |
required: false |
| 132 |
suboptions: |
| 133 |
domain_names: |
| 134 |
description: |
| 135 |
- A list of domain names to look for in the traffic flow. |
| 136 |
type: list |
| 137 |
elements: str |
| 138 |
required: true |
| 139 |
filter_http: |
| 140 |
description: |
| 141 |
- Whether HTTP traffic should be inspected (uses the host header). |
| 142 |
type: bool |
| 143 |
required: false |
| 144 |
default: false |
| 145 |
filter_https: |
| 146 |
description: |
| 147 |
- Whether HTTPS traffic should be inspected (uses the SNI). |
| 148 |
type: bool |
| 149 |
required: false |
| 150 |
default: false |
| 151 |
action: |
| 152 |
description: |
| 153 |
- Action to perform on traffic that matches the rule match settings. |
| 154 |
type: str |
| 155 |
required: true |
| 156 |
choices: ['allow', 'deny'] |
| 157 |
source_ips: |
| 158 |
description: |
| 159 |
- Used to expand the local network definition beyond the CIDR range |
| 160 |
of the VPC where you deploy Network Firewall. |
| 161 |
type: list |
| 162 |
elements: str |
| 163 |
required: false |
| 164 |
rule_list: |
| 165 |
description: |
| 166 |
- Inspection criteria to be used for a 5-tuple based rule group. |
| 167 |
- When set overwrites all existing 5-tuple rules with the new configuration. |
| 168 |
- Mutually exclusive with I(domain_list) and I(rule_strings). |
| 169 |
- Mutually exclusive with I(rule_type=stateless). |
| 170 |
- Exactly one of I(rule_strings), I(domain_list) or I(rule_list) must be |
| 171 |
specified at creation time. |
| 172 |
- For more information about valid values see the AWS documentation |
| 173 |
U(https://docs.aws.amazon.com/network-firewall/latest/APIReference/API_StatefulRule.html) |
| 174 |
and |
| 175 |
U(https://docs.aws.amazon.com/network-firewall/latest/APIReference/API_Header.html). |
| 176 |
- 'Note: Idempotency when comparing AWS Web UI and Ansiible managed rules can not be guaranteed' |
| 177 |
type: list |
| 178 |
elements: dict |
| 179 |
required: false |
| 180 |
aliases: ['stateful_rule_list'] |
| 181 |
suboptions: |
| 182 |
action: |
| 183 |
description: |
| 184 |
- What Network Firewall should do with the packets in a traffic flow when the flow matches. |
| 185 |
type: str |
| 186 |
required: true |
| 187 |
choices: ['pass', 'drop', 'alert'] |
| 188 |
protocol: |
| 189 |
description: |
| 190 |
- The protocol to inspect for. To specify all, you can use C(IP), because all traffic on AWS is C(IP). |
| 191 |
type: str |
| 192 |
required: true |
| 193 |
source: |
| 194 |
description: |
| 195 |
- The source IP address or address range to inspect for, in CIDR notation. |
| 196 |
- To match with any address, specify C(ANY). |
| 197 |
type: str |
| 198 |
required: true |
| 199 |
source_port: |
| 200 |
description: |
| 201 |
- The source port to inspect for. |
| 202 |
- To match with any port, specify C(ANY). |
| 203 |
type: str |
| 204 |
required: true |
| 205 |
direction: |
| 206 |
description: |
| 207 |
- The direction of traffic flow to inspect. |
| 208 |
- If set to C(any), the inspection matches both traffic going from the |
| 209 |
I(source) to the I(destination) and from the I(destination) to the |
| 210 |
I(source). |
| 211 |
- If set to C(forward), the inspection only matches traffic going from the |
| 212 |
I(source) to the I(destination). |
| 213 |
type: str |
| 214 |
required: false |
| 215 |
default: 'forward' |
| 216 |
choices: ['forward', 'any'] |
| 217 |
destination: |
| 218 |
description: |
| 219 |
- The destination IP address or address range to inspect for, in CIDR notation. |
| 220 |
- To match with any address, specify C(ANY). |
| 221 |
type: str |
| 222 |
required: true |
| 223 |
destination_port: |
| 224 |
description: |
| 225 |
- The source port to inspect for. |
| 226 |
- To match with any port, specify C(ANY). |
| 227 |
type: str |
| 228 |
required: true |
| 229 |
sid: |
| 230 |
description: |
| 231 |
- The signature ID of the rule. |
| 232 |
- A unique I(sid) must be passed for all rules. |
| 233 |
type: int |
| 234 |
required: true |
| 235 |
rule_options: |
| 236 |
description: |
| 237 |
- Additional options for the rule. |
| 238 |
- 5-tuple based rules are converted by AWS into Suricata rules, for more |
| 239 |
complex options requirements where order matters consider using I(rule_strings). |
| 240 |
- A dictionary mapping Suricata RuleOptions names to a list of values. |
| 241 |
- The examples section contains some examples of using rule_options. |
| 242 |
- For more information read the AWS documentation |
| 243 |
U(https://docs.aws.amazon.com/network-firewall/latest/developerguide/suricata-limitations-caveats.html) |
| 244 |
and the Suricata documentation |
| 245 |
U(https://suricata.readthedocs.io/en/suricata-6.0.0/rules/intro.html). |
| 246 |
type: dict |
| 247 |
required: false |
| 248 |
wait: |
| 249 |
description: |
| 250 |
- Whether to wait for the firewall rule group to reach the |
| 251 |
C(ACTIVE) or C(DELETED) state before the module returns. |
| 252 |
type: bool |
| 253 |
required: false |
| 254 |
default: true |
| 255 |
wait_timeout: |
| 256 |
description: |
| 257 |
- Maximum time, in seconds, to wait for the firewall rule group |
| 258 |
to reach the expected state. |
| 259 |
- Defaults to 600 seconds. |
| 260 |
type: int |
| 261 |
required: false |
| 262 |
|
| 263 |
author: |
| 264 |
- Mark Chappell (@tremble) |
| 265 |
extends_documentation_fragment: |
| 266 |
- amazon.aws.common.modules |
| 267 |
- amazon.aws.region.modules |
| 268 |
- amazon.aws.tags |
| 269 |
- amazon.aws.boto3 |
| 270 |
""" |
| 271 |
|
| 272 |
EXAMPLES = r""" |
| 273 |
# Create a rule group |
| 274 |
- name: Create a minimal AWS Network Firewall Rule Group |
| 275 |
community.aws.networkfirewall_rule_group: |
| 276 |
name: 'MinimalGroup' |
| 277 |
type: 'stateful' |
| 278 |
capacity: 200 |
| 279 |
rule_strings: |
| 280 |
- 'pass tcp any any -> any any (sid:1000001;)' |
| 281 |
|
| 282 |
# Create an example rule group using rule_list |
| 283 |
- name: Create 5-tuple Rule List based rule group |
| 284 |
community.aws.networkfirewall_rule_group: |
| 285 |
name: 'ExampleGroup' |
| 286 |
type: 'stateful' |
| 287 |
description: 'My description' |
| 288 |
rule_order: default |
| 289 |
capacity: 100 |
| 290 |
rule_list: |
| 291 |
- sid: 1 |
| 292 |
direction: forward |
| 293 |
action: pass |
| 294 |
protocol: IP |
| 295 |
source: any |
| 296 |
source_port: any |
| 297 |
destination: any |
| 298 |
destination_port: any |
| 299 |
|
| 300 |
# Create an example rule group using rule_list |
| 301 |
- name: Create 5-tuple Rule List based rule group |
| 302 |
community.aws.networkfirewall_rule_group: |
| 303 |
name: 'ExampleGroup' |
| 304 |
type: 'stateful' |
| 305 |
description: 'My description' |
| 306 |
ip_variables: |
| 307 |
SOURCE_IPS: ['203.0.113.0/24', '198.51.100.42'] |
| 308 |
DESTINATION_IPS: ['192.0.2.0/24', '198.51.100.48'] |
| 309 |
port_variables: |
| 310 |
HTTP_PORTS: [80, 8080] |
| 311 |
rule_order: default |
| 312 |
capacity: 100 |
| 313 |
rule_list: |
| 314 |
# Allow 'Destination Unreachable' traffic |
| 315 |
- sid: 1 |
| 316 |
action: pass |
| 317 |
protocol: icmp |
| 318 |
source: any |
| 319 |
source_port: any |
| 320 |
destination: any |
| 321 |
destination_port: any |
| 322 |
rule_options: |
| 323 |
itype: 3 |
| 324 |
- sid: 2 |
| 325 |
action: drop |
| 326 |
protocol: tcp |
| 327 |
source: "$SOURCE_IPS" |
| 328 |
source_port: any |
| 329 |
destination: "$DESTINATION_IPS" |
| 330 |
destination_port: "$HTTP_PORTS" |
| 331 |
rule_options: |
| 332 |
urilen: ["20<>40"] |
| 333 |
# Where only a keyword is needed, add the keword, but no value |
| 334 |
http_uri: |
| 335 |
# Settings where Suricata expects raw strings (like the content |
| 336 |
# keyword) will need to have the double-quotes explicitly escaped and |
| 337 |
# passed because there's no practical way to distinguish between them |
| 338 |
# and flags. |
| 339 |
content: '"index.php"' |
| 340 |
|
| 341 |
# Create an example rule group using Suricata rule strings |
| 342 |
- name: Create Suricata rule string based rule group |
| 343 |
community.aws.networkfirewall_rule_group: |
| 344 |
name: 'ExampleSuricata' |
| 345 |
type: 'stateful' |
| 346 |
description: 'My description' |
| 347 |
capacity: 200 |
| 348 |
ip_variables: |
| 349 |
EXAMPLE_IP: ['203.0.113.0/24', '198.51.100.42'] |
| 350 |
ANOTHER_EXAMPLE: ['192.0.2.0/24', '198.51.100.48'] |
| 351 |
port_variables: |
| 352 |
EXAMPLE_PORT: [443, 22] |
| 353 |
rule_strings: |
| 354 |
- 'pass tcp any any -> $EXAMPLE_IP $EXAMPLE_PORT (sid:1000001;)' |
| 355 |
- 'pass udp any any -> $ANOTHER_EXAMPLE any (sid:1000002;)' |
| 356 |
|
| 357 |
# Create an example Domain List based rule group |
| 358 |
- name: Create Domain List based rule group |
| 359 |
community.aws.networkfirewall_rule_group: |
| 360 |
name: 'ExampleDomainList' |
| 361 |
type: 'stateful' |
| 362 |
description: 'My description' |
| 363 |
capacity: 100 |
| 364 |
domain_list: |
| 365 |
domain_names: |
| 366 |
- 'example.com' |
| 367 |
- '.example.net' |
| 368 |
filter_https: true |
| 369 |
filter_http: true |
| 370 |
action: allow |
| 371 |
source_ips: '192.0.2.0/24' |
| 372 |
|
| 373 |
# Update the description of a rule group |
| 374 |
- name: Update the description of a rule group |
| 375 |
community.aws.networkfirewall_rule_group: |
| 376 |
name: 'MinimalGroup' |
| 377 |
type: 'stateful' |
| 378 |
description: 'Another description' |
| 379 |
|
| 380 |
# Update IP Variables for a rule group |
| 381 |
- name: Update IP Variables |
| 382 |
community.aws.networkfirewall_rule_group: |
| 383 |
name: 'ExampleGroup' |
| 384 |
type: 'stateful' |
| 385 |
ip_variables: |
| 386 |
EXAMPLE_IP: ['192.0.2.0/24', '203.0.113.0/24', '198.51.100.42'] |
| 387 |
purge_ip_variables: false |
| 388 |
|
| 389 |
# Delete a rule group |
| 390 |
- name: Delete a rule group |
| 391 |
community.aws.networkfirewall_rule_group: |
| 392 |
name: 'MinimalGroup' |
| 393 |
type: 'stateful' |
| 394 |
state: absent |
| 395 |
""" |
| 396 |
|
| 397 |
RETURN = r""" |
| 398 |
rule_group: |
| 399 |
description: Details of the rules in the rule group |
| 400 |
type: dict |
| 401 |
returned: success |
| 402 |
contains: |
| 403 |
rule_group: |
| 404 |
description: Details of the rules in the rule group |
| 405 |
type: dict |
| 406 |
returned: success |
| 407 |
contains: |
| 408 |
rule_variables: |
| 409 |
description: Settings that are available for use in the rules in the rule group. |
| 410 |
returned: When rule variables are attached to the rule group. |
| 411 |
type: complex |
| 412 |
contains: |
| 413 |
ip_sets: |
| 414 |
description: A dictionary mapping variable names to IP addresses in CIDR format. |
| 415 |
returned: success |
| 416 |
type: dict |
| 417 |
example: ['192.0.2.0/24'] |
| 418 |
port_sets: |
| 419 |
description: A dictionary mapping variable names to ports |
| 420 |
returned: success |
| 421 |
type: dict |
| 422 |
example: ['42'] |
| 423 |
stateful_rule_options: |
| 424 |
description: Additional options governing how Network Firewall handles stateful rules. |
| 425 |
returned: When the rule group is either "rules string" or "rules list" based. |
| 426 |
type: dict |
| 427 |
contains: |
| 428 |
rule_order: |
| 429 |
description: The order in which rules will be evaluated. |
| 430 |
returned: success |
| 431 |
type: str |
| 432 |
example: 'DEFAULT_ACTION_ORDER' |
| 433 |
rules_source: |
| 434 |
description: Inspection criteria used for a 5-tuple based rule group. |
| 435 |
returned: success |
| 436 |
type: dict |
| 437 |
contains: |
| 438 |
stateful_rules: |
| 439 |
description: A list of dictionaries describing the rules that the rule group is comprised of. |
| 440 |
returned: When the rule group is "rules list" based. |
| 441 |
type: list |
| 442 |
elements: dict |
| 443 |
contains: |
| 444 |
action: |
| 445 |
description: What action to perform when a flow matches the rule criteria. |
| 446 |
returned: success |
| 447 |
type: str |
| 448 |
example: 'PASS' |
| 449 |
header: |
| 450 |
description: A description of the criteria used for the rule. |
| 451 |
returned: success |
| 452 |
type: dict |
| 453 |
contains: |
| 454 |
protocol: |
| 455 |
description: The protocol to inspect for. |
| 456 |
returned: success |
| 457 |
type: str |
| 458 |
example: 'IP' |
| 459 |
source: |
| 460 |
description: The source address or range of addresses to inspect for. |
| 461 |
returned: success |
| 462 |
type: str |
| 463 |
example: '203.0.113.98' |
| 464 |
source_port: |
| 465 |
description: The source port to inspect for. |
| 466 |
returned: success |
| 467 |
type: str |
| 468 |
example: '42' |
| 469 |
destination: |
| 470 |
description: The destination address or range of addresses to inspect for. |
| 471 |
returned: success |
| 472 |
type: str |
| 473 |
example: '198.51.100.0/24' |
| 474 |
destination_port: |
| 475 |
description: The destination port to inspect for. |
| 476 |
returned: success |
| 477 |
type: str |
| 478 |
example: '6666:6667' |
| 479 |
direction: |
| 480 |
description: The direction of traffic flow to inspect. |
| 481 |
returned: success |
| 482 |
type: str |
| 483 |
example: 'FORWARD' |
| 484 |
rule_options: |
| 485 |
description: Additional Suricata RuleOptions settings for the rule. |
| 486 |
returned: success |
| 487 |
type: list |
| 488 |
elements: dict |
| 489 |
contains: |
| 490 |
keyword: |
| 491 |
description: The keyword for the setting. |
| 492 |
returned: success |
| 493 |
type: str |
| 494 |
example: 'sid:1' |
| 495 |
settings: |
| 496 |
description: A list of values passed to the setting. |
| 497 |
returned: When values are available |
| 498 |
type: list |
| 499 |
elements: str |
| 500 |
rules_string: |
| 501 |
description: A string describing the rules that the rule group is comprised of. |
| 502 |
returned: When the rule group is "rules string" based. |
| 503 |
type: str |
| 504 |
rules_source_list: |
| 505 |
description: A description of the criteria for a domain list rule group. |
| 506 |
returned: When the rule group is "domain list" based. |
| 507 |
type: dict |
| 508 |
contains: |
| 509 |
targets: |
| 510 |
description: A list of domain names to be inspected for. |
| 511 |
returned: success |
| 512 |
type: list |
| 513 |
elements: str |
| 514 |
example: ['abc.example.com', '.example.net'] |
| 515 |
target_types: |
| 516 |
description: The protocols to be inspected by the rule group. |
| 517 |
returned: success |
| 518 |
type: list |
| 519 |
elements: str |
| 520 |
example: ['TLS_SNI', 'HTTP_HOST'] |
| 521 |
generated_rules_type: |
| 522 |
description: Whether the rule group allows or denies access to the domains in the list. |
| 523 |
returned: success |
| 524 |
type: str |
| 525 |
example: 'ALLOWLIST' |
| 526 |
stateless_rules_and_custom_actions: |
| 527 |
description: A description of the criteria for a stateless rule group. |
| 528 |
returned: When the rule group is a stateless rule group. |
| 529 |
type: dict |
| 530 |
contains: |
| 531 |
stateless_rules: |
| 532 |
description: A list of stateless rules for use in a stateless rule group. |
| 533 |
type: list |
| 534 |
elements: dict |
| 535 |
contains: |
| 536 |
rule_definition: |
| 537 |
description: Describes the stateless 5-tuple inspection criteria and actions for the rule. |
| 538 |
returned: success |
| 539 |
type: dict |
| 540 |
contains: |
| 541 |
match_attributes: |
| 542 |
description: Describes the stateless 5-tuple inspection criteria for the rule. |
| 543 |
returned: success |
| 544 |
type: dict |
| 545 |
contains: |
| 546 |
sources: |
| 547 |
description: The source IP addresses and address ranges to inspect for. |
| 548 |
returned: success |
| 549 |
type: list |
| 550 |
elements: dict |
| 551 |
contains: |
| 552 |
address_definition: |
| 553 |
description: An IP address or a block of IP addresses in CIDR notation. |
| 554 |
returned: success |
| 555 |
type: str |
| 556 |
example: '192.0.2.3' |
| 557 |
destinations: |
| 558 |
description: The destination IP addresses and address ranges to inspect for. |
| 559 |
returned: success |
| 560 |
type: list |
| 561 |
elements: dict |
| 562 |
contains: |
| 563 |
address_definition: |
| 564 |
description: An IP address or a block of IP addresses in CIDR notation. |
| 565 |
returned: success |
| 566 |
type: str |
| 567 |
example: '192.0.2.3' |
| 568 |
source_ports: |
| 569 |
description: The source port ranges to inspect for. |
| 570 |
returned: success |
| 571 |
type: list |
| 572 |
elements: dict |
| 573 |
contains: |
| 574 |
from_port: |
| 575 |
description: The lower limit of the port range. |
| 576 |
returned: success |
| 577 |
type: int |
| 578 |
to_port: |
| 579 |
description: The upper limit of the port range. |
| 580 |
returned: success |
| 581 |
type: int |
| 582 |
destination_ports: |
| 583 |
description: The destination port ranges to inspect for. |
| 584 |
returned: success |
| 585 |
type: list |
| 586 |
elements: dict |
| 587 |
contains: |
| 588 |
from_port: |
| 589 |
description: The lower limit of the port range. |
| 590 |
returned: success |
| 591 |
type: int |
| 592 |
to_port: |
| 593 |
description: The upper limit of the port range. |
| 594 |
returned: success |
| 595 |
type: int |
| 596 |
protocols: |
| 597 |
description: The IANA protocol numbers of the protocols to inspect for. |
| 598 |
returned: success |
| 599 |
type: list |
| 600 |
elements: int |
| 601 |
example: [6] |
| 602 |
tcp_flags: |
| 603 |
description: The TCP flags and masks to inspect for. |
| 604 |
returned: success |
| 605 |
type: list |
| 606 |
elements: dict |
| 607 |
contains: |
| 608 |
flags: |
| 609 |
description: Used with masks to define the TCP flags that flows are inspected for. |
| 610 |
returned: success |
| 611 |
type: list |
| 612 |
elements: str |
| 613 |
masks: |
| 614 |
description: The set of flags considered during inspection. |
| 615 |
returned: success |
| 616 |
type: list |
| 617 |
elements: str |
| 618 |
actions: |
| 619 |
description: The actions to take when a flow matches the rule. |
| 620 |
returned: success |
| 621 |
type: list |
| 622 |
elements: str |
| 623 |
example: ['aws:pass', 'CustomActionName'] |
| 624 |
priority: |
| 625 |
description: Indicates the order in which to run this rule relative to all of the rules that are defined for a stateless rule group. |
| 626 |
returned: success |
| 627 |
type: int |
| 628 |
custom_actions: |
| 629 |
description: A list of individual custom action definitions that are available for use in stateless rules. |
| 630 |
type: list |
| 631 |
elements: dict |
| 632 |
contains: |
| 633 |
action_name: |
| 634 |
description: The name for the custom action. |
| 635 |
returned: success |
| 636 |
type: str |
| 637 |
action_definition: |
| 638 |
description: The custom action associated with the action name. |
| 639 |
returned: success |
| 640 |
type: dict |
| 641 |
contains: |
| 642 |
publish_metric_action: |
| 643 |
description: The description of an action which publishes to CloudWatch. |
| 644 |
returned: When the action publishes to CloudWatch. |
| 645 |
type: dict |
| 646 |
contains: |
| 647 |
dimensions: |
| 648 |
description: The value to use in an Amazon CloudWatch custom metric dimension. |
| 649 |
returned: success |
| 650 |
type: list |
| 651 |
elements: dict |
| 652 |
contains: |
| 653 |
value: |
| 654 |
description: The value to use in the custom metric dimension. |
| 655 |
returned: success |
| 656 |
type: str |
| 657 |
rule_group_metadata: |
| 658 |
description: Details of the rules in the rule group |
| 659 |
type: dict |
| 660 |
returned: success |
| 661 |
contains: |
| 662 |
capacity: |
| 663 |
description: The maximum operating resources that this rule group can use. |
| 664 |
type: int |
| 665 |
returned: success |
| 666 |
consumed_capacity: |
| 667 |
description: The number of capacity units currently consumed by the rule group rules. |
| 668 |
type: int |
| 669 |
returned: success |
| 670 |
description: |
| 671 |
description: A description of the rule group. |
| 672 |
type: str |
| 673 |
returned: success |
| 674 |
number_of_associations: |
| 675 |
description: The number of firewall policies that use this rule group. |
| 676 |
type: int |
| 677 |
returned: success |
| 678 |
rule_group_arn: |
| 679 |
description: The ARN for the rule group |
| 680 |
type: int |
| 681 |
returned: success |
| 682 |
example: 'arn:aws:network-firewall:us-east-1:123456789012:stateful-rulegroup/ExampleGroup' |
| 683 |
rule_group_id: |
| 684 |
description: A unique identifier for the rule group. |
| 685 |
type: int |
| 686 |
returned: success |
| 687 |
example: '12345678-abcd-1234-abcd-123456789abc' |
| 688 |
rule_group_name: |
| 689 |
description: The name of the rule group. |
| 690 |
type: str |
| 691 |
returned: success |
| 692 |
rule_group_status: |
| 693 |
description: The current status of a rule group. |
| 694 |
type: str |
| 695 |
returned: success |
| 696 |
example: 'DELETING' |
| 697 |
tags: |
| 698 |
description: A dictionary representing the tags associated with the rule group. |
| 699 |
type: dict |
| 700 |
returned: success |
| 701 |
type: |
| 702 |
description: Whether the rule group is stateless or stateful. |
| 703 |
type: str |
| 704 |
returned: success |
| 705 |
example: 'STATEFUL' |
| 706 |
""" |
| 707 |
|
| 708 |
from ansible_collections.community.aws.plugins.module_utils.modules import AnsibleCommunityAWSModule as AnsibleAWSModule |
| 709 |
from ansible_collections.community.aws.plugins.module_utils.networkfirewall import NetworkFirewallRuleManager |
| 710 |
|
| 711 |
|
| 712 |
def main(): |
| 713 |
domain_list_spec = dict( |
| 714 |
domain_names=dict(type="list", elements="str", required=True), |
| 715 |
filter_http=dict(type="bool", required=False, default=False), |
| 716 |
filter_https=dict(type="bool", required=False, default=False), |
| 717 |
action=dict(type="str", required=True, choices=["allow", "deny"]), |
| 718 |
source_ips=dict(type="list", elements="str", required=False), |
| 719 |
) |
| 720 |
|
| 721 |
rule_list_spec = dict( |
| 722 |
action=dict(type="str", required=True, choices=["pass", "drop", "alert"]), |
| 723 |
protocol=dict(type="str", required=True), |
| 724 |
source=dict(type="str", required=True), |
| 725 |
source_port=dict(type="str", required=True), |
| 726 |
direction=dict(type="str", required=False, default="forward", choices=["forward", "any"]), |
| 727 |
destination=dict(type="str", required=True), |
| 728 |
destination_port=dict(type="str", required=True), |
| 729 |
sid=dict(type="int", required=True), |
| 730 |
rule_options=dict(type="dict", required=False), |
| 731 |
) |
| 732 |
|
| 733 |
argument_spec = dict( |
| 734 |
arn=dict(type="str", required=False), |
| 735 |
name=dict(type="str", required=False), |
| 736 |
rule_type=dict(type="str", required=False, aliases=["type"], choices=["stateful"]), |
| 737 |
# rule_type=dict(type='str', required=True, aliases=['type'], choices=['stateless', 'stateful']), |
| 738 |
state=dict(type="str", required=False, choices=["present", "absent"], default="present"), |
| 739 |
capacity=dict(type="int", required=False), |
| 740 |
rule_order=dict(type="str", required=False, aliases=["stateful_rule_order"], choices=["default", "strict"]), |
| 741 |
description=dict(type="str", required=False), |
| 742 |
ip_variables=dict(type="dict", required=False, aliases=["ip_set_variables"]), |
| 743 |
purge_ip_variables=dict(type="bool", required=False, aliases=["purge_ip_set_variables"], default=True), |
| 744 |
port_variables=dict(type="dict", required=False, aliases=["port_set_variables"]), |
| 745 |
purge_port_variables=dict(type="bool", required=False, aliases=["purge_port_set_variables"], default=True), |
| 746 |
rule_strings=dict(type="list", elements="str", required=False), |
| 747 |
domain_list=dict(type="dict", options=domain_list_spec, required=False), |
| 748 |
rule_list=dict( |
| 749 |
type="list", elements="dict", aliases=["stateful_rule_list"], options=rule_list_spec, required=False |
| 750 |
), |
| 751 |
tags=dict(type="dict", required=False, aliases=["resource_tags"]), |
| 752 |
purge_tags=dict(type="bool", required=False, default=True), |
| 753 |
wait=dict(type="bool", required=False, default=True), |
| 754 |
wait_timeout=dict(type="int", required=False), |
| 755 |
) |
| 756 |
|
| 757 |
module = AnsibleAWSModule( |
| 758 |
argument_spec=argument_spec, |
| 759 |
supports_check_mode=True, |
| 760 |
mutually_exclusive=[ |
| 761 |
["name", "arn"], |
| 762 |
["rule_strings", "domain_list", "rule_list"], |
| 763 |
["domain_list", "ip_variables"], |
| 764 |
], |
| 765 |
required_together=[ |
| 766 |
["name", "rule_type"], |
| 767 |
], |
| 768 |
required_one_of=[ |
| 769 |
["name", "arn"], |
| 770 |
], |
| 771 |
) |
| 772 |
|
| 773 |
state = module.params.get("state") |
| 774 |
name = module.params.get("name") |
| 775 |
arn = module.params.get("arn") |
| 776 |
rule_type = module.params.get("rule_type") |
| 777 |
|
| 778 |
if rule_type == "stateless": |
| 779 |
if module.params.get("rule_order"): |
| 780 |
module.fail_json("rule_order can not be set for stateless rule groups") |
| 781 |
if module.params.get("rule_strings"): |
| 782 |
module.fail_json("rule_strings can only be used for stateful rule groups") |
| 783 |
if module.params.get("rule_list"): |
| 784 |
module.fail_json("rule_list can only be used for stateful rule groups") |
| 785 |
if module.params.get("domain_list"): |
| 786 |
module.fail_json("domain_list can only be used for stateful rule groups") |
| 787 |
|
| 788 |
manager = NetworkFirewallRuleManager(module, arn=arn, name=name, rule_type=rule_type) |
| 789 |
manager.set_wait(module.params.get("wait", None)) |
| 790 |
manager.set_wait_timeout(module.params.get("wait_timeout", None)) |
| 791 |
|
| 792 |
if state == "absent": |
| 793 |
manager.delete() |
| 794 |
else: |
| 795 |
manager.set_description(module.params.get("description")) |
| 796 |
manager.set_capacity(module.params.get("capacity")) |
| 797 |
manager.set_rule_order(module.params.get("rule_order")) |
| 798 |
manager.set_ip_variables(module.params.get("ip_variables"), module.params.get("purge_ip_variables")) |
| 799 |
manager.set_port_variables(module.params.get("port_variables"), module.params.get("purge_port_variables")) |
| 800 |
manager.set_rule_string(module.params.get("rule_strings")) |
| 801 |
manager.set_domain_list(module.params.get("domain_list")) |
| 802 |
manager.set_rule_list(module.params.get("rule_list")) |
| 803 |
manager.set_tags(module.params.get("tags"), module.params.get("purge_tags")) |
| 804 |
|
| 805 |
manager.flush_changes() |
| 806 |
|
| 807 |
results = dict( |
| 808 |
changed=manager.changed, |
| 809 |
rule_group=manager.updated_resource, |
| 810 |
) |
| 811 |
if manager.changed: |
| 812 |
diff = dict( |
| 813 |
before=manager.original_resource, |
| 814 |
after=manager.updated_resource, |
| 815 |
) |
| 816 |
results["diff"] = diff |
| 817 |
module.exit_json(**results) |
| 818 |
|
| 819 |
|
| 820 |
if __name__ == "__main__": |
| 821 |
main() |