Debian Codegraph @

ansible_collections/community/aws/tests/integration/targets/wafv2/tasks/create_webacl.yml

raw
1 #######################
2 ## Create web acl
3 #######################
4
5 - block:
6
7 - name: check_mode create web acl
8 wafv2_web_acl:
9 name: "{{ web_acl_name }}"
10 state: present
11 description: hallo eins
12 scope: REGIONAL
13 default_action: Allow
14 sampled_requests: no
15 cloudwatch_metrics: yes
16 metric_name: blub
17 rules:
18 - name: zwei
19 priority: 2
20 action:
21 block: {}
22 visibility_config:
23 sampled_requests_enabled: yes
24 cloud_watch_metrics_enabled: yes
25 metric_name: ddos
26 statement:
27 xss_match_statement:
28 field_to_match:
29 body: {}
30 text_transformations:
31 - type: NONE
32 priority: 0
33 - name: admin_protect
34 priority: 1
35 override_action:
36 none: {}
37 visibility_config:
38 sampled_requests_enabled: yes
39 cloud_watch_metrics_enabled: yes
40 metric_name: fsd
41 statement:
42 managed_rule_group_statement:
43 vendor_name: AWS
44 name: AWSManagedRulesAdminProtectionRuleSet
45 custom_response_bodies:
46 too_many_requests:
47 content_type: APPLICATION_JSON
48 content: '{ message: "Your request has been blocked due to too many HTTP requests coming from your IP" }'
49 tags:
50 A: B
51 C: D
52 register: out
53 check_mode: yes
54
55 - name: check_mode verify create
56 assert:
57 that:
58 - out is changed
59
60 - name: Create web acl with custom response bodies
61 wafv2_web_acl:
62 name: "{{ resource_prefix }}-acl-with-response-body"
63 state: present
64 description: foo
65 scope: REGIONAL
66 default_action: Allow
67 sampled_requests: no
68 cloudwatch_metrics: no
69 rules:
70 - name: rate-limit-per-IP
71 priority: 1
72 action:
73 block:
74 custom_response:
75 response_code: 429
76 custom_response_body_key: too_many_requests
77 statement:
78 rate_based_statement:
79 limit: 1000
80 aggregate_key_type: IP
81 visibility_config:
82 sampled_requests_enabled: yes
83 cloud_watch_metrics_enabled: no
84 metric_name: unused
85 custom_response_bodies:
86 too_many_requests:
87 content_type: APPLICATION_JSON
88 content: '{ message: "Your request has been blocked due to too many HTTP requests coming from your IP" }'
89 register: acl_with_response_body
90
91 - name: Web acl with custom response bodies verify create
92 assert:
93 that:
94 - acl_with_response_body is changed
95 - acl_with_response_body.web_acl.rules | count == 1
96 - acl_with_response_body.web_acl.custom_response_bodies.too_many_requests is defined
97
98 - name: Update web acl with custom response bodies to remove custom response
99 wafv2_web_acl:
100 name: "{{ resource_prefix }}-acl-with-response-body"
101 state: present
102 scope: REGIONAL
103 description: foo
104 default_action: Allow
105 sampled_requests: no
106 cloudwatch_metrics: no
107 rules:
108 - name: rate-limit-per-IP
109 priority: 1
110 action:
111 block: {}
112 statement:
113 rate_based_statement:
114 limit: 1000
115 aggregate_key_type: IP
116 visibility_config:
117 sampled_requests_enabled: yes
118 cloud_watch_metrics_enabled: no
119 metric_name: unused
120 custom_response_bodies: {}
121
122 # unfortunately the wafv2_web_acl does not return the ACL structure after an update
123 # hence we have to do another task here using the info module to retrieve the latest state
124 # of the ACL and then to check it
125 - name: check if custom response body was really removed
126 wafv2_web_acl_info:
127 name: "{{ resource_prefix }}-acl-with-response-body"
128 scope: REGIONAL
129 register: acl_without_response_bodies
130
131 - name: Web acl with custom response bodies verify removal of custom response
132 assert:
133 that:
134 - acl_without_response_bodies.custom_response_bodies is undefined
135
136 - name: create web acl
137 wafv2_web_acl:
138 name: "{{ web_acl_name }}"
139 state: present
140 description: hallo eins
141 scope: REGIONAL
142 default_action: Allow
143 sampled_requests: no
144 cloudwatch_metrics: yes
145 metric_name: blub
146 rules:
147 - name: zwei
148 priority: 2
149 action:
150 block: {}
151 visibility_config:
152 sampled_requests_enabled: yes
153 cloud_watch_metrics_enabled: yes
154 metric_name: ddos
155 statement:
156 xss_match_statement:
157 field_to_match:
158 body: {}
159 text_transformations:
160 - type: NONE
161 priority: 0
162 - name: admin_protect
163 priority: 1
164 override_action:
165 none: {}
166 visibility_config:
167 sampled_requests_enabled: yes
168 cloud_watch_metrics_enabled: yes
169 metric_name: fsd
170 statement:
171 managed_rule_group_statement:
172 vendor_name: AWS
173 name: AWSManagedRulesAdminProtectionRuleSet
174 - name: rate-limit-per-IP
175 priority: 3
176 action:
177 block:
178 custom_response:
179 response_code: 429
180 custom_response_body_key: too_many_requests
181 statement:
182 rate_based_statement:
183 limit: 5000
184 aggregate_key_type: IP
185 visibility_config:
186 sampled_requests_enabled: yes
187 cloud_watch_metrics_enabled: yes
188 metric_name: waf-acl-rule-rate-limit-per-IP
189 custom_response_bodies:
190 too_many_requests:
191 content_type: APPLICATION_JSON
192 content: '{ message: "Your request has been blocked due to too many HTTP requests coming from your IP" }'
193 tags:
194 A: B
195 C: D
196 register: ACL
197
198 - name: verify create
199 assert:
200 that:
201 - ACL is changed
202 - ACL.web_acl.name == web_acl_name
203 - not ACL.web_acl.visibility_config.sampled_requests_enabled
204 - ACL.web_acl.rules | count == 3
205 - ACL.web_acl.description == 'hallo eins'
206
207 - name: immutable create web acl
208 wafv2_web_acl:
209 name: "{{ web_acl_name }}"
210 state: present
211 description: hallo eins
212 scope: REGIONAL
213 default_action: Allow
214 sampled_requests: no
215 cloudwatch_metrics: yes
216 metric_name: blub
217 rules:
218 - name: zwei
219 priority: 2
220 action:
221 block: {}
222 visibility_config:
223 sampled_requests_enabled: yes
224 cloud_watch_metrics_enabled: yes
225 metric_name: ddos
226 statement:
227 xss_match_statement:
228 field_to_match:
229 body: {}
230 text_transformations:
231 - type: NONE
232 priority: 0
233 - name: admin_protect
234 priority: 1
235 override_action:
236 none: {}
237 visibility_config:
238 sampled_requests_enabled: yes
239 cloud_watch_metrics_enabled: yes
240 metric_name: fsd
241 statement:
242 managed_rule_group_statement:
243 vendor_name: AWS
244 name: AWSManagedRulesAdminProtectionRuleSet
245 - name: rate-limit-per-IP
246 priority: 3
247 action:
248 block:
249 custom_response:
250 response_code: 429
251 custom_response_body_key: too_many_requests
252 statement:
253 rate_based_statement:
254 limit: 5000
255 aggregate_key_type: IP
256 visibility_config:
257 sampled_requests_enabled: yes
258 cloud_watch_metrics_enabled: yes
259 metric_name: waf-acl-rule-rate-limit-per-IP
260 custom_response_bodies:
261 too_many_requests:
262 content_type: APPLICATION_JSON
263 content: '{ message: "Your request has been blocked due to too many HTTP requests coming from your IP" }'
264 tags:
265 A: B
266 C: D
267 register: out
268
269 - name: verify create
270 assert:
271 that:
272 - out is not changed