| 1 |
--- |
| 2 |
- name: 'aws_waf_web_acl integration tests' |
| 3 |
collections: |
| 4 |
- amazon.aws |
| 5 |
module_defaults: |
| 6 |
group/aws: |
| 7 |
access_key: '{{ aws_access_key }}' |
| 8 |
secret_key: '{{ aws_secret_key }}' |
| 9 |
session_token: '{{ security_token | default(omit) }}' |
| 10 |
region: '{{ aws_region }}' |
| 11 |
block: |
| 12 |
|
| 13 |
################################################## |
| 14 |
# aws_waf_condition tests |
| 15 |
################################################## |
| 16 |
|
| 17 |
- name: create WAF IP condition |
| 18 |
waf_condition: |
| 19 |
name: "{{ resource_prefix }}_ip_condition" |
| 20 |
filters: |
| 21 |
- ip_address: "10.0.0.0/8" |
| 22 |
type: ip |
| 23 |
register: create_waf_ip_condition |
| 24 |
|
| 25 |
- name: add an IP address to WAF condition |
| 26 |
waf_condition: |
| 27 |
name: "{{ resource_prefix }}_ip_condition" |
| 28 |
filters: |
| 29 |
- ip_address: "10.0.0.0/8" |
| 30 |
- ip_address: "192.168.0.0/24" |
| 31 |
type: ip |
| 32 |
register: add_ip_address_to_waf_condition |
| 33 |
|
| 34 |
- name: check expected waf filter length |
| 35 |
assert: |
| 36 |
that: |
| 37 |
- add_ip_address_to_waf_condition.condition.ip_set_descriptors|length == 2 |
| 38 |
|
| 39 |
- name: add an IP address to WAF condition (rely on purge_filters defaulting to false) |
| 40 |
waf_condition: |
| 41 |
name: "{{ resource_prefix }}_ip_condition" |
| 42 |
filters: |
| 43 |
- ip_address: "192.168.10.0/24" |
| 44 |
type: ip |
| 45 |
register: add_ip_address_to_waf_condition_no_purge |
| 46 |
|
| 47 |
- name: check waf filter length has increased |
| 48 |
assert: |
| 49 |
that: |
| 50 |
- add_ip_address_to_waf_condition_no_purge.condition.ip_set_descriptors|length == 3 |
| 51 |
- add_ip_address_to_waf_condition_no_purge.changed |
| 52 |
|
| 53 |
- name: add an IP address to WAF condition (set purge_filters) |
| 54 |
waf_condition: |
| 55 |
name: "{{ resource_prefix }}_ip_condition" |
| 56 |
filters: |
| 57 |
- ip_address: "192.168.20.0/24" |
| 58 |
purge_filters: yes |
| 59 |
type: ip |
| 60 |
register: add_ip_address_to_waf_condition_purge |
| 61 |
|
| 62 |
- name: check waf filter length has reduced |
| 63 |
assert: |
| 64 |
that: |
| 65 |
- add_ip_address_to_waf_condition_purge.condition.ip_set_descriptors|length == 1 |
| 66 |
- add_ip_address_to_waf_condition_purge.changed |
| 67 |
|
| 68 |
- name: create WAF byte condition |
| 69 |
waf_condition: |
| 70 |
name: "{{ resource_prefix }}_byte_condition" |
| 71 |
filters: |
| 72 |
- field_to_match: header |
| 73 |
position: STARTS_WITH |
| 74 |
target_string: Hello |
| 75 |
header: Content-type |
| 76 |
type: byte |
| 77 |
register: create_waf_byte_condition |
| 78 |
|
| 79 |
- name: recreate WAF byte condition |
| 80 |
waf_condition: |
| 81 |
name: "{{ resource_prefix }}_byte_condition" |
| 82 |
filters: |
| 83 |
- field_to_match: header |
| 84 |
position: STARTS_WITH |
| 85 |
target_string: Hello |
| 86 |
header: Content-type |
| 87 |
type: byte |
| 88 |
register: recreate_waf_byte_condition |
| 89 |
|
| 90 |
- name: assert that no change was made |
| 91 |
assert: |
| 92 |
that: |
| 93 |
- not recreate_waf_byte_condition.changed |
| 94 |
|
| 95 |
- name: create WAF geo condition |
| 96 |
waf_condition: |
| 97 |
name: "{{ resource_prefix }}_geo_condition" |
| 98 |
filters: |
| 99 |
- country: US |
| 100 |
- country: AU |
| 101 |
- country: AT |
| 102 |
type: geo |
| 103 |
register: create_waf_geo_condition |
| 104 |
|
| 105 |
- name: create WAF size condition |
| 106 |
waf_condition: |
| 107 |
name: "{{ resource_prefix }}_size_condition" |
| 108 |
filters: |
| 109 |
- field_to_match: query_string |
| 110 |
size: 300 |
| 111 |
comparison: GT |
| 112 |
type: size |
| 113 |
register: create_waf_size_condition |
| 114 |
|
| 115 |
- name: create WAF sql condition |
| 116 |
waf_condition: |
| 117 |
name: "{{ resource_prefix }}_sql_condition" |
| 118 |
filters: |
| 119 |
- field_to_match: query_string |
| 120 |
transformation: url_decode |
| 121 |
type: sql |
| 122 |
register: create_waf_sql_condition |
| 123 |
|
| 124 |
- name: create WAF xss condition |
| 125 |
waf_condition: |
| 126 |
name: "{{ resource_prefix }}_xss_condition" |
| 127 |
filters: |
| 128 |
- field_to_match: query_string |
| 129 |
transformation: url_decode |
| 130 |
type: xss |
| 131 |
register: create_waf_xss_condition |
| 132 |
|
| 133 |
- name: create WAF regex condition |
| 134 |
waf_condition: |
| 135 |
name: "{{ resource_prefix }}_regex_condition" |
| 136 |
filters: |
| 137 |
- field_to_match: query_string |
| 138 |
regex_pattern: |
| 139 |
name: greetings |
| 140 |
regex_strings: |
| 141 |
- '[hH]ello' |
| 142 |
- '^Hi there' |
| 143 |
- '.*Good Day to You' |
| 144 |
type: regex |
| 145 |
register: create_waf_regex_condition |
| 146 |
|
| 147 |
- name: create a second WAF regex condition with the same regex |
| 148 |
waf_condition: |
| 149 |
name: "{{ resource_prefix }}_regex_condition_part_2" |
| 150 |
filters: |
| 151 |
- field_to_match: header |
| 152 |
header: cookie |
| 153 |
regex_pattern: |
| 154 |
name: greetings |
| 155 |
regex_strings: |
| 156 |
- '[hH]ello' |
| 157 |
- '^Hi there' |
| 158 |
- '.*Good Day to You' |
| 159 |
type: regex |
| 160 |
register: create_second_waf_regex_condition |
| 161 |
|
| 162 |
- name: check that the pattern is shared |
| 163 |
assert: |
| 164 |
that: |
| 165 |
- > |
| 166 |
create_waf_regex_condition.condition.regex_match_tuples[0].regex_pattern_set_id == |
| 167 |
create_second_waf_regex_condition.condition.regex_match_tuples[0].regex_pattern_set_id |
| 168 |
- create_second_waf_regex_condition.changed |
| 169 |
|
| 170 |
|
| 171 |
- name: delete first WAF regex condition |
| 172 |
waf_condition: |
| 173 |
name: "{{ resource_prefix }}_regex_condition" |
| 174 |
filters: |
| 175 |
- field_to_match: query_string |
| 176 |
regex_pattern: |
| 177 |
name: greetings |
| 178 |
regex_strings: |
| 179 |
- '[hH]ello' |
| 180 |
- '^Hi there' |
| 181 |
- '.*Good Day to You' |
| 182 |
type: regex |
| 183 |
state: absent |
| 184 |
register: delete_waf_regex_condition |
| 185 |
|
| 186 |
- name: delete second WAF regex condition |
| 187 |
waf_condition: |
| 188 |
name: "{{ resource_prefix }}_regex_condition_part_2" |
| 189 |
filters: |
| 190 |
- field_to_match: header |
| 191 |
header: cookie |
| 192 |
regex_pattern: |
| 193 |
name: greetings |
| 194 |
regex_strings: |
| 195 |
- '[hH]ello' |
| 196 |
- '^Hi there' |
| 197 |
- '.*Good Day to You' |
| 198 |
type: regex |
| 199 |
state: absent |
| 200 |
register: delete_second_waf_regex_condition |
| 201 |
|
| 202 |
- name: create WAF regex condition |
| 203 |
waf_condition: |
| 204 |
name: "{{ resource_prefix }}_regex_condition" |
| 205 |
filters: |
| 206 |
- field_to_match: query_string |
| 207 |
regex_pattern: |
| 208 |
name: greetings |
| 209 |
regex_strings: |
| 210 |
- '[hH]ello' |
| 211 |
- '^Hi there' |
| 212 |
- '.*Good Day to You' |
| 213 |
type: regex |
| 214 |
register: recreate_waf_regex_condition |
| 215 |
|
| 216 |
- name: check that a new pattern is created (because the first pattern should have been deleted once unused) |
| 217 |
assert: |
| 218 |
that: |
| 219 |
- > |
| 220 |
recreate_waf_regex_condition.condition.regex_match_tuples[0].regex_pattern_set_id != |
| 221 |
create_waf_regex_condition.condition.regex_match_tuples[0].regex_pattern_set_id |
| 222 |
|
| 223 |
- name: create WAF Regional IP condition |
| 224 |
waf_condition: |
| 225 |
name: "{{ resource_prefix }}_ip_condition" |
| 226 |
filters: |
| 227 |
- ip_address: "10.0.0.0/8" |
| 228 |
type: ip |
| 229 |
region: "{{ aws_region }}" |
| 230 |
waf_regional: true |
| 231 |
register: create_waf_regional_ip_condition |
| 232 |
|
| 233 |
- name: add an IP address to WAF Regional condition |
| 234 |
waf_condition: |
| 235 |
name: "{{ resource_prefix }}_ip_condition" |
| 236 |
filters: |
| 237 |
- ip_address: "10.0.0.0/8" |
| 238 |
- ip_address: "192.168.0.0/24" |
| 239 |
type: ip |
| 240 |
region: "{{ aws_region }}" |
| 241 |
waf_regional: true |
| 242 |
register: add_ip_address_to_waf_regional_condition |
| 243 |
|
| 244 |
- name: check expected WAF Regional filter length |
| 245 |
assert: |
| 246 |
that: |
| 247 |
- add_ip_address_to_waf_regional_condition.condition.ip_set_descriptors|length == 2 |
| 248 |
|
| 249 |
- name: add an IP address to WAF Regional condition (rely on purge_filters defaulting to false) |
| 250 |
waf_condition: |
| 251 |
name: "{{ resource_prefix }}_ip_condition" |
| 252 |
filters: |
| 253 |
- ip_address: "192.168.10.0/24" |
| 254 |
type: ip |
| 255 |
region: "{{ aws_region }}" |
| 256 |
waf_regional: true |
| 257 |
register: add_ip_address_to_waf_regional_condition_no_purge |
| 258 |
|
| 259 |
- name: check WAF Regional filter length has increased |
| 260 |
assert: |
| 261 |
that: |
| 262 |
- add_ip_address_to_waf_regional_condition_no_purge.condition.ip_set_descriptors|length == 3 |
| 263 |
- add_ip_address_to_waf_regional_condition_no_purge.changed |
| 264 |
|
| 265 |
- name: add an IP address to WAF Regional condition (set purge_filters) |
| 266 |
waf_condition: |
| 267 |
name: "{{ resource_prefix }}_ip_condition" |
| 268 |
filters: |
| 269 |
- ip_address: "192.168.20.0/24" |
| 270 |
purge_filters: yes |
| 271 |
type: ip |
| 272 |
region: "{{ aws_region }}" |
| 273 |
waf_regional: true |
| 274 |
register: add_ip_address_to_waf_regional_condition_purge |
| 275 |
|
| 276 |
- name: check WAF Regional filter length has reduced |
| 277 |
assert: |
| 278 |
that: |
| 279 |
- add_ip_address_to_waf_regional_condition_purge.condition.ip_set_descriptors|length == 1 |
| 280 |
- add_ip_address_to_waf_regional_condition_purge.changed |
| 281 |
|
| 282 |
- name: create WAF Regional byte condition |
| 283 |
waf_condition: |
| 284 |
name: "{{ resource_prefix }}_byte_condition" |
| 285 |
filters: |
| 286 |
- field_to_match: header |
| 287 |
position: STARTS_WITH |
| 288 |
target_string: Hello |
| 289 |
header: Content-type |
| 290 |
type: byte |
| 291 |
region: "{{ aws_region }}" |
| 292 |
waf_regional: true |
| 293 |
register: create_waf_regional_byte_condition |
| 294 |
|
| 295 |
- name: recreate WAF Regional byte condition |
| 296 |
waf_condition: |
| 297 |
name: "{{ resource_prefix }}_byte_condition" |
| 298 |
filters: |
| 299 |
- field_to_match: header |
| 300 |
position: STARTS_WITH |
| 301 |
target_string: Hello |
| 302 |
header: Content-type |
| 303 |
type: byte |
| 304 |
region: "{{ aws_region }}" |
| 305 |
waf_regional: true |
| 306 |
register: recreate_waf_regional_byte_condition |
| 307 |
|
| 308 |
- name: assert that no change was made |
| 309 |
assert: |
| 310 |
that: |
| 311 |
- not recreate_waf_regional_byte_condition.changed |
| 312 |
|
| 313 |
- name: create WAF Regional geo condition |
| 314 |
waf_condition: |
| 315 |
name: "{{ resource_prefix }}_geo_condition" |
| 316 |
filters: |
| 317 |
- country: US |
| 318 |
- country: AU |
| 319 |
- country: AT |
| 320 |
type: geo |
| 321 |
region: "{{ aws_region }}" |
| 322 |
waf_regional: true |
| 323 |
register: create_waf_regional_geo_condition |
| 324 |
|
| 325 |
- name: create WAF Regional size condition |
| 326 |
waf_condition: |
| 327 |
name: "{{ resource_prefix }}_size_condition" |
| 328 |
filters: |
| 329 |
- field_to_match: query_string |
| 330 |
size: 300 |
| 331 |
comparison: GT |
| 332 |
type: size |
| 333 |
region: "{{ aws_region }}" |
| 334 |
waf_regional: true |
| 335 |
register: create_waf_regional_size_condition |
| 336 |
|
| 337 |
- name: create WAF Regional sql condition |
| 338 |
waf_condition: |
| 339 |
name: "{{ resource_prefix }}_sql_condition" |
| 340 |
filters: |
| 341 |
- field_to_match: query_string |
| 342 |
transformation: url_decode |
| 343 |
type: sql |
| 344 |
region: "{{ aws_region }}" |
| 345 |
waf_regional: true |
| 346 |
register: create_waf_regional_sql_condition |
| 347 |
|
| 348 |
- name: create WAF Regional xss condition |
| 349 |
waf_condition: |
| 350 |
name: "{{ resource_prefix }}_xss_condition" |
| 351 |
filters: |
| 352 |
- field_to_match: query_string |
| 353 |
transformation: url_decode |
| 354 |
type: xss |
| 355 |
region: "{{ aws_region }}" |
| 356 |
waf_regional: true |
| 357 |
register: create_waf_regional_xss_condition |
| 358 |
|
| 359 |
- name: create WAF Regional regex condition |
| 360 |
waf_condition: |
| 361 |
name: "{{ resource_prefix }}_regex_condition" |
| 362 |
filters: |
| 363 |
- field_to_match: query_string |
| 364 |
regex_pattern: |
| 365 |
name: greetings |
| 366 |
regex_strings: |
| 367 |
- '[hH]ello' |
| 368 |
- '^Hi there' |
| 369 |
- '.*Good Day to You' |
| 370 |
type: regex |
| 371 |
region: "{{ aws_region }}" |
| 372 |
waf_regional: true |
| 373 |
register: create_waf_regional_regex_condition |
| 374 |
|
| 375 |
- name: create a second WAF Regional regex condition with the same regex |
| 376 |
waf_condition: |
| 377 |
name: "{{ resource_prefix }}_regex_condition_part_2" |
| 378 |
filters: |
| 379 |
- field_to_match: header |
| 380 |
header: cookie |
| 381 |
regex_pattern: |
| 382 |
name: greetings |
| 383 |
regex_strings: |
| 384 |
- '[hH]ello' |
| 385 |
- '^Hi there' |
| 386 |
- '.*Good Day to You' |
| 387 |
type: regex |
| 388 |
region: "{{ aws_region }}" |
| 389 |
waf_regional: true |
| 390 |
register: create_second_waf_regional_regex_condition |
| 391 |
|
| 392 |
- name: check that the pattern is shared |
| 393 |
assert: |
| 394 |
that: |
| 395 |
- > |
| 396 |
create_waf_regional_regex_condition.condition.regex_match_tuples[0].regex_pattern_set_id == |
| 397 |
create_second_waf_regional_regex_condition.condition.regex_match_tuples[0].regex_pattern_set_id |
| 398 |
- create_second_waf_regional_regex_condition.changed |
| 399 |
|
| 400 |
|
| 401 |
- name: delete first WAF Regional regex condition |
| 402 |
waf_condition: |
| 403 |
name: "{{ resource_prefix }}_regex_condition" |
| 404 |
filters: |
| 405 |
- field_to_match: query_string |
| 406 |
regex_pattern: |
| 407 |
name: greetings |
| 408 |
regex_strings: |
| 409 |
- '[hH]ello' |
| 410 |
- '^Hi there' |
| 411 |
- '.*Good Day to You' |
| 412 |
type: regex |
| 413 |
state: absent |
| 414 |
region: "{{ aws_region }}" |
| 415 |
waf_regional: true |
| 416 |
register: delete_waf_regional_regex_condition |
| 417 |
|
| 418 |
- name: delete second WAF Regional regex condition |
| 419 |
waf_condition: |
| 420 |
name: "{{ resource_prefix }}_regex_condition_part_2" |
| 421 |
filters: |
| 422 |
- field_to_match: header |
| 423 |
header: cookie |
| 424 |
regex_pattern: |
| 425 |
name: greetings |
| 426 |
regex_strings: |
| 427 |
- '[hH]ello' |
| 428 |
- '^Hi there' |
| 429 |
- '.*Good Day to You' |
| 430 |
type: regex |
| 431 |
state: absent |
| 432 |
region: "{{ aws_region }}" |
| 433 |
waf_regional: true |
| 434 |
register: delete_second_waf_regional_regex_condition |
| 435 |
|
| 436 |
- name: create WAF Regional regex condition |
| 437 |
waf_condition: |
| 438 |
name: "{{ resource_prefix }}_regex_condition" |
| 439 |
filters: |
| 440 |
- field_to_match: query_string |
| 441 |
regex_pattern: |
| 442 |
name: greetings |
| 443 |
regex_strings: |
| 444 |
- '[hH]ello' |
| 445 |
- '^Hi there' |
| 446 |
- '.*Good Day to You' |
| 447 |
type: regex |
| 448 |
region: "{{ aws_region }}" |
| 449 |
waf_regional: true |
| 450 |
register: recreate_waf_regional_regex_condition |
| 451 |
|
| 452 |
- name: check that a new pattern is created (because the first pattern should have been deleted once unused) |
| 453 |
assert: |
| 454 |
that: |
| 455 |
- > |
| 456 |
recreate_waf_regional_regex_condition.condition.regex_match_tuples[0].regex_pattern_set_id != |
| 457 |
create_waf_regional_regex_condition.condition.regex_match_tuples[0].regex_pattern_set_id |
| 458 |
|
| 459 |
################################################## |
| 460 |
# aws_waf_rule tests |
| 461 |
################################################## |
| 462 |
|
| 463 |
- name: create WAF rule |
| 464 |
waf_rule: |
| 465 |
name: "{{ resource_prefix }}_rule" |
| 466 |
conditions: |
| 467 |
- name: "{{ resource_prefix }}_regex_condition" |
| 468 |
type: regex |
| 469 |
negated: no |
| 470 |
- name: "{{ resource_prefix }}_geo_condition" |
| 471 |
type: geo |
| 472 |
negated: no |
| 473 |
- name: "{{ resource_prefix }}_byte_condition" |
| 474 |
type: byte |
| 475 |
negated: no |
| 476 |
purge_conditions: yes |
| 477 |
register: create_aws_waf_rule |
| 478 |
|
| 479 |
- name: check WAF rule |
| 480 |
assert: |
| 481 |
that: |
| 482 |
- create_aws_waf_rule.changed |
| 483 |
- create_aws_waf_rule.rule.predicates|length == 3 |
| 484 |
|
| 485 |
- name: recreate WAF rule |
| 486 |
waf_rule: |
| 487 |
name: "{{ resource_prefix }}_rule" |
| 488 |
conditions: |
| 489 |
- name: "{{ resource_prefix }}_regex_condition" |
| 490 |
type: regex |
| 491 |
negated: no |
| 492 |
- name: "{{ resource_prefix }}_geo_condition" |
| 493 |
type: geo |
| 494 |
negated: no |
| 495 |
- name: "{{ resource_prefix }}_byte_condition" |
| 496 |
type: byte |
| 497 |
negated: no |
| 498 |
register: create_aws_waf_rule |
| 499 |
|
| 500 |
- name: check WAF rule did not change |
| 501 |
assert: |
| 502 |
that: |
| 503 |
- not create_aws_waf_rule.changed |
| 504 |
- create_aws_waf_rule.rule.predicates|length == 3 |
| 505 |
|
| 506 |
- name: add further WAF rules relying on purge_conditions defaulting to false |
| 507 |
waf_rule: |
| 508 |
name: "{{ resource_prefix }}_rule" |
| 509 |
conditions: |
| 510 |
- name: "{{ resource_prefix }}_ip_condition" |
| 511 |
type: ip |
| 512 |
negated: yes |
| 513 |
- name: "{{ resource_prefix }}_sql_condition" |
| 514 |
type: sql |
| 515 |
negated: no |
| 516 |
- name: "{{ resource_prefix }}_xss_condition" |
| 517 |
type: xss |
| 518 |
negated: no |
| 519 |
register: add_conditions_to_aws_waf_rule |
| 520 |
|
| 521 |
- name: check WAF rule added rules |
| 522 |
assert: |
| 523 |
that: |
| 524 |
- add_conditions_to_aws_waf_rule.changed |
| 525 |
- add_conditions_to_aws_waf_rule.rule.predicates|length == 6 |
| 526 |
|
| 527 |
- name: remove some rules through purging conditions |
| 528 |
waf_rule: |
| 529 |
name: "{{ resource_prefix }}_rule" |
| 530 |
conditions: |
| 531 |
- name: "{{ resource_prefix }}_ip_condition" |
| 532 |
type: ip |
| 533 |
negated: yes |
| 534 |
- name: "{{ resource_prefix }}_xss_condition" |
| 535 |
type: xss |
| 536 |
negated: no |
| 537 |
- name: "{{ resource_prefix }}_byte_condition" |
| 538 |
type: byte |
| 539 |
negated: no |
| 540 |
- name: "{{ resource_prefix }}_size_condition" |
| 541 |
type: size |
| 542 |
negated: no |
| 543 |
purge_conditions: yes |
| 544 |
register: add_and_remove_waf_rule_conditions |
| 545 |
|
| 546 |
- name: check WAF rules were updated as expected |
| 547 |
assert: |
| 548 |
that: |
| 549 |
- add_and_remove_waf_rule_conditions.changed |
| 550 |
- add_and_remove_waf_rule_conditions.rule.predicates|length == 4 |
| 551 |
|
| 552 |
- name: attempt to remove an in use condition |
| 553 |
waf_condition: |
| 554 |
name: "{{ resource_prefix }}_size_condition" |
| 555 |
type: size |
| 556 |
state: absent |
| 557 |
ignore_errors: yes |
| 558 |
register: remove_in_use_condition |
| 559 |
|
| 560 |
- name: check failure was sensible |
| 561 |
assert: |
| 562 |
that: |
| 563 |
- remove_in_use_condition.failed |
| 564 |
- "'Condition ' ~ resource_prefix ~ '_size_condition is in use' in remove_in_use_condition.msg" |
| 565 |
|
| 566 |
- name: create WAF Regional rule |
| 567 |
waf_rule: |
| 568 |
name: "{{ resource_prefix }}_rule" |
| 569 |
conditions: |
| 570 |
- name: "{{ resource_prefix }}_regex_condition" |
| 571 |
type: regex |
| 572 |
negated: no |
| 573 |
- name: "{{ resource_prefix }}_geo_condition" |
| 574 |
type: geo |
| 575 |
negated: no |
| 576 |
- name: "{{ resource_prefix }}_byte_condition" |
| 577 |
type: byte |
| 578 |
negated: no |
| 579 |
purge_conditions: yes |
| 580 |
region: "{{ aws_region }}" |
| 581 |
waf_regional: true |
| 582 |
register: create_aws_waf_regional_rule |
| 583 |
|
| 584 |
- name: check WAF Regional rule |
| 585 |
assert: |
| 586 |
that: |
| 587 |
- create_aws_waf_regional_rule.changed |
| 588 |
- create_aws_waf_regional_rule.rule.predicates|length == 3 |
| 589 |
|
| 590 |
- name: recreate WAF Regional rule |
| 591 |
waf_rule: |
| 592 |
name: "{{ resource_prefix }}_rule" |
| 593 |
conditions: |
| 594 |
- name: "{{ resource_prefix }}_regex_condition" |
| 595 |
type: regex |
| 596 |
negated: no |
| 597 |
- name: "{{ resource_prefix }}_geo_condition" |
| 598 |
type: geo |
| 599 |
negated: no |
| 600 |
- name: "{{ resource_prefix }}_byte_condition" |
| 601 |
type: byte |
| 602 |
negated: no |
| 603 |
region: "{{ aws_region }}" |
| 604 |
waf_regional: true |
| 605 |
register: create_aws_waf_regional_rule |
| 606 |
|
| 607 |
- name: check WAF Regional rule did not change |
| 608 |
assert: |
| 609 |
that: |
| 610 |
- not create_aws_waf_regional_rule.changed |
| 611 |
- create_aws_waf_regional_rule.rule.predicates|length == 3 |
| 612 |
|
| 613 |
- name: add further WAF Regional rules relying on purge_conditions defaulting to false |
| 614 |
waf_rule: |
| 615 |
name: "{{ resource_prefix }}_rule" |
| 616 |
conditions: |
| 617 |
- name: "{{ resource_prefix }}_ip_condition" |
| 618 |
type: ip |
| 619 |
negated: yes |
| 620 |
- name: "{{ resource_prefix }}_sql_condition" |
| 621 |
type: sql |
| 622 |
negated: no |
| 623 |
- name: "{{ resource_prefix }}_xss_condition" |
| 624 |
type: xss |
| 625 |
negated: no |
| 626 |
region: "{{ aws_region }}" |
| 627 |
waf_regional: true |
| 628 |
register: add_conditions_to_aws_waf_regional_rule |
| 629 |
|
| 630 |
- name: check WAF Regional rule added rules |
| 631 |
assert: |
| 632 |
that: |
| 633 |
- add_conditions_to_aws_waf_regional_rule.changed |
| 634 |
- add_conditions_to_aws_waf_regional_rule.rule.predicates|length == 6 |
| 635 |
|
| 636 |
- name: remove some rules through purging conditions |
| 637 |
waf_rule: |
| 638 |
name: "{{ resource_prefix }}_rule" |
| 639 |
conditions: |
| 640 |
- name: "{{ resource_prefix }}_ip_condition" |
| 641 |
type: ip |
| 642 |
negated: yes |
| 643 |
- name: "{{ resource_prefix }}_xss_condition" |
| 644 |
type: xss |
| 645 |
negated: no |
| 646 |
- name: "{{ resource_prefix }}_byte_condition" |
| 647 |
type: byte |
| 648 |
negated: no |
| 649 |
- name: "{{ resource_prefix }}_size_condition" |
| 650 |
type: size |
| 651 |
negated: no |
| 652 |
purge_conditions: yes |
| 653 |
region: "{{ aws_region }}" |
| 654 |
waf_regional: true |
| 655 |
register: add_and_remove_waf_regional_rule_conditions |
| 656 |
|
| 657 |
- name: check WAF Regional rules were updated as expected |
| 658 |
assert: |
| 659 |
that: |
| 660 |
- add_and_remove_waf_regional_rule_conditions.changed |
| 661 |
- add_and_remove_waf_regional_rule_conditions.rule.predicates|length == 4 |
| 662 |
|
| 663 |
- name: attempt to remove an WAF Regional in use condition |
| 664 |
waf_condition: |
| 665 |
name: "{{ resource_prefix }}_size_condition" |
| 666 |
type: size |
| 667 |
state: absent |
| 668 |
region: "{{ aws_region }}" |
| 669 |
waf_regional: true |
| 670 |
ignore_errors: yes |
| 671 |
register: remove_in_use_condition |
| 672 |
|
| 673 |
- name: check failure was sensible |
| 674 |
assert: |
| 675 |
that: |
| 676 |
- remove_in_use_condition.failed |
| 677 |
- "'Condition ' ~ resource_prefix ~ '_size_condition is in use' in remove_in_use_condition.msg" |
| 678 |
|
| 679 |
################################################## |
| 680 |
# aws_waf_web_acl tests |
| 681 |
################################################## |
| 682 |
|
| 683 |
- name: create web ACL |
| 684 |
waf_web_acl: |
| 685 |
name: "{{ resource_prefix }}_web_acl" |
| 686 |
rules: |
| 687 |
- name: "{{ resource_prefix }}_rule" |
| 688 |
priority: 1 |
| 689 |
action: block |
| 690 |
default_action: block |
| 691 |
purge_rules: yes |
| 692 |
state: present |
| 693 |
register: create_web_acl |
| 694 |
|
| 695 |
- name: recreate web acl |
| 696 |
waf_web_acl: |
| 697 |
name: "{{ resource_prefix }}_web_acl" |
| 698 |
rules: |
| 699 |
- name: "{{ resource_prefix }}_rule" |
| 700 |
priority: 1 |
| 701 |
action: block |
| 702 |
default_action: block |
| 703 |
state: present |
| 704 |
register: recreate_web_acl |
| 705 |
|
| 706 |
- name: check web acl was not changed |
| 707 |
assert: |
| 708 |
that: |
| 709 |
- not recreate_web_acl.changed |
| 710 |
- recreate_web_acl.web_acl.rules|length == 1 |
| 711 |
|
| 712 |
- name: create a second WAF rule |
| 713 |
waf_rule: |
| 714 |
name: "{{ resource_prefix }}_rule_2" |
| 715 |
conditions: |
| 716 |
- name: "{{ resource_prefix }}_ip_condition" |
| 717 |
type: ip |
| 718 |
negated: yes |
| 719 |
- name: "{{ resource_prefix }}_sql_condition" |
| 720 |
type: sql |
| 721 |
negated: no |
| 722 |
- name: "{{ resource_prefix }}_xss_condition" |
| 723 |
type: xss |
| 724 |
negated: no |
| 725 |
|
| 726 |
- name: add a new rule to the web acl |
| 727 |
waf_web_acl: |
| 728 |
name: "{{ resource_prefix }}_web_acl" |
| 729 |
rules: |
| 730 |
- name: "{{ resource_prefix }}_rule_2" |
| 731 |
priority: 2 |
| 732 |
action: allow |
| 733 |
default_action: block |
| 734 |
state: present |
| 735 |
register: web_acl_add_rule |
| 736 |
|
| 737 |
- name: check that rule was added to the web acl |
| 738 |
assert: |
| 739 |
that: |
| 740 |
- web_acl_add_rule.changed |
| 741 |
- web_acl_add_rule.web_acl.rules|length == 2 |
| 742 |
|
| 743 |
- name: use purge rules to remove the first rule |
| 744 |
waf_web_acl: |
| 745 |
name: "{{ resource_prefix }}_web_acl" |
| 746 |
rules: |
| 747 |
- name: "{{ resource_prefix }}_rule_2" |
| 748 |
priority: 2 |
| 749 |
action: allow |
| 750 |
purge_rules: yes |
| 751 |
default_action: block |
| 752 |
state: present |
| 753 |
register: web_acl_add_rule |
| 754 |
|
| 755 |
- name: check that rule was removed from the web acl |
| 756 |
assert: |
| 757 |
that: |
| 758 |
- web_acl_add_rule.changed |
| 759 |
- web_acl_add_rule.web_acl.rules|length == 1 |
| 760 |
|
| 761 |
- name: swap two rules of same priority |
| 762 |
waf_web_acl: |
| 763 |
name: "{{ resource_prefix }}_web_acl" |
| 764 |
rules: |
| 765 |
- name: "{{ resource_prefix }}_rule" |
| 766 |
priority: 2 |
| 767 |
action: allow |
| 768 |
purge_rules: yes |
| 769 |
default_action: block |
| 770 |
state: present |
| 771 |
register: web_acl_swap_rule |
| 772 |
|
| 773 |
- name: attempt to delete the inuse first rule |
| 774 |
waf_rule: |
| 775 |
name: "{{ resource_prefix }}_rule" |
| 776 |
state: absent |
| 777 |
ignore_errors: yes |
| 778 |
register: remove_inuse_rule |
| 779 |
|
| 780 |
- name: check that removing in-use rule fails |
| 781 |
assert: |
| 782 |
that: |
| 783 |
- remove_inuse_rule.failed |
| 784 |
|
| 785 |
- name: delete the web acl |
| 786 |
waf_web_acl: |
| 787 |
name: "{{ resource_prefix }}_web_acl" |
| 788 |
state: absent |
| 789 |
register: delete_web_acl |
| 790 |
|
| 791 |
- name: check that web acl was deleted |
| 792 |
assert: |
| 793 |
that: |
| 794 |
- delete_web_acl.changed |
| 795 |
- not delete_web_acl.web_acl |
| 796 |
|
| 797 |
- name: delete the no longer in use first rule |
| 798 |
waf_rule: |
| 799 |
name: "{{ resource_prefix }}_rule" |
| 800 |
state: absent |
| 801 |
|
| 802 |
- name: create WAF Regional web ACL |
| 803 |
waf_web_acl: |
| 804 |
name: "{{ resource_prefix }}_web_acl" |
| 805 |
rules: |
| 806 |
- name: "{{ resource_prefix }}_rule" |
| 807 |
priority: 1 |
| 808 |
action: block |
| 809 |
default_action: block |
| 810 |
purge_rules: yes |
| 811 |
state: present |
| 812 |
region: "{{ aws_region }}" |
| 813 |
waf_regional: true |
| 814 |
register: create_waf_regional_web_acl |
| 815 |
|
| 816 |
- name: recreate WAF Regional web acl |
| 817 |
waf_web_acl: |
| 818 |
name: "{{ resource_prefix }}_web_acl" |
| 819 |
rules: |
| 820 |
- name: "{{ resource_prefix }}_rule" |
| 821 |
priority: 1 |
| 822 |
action: block |
| 823 |
default_action: block |
| 824 |
state: present |
| 825 |
region: "{{ aws_region }}" |
| 826 |
waf_regional: true |
| 827 |
register: recreate_waf_regional_web_acl |
| 828 |
|
| 829 |
- name: check WAF Regional web acl was not changed |
| 830 |
assert: |
| 831 |
that: |
| 832 |
- not recreate_waf_regional_web_acl.changed |
| 833 |
- recreate_waf_regional_web_acl.web_acl.rules|length == 1 |
| 834 |
|
| 835 |
- name: create a second WAF Regional rule |
| 836 |
waf_rule: |
| 837 |
name: "{{ resource_prefix }}_rule_2" |
| 838 |
conditions: |
| 839 |
- name: "{{ resource_prefix }}_ip_condition" |
| 840 |
type: ip |
| 841 |
negated: yes |
| 842 |
- name: "{{ resource_prefix }}_sql_condition" |
| 843 |
type: sql |
| 844 |
negated: no |
| 845 |
- name: "{{ resource_prefix }}_xss_condition" |
| 846 |
type: xss |
| 847 |
negated: no |
| 848 |
region: "{{ aws_region }}" |
| 849 |
waf_regional: true |
| 850 |
|
| 851 |
- name: add a new rule to the WAF Regional web acl |
| 852 |
waf_web_acl: |
| 853 |
name: "{{ resource_prefix }}_web_acl" |
| 854 |
rules: |
| 855 |
- name: "{{ resource_prefix }}_rule_2" |
| 856 |
priority: 2 |
| 857 |
action: allow |
| 858 |
default_action: block |
| 859 |
state: present |
| 860 |
region: "{{ aws_region }}" |
| 861 |
waf_regional: true |
| 862 |
register: waf_regional_web_acl_add_rule |
| 863 |
|
| 864 |
- name: check that rule was added to the WAF Regional web acl |
| 865 |
assert: |
| 866 |
that: |
| 867 |
- waf_regional_web_acl_add_rule.changed |
| 868 |
- waf_regional_web_acl_add_rule.web_acl.rules|length == 2 |
| 869 |
|
| 870 |
- name: use purge rules to remove the WAF Regional first rule |
| 871 |
waf_web_acl: |
| 872 |
name: "{{ resource_prefix }}_web_acl" |
| 873 |
rules: |
| 874 |
- name: "{{ resource_prefix }}_rule_2" |
| 875 |
priority: 2 |
| 876 |
action: allow |
| 877 |
purge_rules: yes |
| 878 |
default_action: block |
| 879 |
state: present |
| 880 |
region: "{{ aws_region }}" |
| 881 |
waf_regional: true |
| 882 |
register: waf_regional_web_acl_add_rule |
| 883 |
|
| 884 |
- name: check that rule was removed from the WAF Regional web acl |
| 885 |
assert: |
| 886 |
that: |
| 887 |
- waf_regional_web_acl_add_rule.changed |
| 888 |
- waf_regional_web_acl_add_rule.web_acl.rules|length == 1 |
| 889 |
|
| 890 |
- name: swap two WAF Regional rules of same priority |
| 891 |
waf_web_acl: |
| 892 |
name: "{{ resource_prefix }}_web_acl" |
| 893 |
rules: |
| 894 |
- name: "{{ resource_prefix }}_rule" |
| 895 |
priority: 2 |
| 896 |
action: allow |
| 897 |
purge_rules: yes |
| 898 |
default_action: block |
| 899 |
state: present |
| 900 |
region: "{{ aws_region }}" |
| 901 |
waf_regional: true |
| 902 |
register: waf_regional_web_acl_swap_rule |
| 903 |
|
| 904 |
- name: attempt to delete the WAF Regional inuse first rule |
| 905 |
waf_rule: |
| 906 |
name: "{{ resource_prefix }}_rule" |
| 907 |
state: absent |
| 908 |
region: "{{ aws_region }}" |
| 909 |
waf_regional: true |
| 910 |
ignore_errors: yes |
| 911 |
register: remove_waf_regional_inuse_rule |
| 912 |
|
| 913 |
- name: check that removing WAF Regional in-use rule fails |
| 914 |
assert: |
| 915 |
that: |
| 916 |
- remove_waf_regional_inuse_rule.failed |
| 917 |
|
| 918 |
- name: delete the WAF Regional web acl |
| 919 |
waf_web_acl: |
| 920 |
name: "{{ resource_prefix }}_web_acl" |
| 921 |
state: absent |
| 922 |
region: "{{ aws_region }}" |
| 923 |
waf_regional: true |
| 924 |
register: delete_waf_regional_web_acl |
| 925 |
|
| 926 |
- name: check that WAF Regional web acl was deleted |
| 927 |
assert: |
| 928 |
that: |
| 929 |
- delete_waf_regional_web_acl.changed |
| 930 |
- not delete_waf_regional_web_acl.web_acl |
| 931 |
|
| 932 |
- name: delete the no longer in use WAF Regional first rule |
| 933 |
waf_rule: |
| 934 |
name: "{{ resource_prefix }}_rule" |
| 935 |
state: absent |
| 936 |
region: "{{ aws_region }}" |
| 937 |
waf_regional: true |
| 938 |
|
| 939 |
################################################## |
| 940 |
# TEARDOWN |
| 941 |
################################################## |
| 942 |
|
| 943 |
always: |
| 944 |
- debug: |
| 945 |
msg: "****** TEARDOWN STARTS HERE ******" |
| 946 |
|
| 947 |
- name: delete the web acl |
| 948 |
waf_web_acl: |
| 949 |
name: "{{ resource_prefix }}_web_acl" |
| 950 |
state: absent |
| 951 |
purge_rules: yes |
| 952 |
ignore_errors: yes |
| 953 |
|
| 954 |
- name: remove second WAF rule |
| 955 |
waf_rule: |
| 956 |
name: "{{ resource_prefix }}_rule_2" |
| 957 |
state: absent |
| 958 |
purge_conditions: yes |
| 959 |
ignore_errors: yes |
| 960 |
|
| 961 |
- name: remove WAF rule |
| 962 |
waf_rule: |
| 963 |
name: "{{ resource_prefix }}_rule" |
| 964 |
state: absent |
| 965 |
purge_conditions: yes |
| 966 |
ignore_errors: yes |
| 967 |
|
| 968 |
- name: remove XSS condition |
| 969 |
waf_condition: |
| 970 |
name: "{{ resource_prefix }}_xss_condition" |
| 971 |
type: xss |
| 972 |
state: absent |
| 973 |
ignore_errors: yes |
| 974 |
|
| 975 |
- name: remove SQL condition |
| 976 |
waf_condition: |
| 977 |
name: "{{ resource_prefix }}_sql_condition" |
| 978 |
type: sql |
| 979 |
state: absent |
| 980 |
ignore_errors: yes |
| 981 |
|
| 982 |
- name: remove size condition |
| 983 |
waf_condition: |
| 984 |
name: "{{ resource_prefix }}_size_condition" |
| 985 |
type: size |
| 986 |
state: absent |
| 987 |
ignore_errors: yes |
| 988 |
|
| 989 |
- name: remove geo condition |
| 990 |
waf_condition: |
| 991 |
name: "{{ resource_prefix }}_geo_condition" |
| 992 |
type: geo |
| 993 |
state: absent |
| 994 |
ignore_errors: yes |
| 995 |
|
| 996 |
- name: remove byte condition |
| 997 |
waf_condition: |
| 998 |
name: "{{ resource_prefix }}_byte_condition" |
| 999 |
type: byte |
| 1000 |
state: absent |
| 1001 |
ignore_errors: yes |
| 1002 |
|
| 1003 |
- name: remove ip address condition |
| 1004 |
waf_condition: |
| 1005 |
name: "{{ resource_prefix }}_ip_condition" |
| 1006 |
type: ip |
| 1007 |
state: absent |
| 1008 |
ignore_errors: yes |
| 1009 |
|
| 1010 |
- name: remove regex part 2 condition |
| 1011 |
waf_condition: |
| 1012 |
name: "{{ resource_prefix }}_regex_condition_part_2" |
| 1013 |
type: regex |
| 1014 |
state: absent |
| 1015 |
ignore_errors: yes |
| 1016 |
|
| 1017 |
- name: remove first regex condition |
| 1018 |
waf_condition: |
| 1019 |
name: "{{ resource_prefix }}_regex_condition" |
| 1020 |
type: regex |
| 1021 |
state: absent |
| 1022 |
ignore_errors: yes |
| 1023 |
|
| 1024 |
- name: delete the WAF Regional web acl |
| 1025 |
waf_web_acl: |
| 1026 |
name: "{{ resource_prefix }}_web_acl" |
| 1027 |
state: absent |
| 1028 |
purge_rules: yes |
| 1029 |
region: "{{ aws_region }}" |
| 1030 |
waf_regional: true |
| 1031 |
ignore_errors: yes |
| 1032 |
|
| 1033 |
- name: remove second WAF Regional rule |
| 1034 |
waf_rule: |
| 1035 |
name: "{{ resource_prefix }}_rule_2" |
| 1036 |
state: absent |
| 1037 |
purge_conditions: yes |
| 1038 |
region: "{{ aws_region }}" |
| 1039 |
waf_regional: true |
| 1040 |
ignore_errors: yes |
| 1041 |
|
| 1042 |
- name: remove WAF Regional rule |
| 1043 |
waf_rule: |
| 1044 |
name: "{{ resource_prefix }}_rule" |
| 1045 |
state: absent |
| 1046 |
purge_conditions: yes |
| 1047 |
region: "{{ aws_region }}" |
| 1048 |
waf_regional: true |
| 1049 |
ignore_errors: yes |
| 1050 |
|
| 1051 |
- name: remove WAF Regional XSS condition |
| 1052 |
waf_condition: |
| 1053 |
name: "{{ resource_prefix }}_xss_condition" |
| 1054 |
type: xss |
| 1055 |
state: absent |
| 1056 |
region: "{{ aws_region }}" |
| 1057 |
waf_regional: true |
| 1058 |
ignore_errors: yes |
| 1059 |
|
| 1060 |
- name: remove WAF Regional SQL condition |
| 1061 |
waf_condition: |
| 1062 |
name: "{{ resource_prefix }}_sql_condition" |
| 1063 |
type: sql |
| 1064 |
state: absent |
| 1065 |
region: "{{ aws_region }}" |
| 1066 |
waf_regional: true |
| 1067 |
ignore_errors: yes |
| 1068 |
|
| 1069 |
- name: remove WAF Regional size condition |
| 1070 |
waf_condition: |
| 1071 |
name: "{{ resource_prefix }}_size_condition" |
| 1072 |
type: size |
| 1073 |
state: absent |
| 1074 |
region: "{{ aws_region }}" |
| 1075 |
waf_regional: true |
| 1076 |
ignore_errors: yes |
| 1077 |
|
| 1078 |
- name: remove WAF Regional geo condition |
| 1079 |
waf_condition: |
| 1080 |
name: "{{ resource_prefix }}_geo_condition" |
| 1081 |
type: geo |
| 1082 |
state: absent |
| 1083 |
region: "{{ aws_region }}" |
| 1084 |
waf_regional: true |
| 1085 |
ignore_errors: yes |
| 1086 |
|
| 1087 |
- name: remove WAF Regional byte condition |
| 1088 |
waf_condition: |
| 1089 |
name: "{{ resource_prefix }}_byte_condition" |
| 1090 |
type: byte |
| 1091 |
state: absent |
| 1092 |
region: "{{ aws_region }}" |
| 1093 |
waf_regional: true |
| 1094 |
ignore_errors: yes |
| 1095 |
|
| 1096 |
- name: remove WAF Regional ip address condition |
| 1097 |
waf_condition: |
| 1098 |
name: "{{ resource_prefix }}_ip_condition" |
| 1099 |
type: ip |
| 1100 |
state: absent |
| 1101 |
region: "{{ aws_region }}" |
| 1102 |
waf_regional: true |
| 1103 |
ignore_errors: yes |
| 1104 |
|
| 1105 |
- name: remove WAF Regional regex part 2 condition |
| 1106 |
waf_condition: |
| 1107 |
name: "{{ resource_prefix }}_regex_condition_part_2" |
| 1108 |
type: regex |
| 1109 |
state: absent |
| 1110 |
region: "{{ aws_region }}" |
| 1111 |
waf_regional: true |
| 1112 |
ignore_errors: yes |
| 1113 |
|
| 1114 |
- name: remove first WAF Regional regex condition |
| 1115 |
waf_condition: |
| 1116 |
name: "{{ resource_prefix }}_regex_condition" |
| 1117 |
type: regex |
| 1118 |
state: absent |
| 1119 |
region: "{{ aws_region }}" |
| 1120 |
waf_regional: true |
| 1121 |
ignore_errors: yes |