Debian Codegraph @

ansible_collections/community/aws/tests/integration/targets/wafv2_web_acl/tasks/main.yml

raw
1 ---
2 - module_defaults:
3 group/aws:
4 access_key: "{{ aws_access_key }}"
5 secret_key: "{{ aws_secret_key }}"
6 session_token: "{{ security_token | default(omit) }}"
7 region: "{{ aws_region }}"
8 block:
9
10 #######################
11 ## Create web acl
12 #######################
13
14 - name: check_mode create web acl
15 wafv2_web_acl:
16 name: "{{ web_acl_name }}"
17 state: present
18 description: hallo eins
19 scope: REGIONAL
20 default_action: Allow
21 sampled_requests: no
22 cloudwatch_metrics: yes
23 metric_name: blub
24 rules:
25 - name: zwei
26 priority: 2
27 action:
28 block: {}
29 visibility_config:
30 sampled_requests_enabled: yes
31 cloud_watch_metrics_enabled: yes
32 metric_name: ddos
33 statement:
34 xss_match_statement:
35 field_to_match:
36 body: {}
37 text_transformations:
38 - type: NONE
39 priority: 0
40 - name: admin_protect
41 priority: 1
42 override_action:
43 none: {}
44 visibility_config:
45 sampled_requests_enabled: yes
46 cloud_watch_metrics_enabled: yes
47 metric_name: fsd
48 statement:
49 managed_rule_group_statement:
50 vendor_name: AWS
51 name: AWSManagedRulesAdminProtectionRuleSet
52 custom_response_bodies:
53 too_many_requests:
54 content_type: APPLICATION_JSON
55 content: '{ message: "Your request has been blocked due to too many HTTP requests coming from your IP" }'
56 tags:
57 A: B
58 C: D
59 register: out
60 check_mode: yes
61
62 - name: check_mode verify create
63 assert:
64 that:
65 - out is changed
66
67 - name: Create web acl with custom response bodies
68 wafv2_web_acl:
69 name: "{{ resource_prefix }}-acl-with-response-body"
70 state: present
71 description: foo
72 scope: REGIONAL
73 default_action: Allow
74 sampled_requests: no
75 cloudwatch_metrics: no
76 rules:
77 - name: rate-limit-per-IP
78 priority: 1
79 action:
80 block:
81 custom_response:
82 response_code: 429
83 custom_response_body_key: too_many_requests
84 statement:
85 rate_based_statement:
86 limit: 1000
87 aggregate_key_type: IP
88 visibility_config:
89 sampled_requests_enabled: yes
90 cloud_watch_metrics_enabled: no
91 metric_name: unused
92 custom_response_bodies:
93 too_many_requests:
94 content_type: APPLICATION_JSON
95 content: '{ message: "Your request has been blocked due to too many HTTP requests coming from your IP" }'
96 register: acl_with_response_body
97
98 - name: Web acl with custom response bodies verify create
99 assert:
100 that:
101 - acl_with_response_body is changed
102 - acl_with_response_body.web_acl.rules | count == 1
103 - acl_with_response_body.web_acl.custom_response_bodies.too_many_requests is defined
104
105 - name: Update web acl with custom response bodies to remove custom response
106 wafv2_web_acl:
107 name: "{{ resource_prefix }}-acl-with-response-body"
108 state: present
109 scope: REGIONAL
110 description: foo
111 default_action: Allow
112 sampled_requests: no
113 cloudwatch_metrics: no
114 rules:
115 - name: rate-limit-per-IP
116 priority: 1
117 action:
118 block: {}
119 statement:
120 rate_based_statement:
121 limit: 1000
122 aggregate_key_type: IP
123 visibility_config:
124 sampled_requests_enabled: yes
125 cloud_watch_metrics_enabled: no
126 metric_name: unused
127 custom_response_bodies: {}
128
129 # unfortunately the wafv2_web_acl does not return the ACL structure after an update
130 # hence we have to do another task here using the info module to retrieve the latest state
131 # of the ACL and then to check it
132 - name: check if custom response body was really removed
133 wafv2_web_acl_info:
134 name: "{{ resource_prefix }}-acl-with-response-body"
135 scope: REGIONAL
136 register: acl_without_response_bodies
137
138 - name: Web acl with custom response bodies verify removal of custom response
139 assert:
140 that:
141 - acl_without_response_bodies.custom_response_bodies is undefined
142
143 - name: create web acl
144 wafv2_web_acl:
145 name: "{{ web_acl_name }}"
146 state: present
147 description: hallo eins
148 scope: REGIONAL
149 default_action: Allow
150 sampled_requests: no
151 cloudwatch_metrics: yes
152 metric_name: blub
153 rules:
154 - name: zwei
155 priority: 2
156 action:
157 block: {}
158 visibility_config:
159 sampled_requests_enabled: yes
160 cloud_watch_metrics_enabled: yes
161 metric_name: ddos
162 statement:
163 xss_match_statement:
164 field_to_match:
165 body: {}
166 text_transformations:
167 - type: NONE
168 priority: 0
169 - name: admin_protect
170 priority: 1
171 override_action:
172 none: {}
173 visibility_config:
174 sampled_requests_enabled: yes
175 cloud_watch_metrics_enabled: yes
176 metric_name: fsd
177 statement:
178 managed_rule_group_statement:
179 vendor_name: AWS
180 name: AWSManagedRulesAdminProtectionRuleSet
181 - name: rate-limit-per-IP
182 priority: 3
183 action:
184 block:
185 custom_response:
186 response_code: 429
187 custom_response_body_key: too_many_requests
188 statement:
189 rate_based_statement:
190 limit: 5000
191 aggregate_key_type: IP
192 visibility_config:
193 sampled_requests_enabled: yes
194 cloud_watch_metrics_enabled: yes
195 metric_name: waf-acl-rule-rate-limit-per-IP
196 custom_response_bodies:
197 too_many_requests:
198 content_type: APPLICATION_JSON
199 content: '{ message: "Your request has been blocked due to too many HTTP requests coming from your IP" }'
200 tags:
201 A: B
202 C: D
203 register: ACL
204
205 - name: verify create
206 assert:
207 that:
208 - ACL is changed
209 - ACL.web_acl.name == web_acl_name
210 - not ACL.web_acl.visibility_config.sampled_requests_enabled
211 - ACL.web_acl.rules | count == 3
212 - ACL.web_acl.description == 'hallo eins'
213
214 - name: immutable create web acl
215 wafv2_web_acl:
216 name: "{{ web_acl_name }}"
217 state: present
218 description: hallo eins
219 scope: REGIONAL
220 default_action: Allow
221 sampled_requests: no
222 cloudwatch_metrics: yes
223 metric_name: blub
224 rules:
225 - name: zwei
226 priority: 2
227 action:
228 block: {}
229 visibility_config:
230 sampled_requests_enabled: yes
231 cloud_watch_metrics_enabled: yes
232 metric_name: ddos
233 statement:
234 xss_match_statement:
235 field_to_match:
236 body: {}
237 text_transformations:
238 - type: NONE
239 priority: 0
240 - name: admin_protect
241 priority: 1
242 override_action:
243 none: {}
244 visibility_config:
245 sampled_requests_enabled: yes
246 cloud_watch_metrics_enabled: yes
247 metric_name: fsd
248 statement:
249 managed_rule_group_statement:
250 vendor_name: AWS
251 name: AWSManagedRulesAdminProtectionRuleSet
252 - name: rate-limit-per-IP
253 priority: 3
254 action:
255 block:
256 custom_response:
257 response_code: 429
258 custom_response_body_key: too_many_requests
259 statement:
260 rate_based_statement:
261 limit: 5000
262 aggregate_key_type: IP
263 visibility_config:
264 sampled_requests_enabled: yes
265 cloud_watch_metrics_enabled: yes
266 metric_name: waf-acl-rule-rate-limit-per-IP
267 custom_response_bodies:
268 too_many_requests:
269 content_type: APPLICATION_JSON
270 content: '{ message: "Your request has been blocked due to too many HTTP requests coming from your IP" }'
271 tags:
272 A: B
273 C: D
274 register: out
275
276 - name: verify create
277 assert:
278 that:
279 - out is not changed
280
281 ###############################
282 # test web acl
283 ###############################
284 - name: get web acl
285 wafv2_web_acl_info:
286 name: "{{ web_acl_name }}"
287 scope: REGIONAL
288 register: out
289
290 - name: verify rules
291 assert:
292 that:
293 - out.rules | count == 3
294
295 - name: change web acl description
296 wafv2_web_acl:
297 name: "{{ web_acl_name }}"
298 state: present
299 description: hallo eins drei
300 scope: REGIONAL
301 default_action: Allow
302 sampled_requests: no
303 cloudwatch_metrics: yes
304 metric_name: blub
305 rules:
306 - name: zwei
307 priority: 2
308 action:
309 block: {}
310 visibility_config:
311 sampled_requests_enabled: yes
312 cloud_watch_metrics_enabled: yes
313 metric_name: ddos
314 statement:
315 xss_match_statement:
316 field_to_match:
317 body: {}
318 text_transformations:
319 - type: NONE
320 priority: 0
321 - name: admin_protect
322 priority: 1
323 override_action:
324 none: {}
325 visibility_config:
326 sampled_requests_enabled: yes
327 cloud_watch_metrics_enabled: yes
328 metric_name: fsd
329 statement:
330 managed_rule_group_statement:
331 vendor_name: AWS
332 name: AWSManagedRulesAdminProtectionRuleSet
333 tags:
334 A: B
335 C: D
336 register: out
337
338 - name: verify change
339 assert:
340 that:
341 - out is changed
342
343
344 - name: add 1 rules
345 wafv2_web_acl:
346 name: "{{ web_acl_name }}"
347 state: present
348 description: hallo eins drei
349 scope: REGIONAL
350 default_action: Allow
351 sampled_requests: no
352 cloudwatch_metrics: yes
353 metric_name: blub
354 purge_rules: no
355 rules:
356 - name: bla
357 priority: 8
358 override_action:
359 none: {}
360 visibility_config:
361 sampled_requests_enabled: yes
362 cloud_watch_metrics_enabled: yes
363 metric_name: fsd
364 statement:
365 managed_rule_group_statement:
366 vendor_name: AWS
367 name: AWSManagedRulesAdminProtectionRuleSet
368 tags:
369 A: B
370 C: D
371 register: out
372
373 - name: verify change
374 assert:
375 that:
376 - out is changed
377
378 - name: get web acl
379 wafv2_web_acl_info:
380 name: "{{ web_acl_name }}"
381 scope: REGIONAL
382 register: out
383
384 - name: verify rules
385 assert:
386 that:
387 - out.rules | count == 3
388
389 - name: reduce rules to 1
390 wafv2_web_acl:
391 name: "{{ web_acl_name }}"
392 state: present
393 description: hallo eins drei
394 scope: REGIONAL
395 default_action: Allow
396 sampled_requests: no
397 cloudwatch_metrics: yes
398 metric_name: blub
399 purge_rules: yes
400 rules:
401 - name: admin_protect
402 priority: 1
403 override_action:
404 none: {}
405 visibility_config:
406 sampled_requests_enabled: yes
407 cloud_watch_metrics_enabled: yes
408 metric_name: admin_protect
409 statement:
410 managed_rule_group_statement:
411 vendor_name: AWS
412 name: AWSManagedRulesAdminProtectionRuleSet
413 tags:
414 A: B
415 C: D
416 register: out
417
418 - name: verify change
419 assert:
420 that:
421 - out is changed
422
423 - name: get web acl
424 wafv2_web_acl_info:
425 name: "{{ web_acl_name }}"
426 scope: REGIONAL
427 register: out
428
429 - name: verify rules
430 assert:
431 that:
432 - out.rules | count == 1
433
434 - name: immutable change web acl
435 wafv2_web_acl:
436 name: "{{ web_acl_name }}"
437 state: present
438 description: hallo eins drei
439 scope: REGIONAL
440 default_action: Allow
441 sampled_requests: no
442 cloudwatch_metrics: yes
443 metric_name: blub
444 rules:
445 - name: admin_protect
446 priority: 1
447 override_action:
448 none: {}
449 visibility_config:
450 sampled_requests_enabled: yes
451 cloud_watch_metrics_enabled: yes
452 metric_name: admin_protect
453 statement:
454 managed_rule_group_statement:
455 vendor_name: AWS
456 name: AWSManagedRulesAdminProtectionRuleSet
457 tags:
458 A: B
459 C: D
460 register: out
461
462 - name: verify no change
463 assert:
464 that:
465 - out is not changed
466
467 - name: test geo match statement
468 wafv2_web_acl:
469 name: "{{ web_acl_name }}"
470 state: present
471 description: hallo eins drei
472 scope: REGIONAL
473 default_action: Allow
474 sampled_requests: no
475 cloudwatch_metrics: yes
476 metric_name: blub
477 purge_rules: yes
478 rules:
479 - name: block-germany
480 priority: 1
481 action:
482 block: {}
483 visibility_config:
484 sampled_requests_enabled: yes
485 cloud_watch_metrics_enabled: yes
486 metric_name: block-germany
487 statement:
488 geo_match_statement:
489 country_codes:
490 - DE
491 tags:
492 A: B
493 C: D
494 register: out
495
496 - name: verify change
497 assert:
498 that:
499 - out is changed
500
501 - name: re-read webacl
502 wafv2_web_acl_info:
503 name: "{{ web_acl_name }}"
504 scope: REGIONAL
505 register: out
506
507 - name: verify geo match statement
508 assert:
509 that:
510 - out.rules[0].statement.geo_match_statement.country_codes[0] == 'DE'
511
512 - include_tasks: 'description.yml'
513 - include_tasks: 'tags.yml'
514
515 - name: re-read webacl
516 wafv2_web_acl_info:
517 name: "{{ web_acl_name }}"
518 scope: REGIONAL
519 register: out
520
521 - name: verify geo match statement
522 assert:
523 that:
524 - out.rules[0].statement.geo_match_statement.country_codes[0] == 'DE'
525
526 - name: delete web acl
527 wafv2_web_acl:
528 name: "{{ web_acl_name }}"
529 state: absent
530 scope: REGIONAL
531 register: out
532
533 - name: verify change
534 assert:
535 that:
536 - out is changed
537
538 - name: immutable delete web acl
539 wafv2_web_acl:
540 name: "{{ web_acl_name }}"
541 state: absent
542 scope: REGIONAL
543 register: out
544
545 - name: verify not change
546 assert:
547 that:
548 - out is not changed
549
550 always:
551 ###################################
552 # always delete wafv2 components
553 ###################################
554 - name: always delete web acl
555 wafv2_web_acl:
556 name: "{{ web_acl_name }}"
557 state: absent
558 scope: REGIONAL
559 ignore_errors: true
560
561 - name: Ensure ACL with response body is removed
562 wafv2_web_acl:
563 name: "{{ resource_prefix }}-acl-with-response-body"
564 state: absent
565 scope: REGIONAL
566 ignore_errors: true