Debian Codegraph @

ansible_collections/fortinet/fortimanager/plugins/modules/fmgr_waf_profile_constraint.py

raw symbols SCIP
1 #!/usr/bin/python
2 from __future__ import absolute_import, division, print_function
3 # Copyright 2019-2024 Fortinet, Inc.
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 __metaclass__ = type
7
8 ANSIBLE_METADATA = {'status': ['preview'],
9 'supported_by': 'community',
10 'metadata_version': '1.1'}
11
12 DOCUMENTATION = '''
13 ---
14 module: fmgr_waf_profile_constraint
15 short_description: WAF HTTP protocol restrictions.
16 version_added: "2.0.0"
17 extends_documentation_fragment:
18 - fortinet.fortimanager.general
19 - fortinet.fortimanager.general.partial_crud
20 options:
21 revision_note:
22 description: The change note that can be specified when an object is created or updated.
23 type: str
24 adom:
25 description: The parameter (adom) in requested url.
26 type: str
27 required: true
28 profile:
29 description: The parameter (profile) in requested url.
30 type: str
31 required: true
32 waf_profile_constraint:
33 description: The top level parameters set.
34 required: false
35 type: dict
36 suboptions:
37 content_length:
38 aliases: ['content-length']
39 type: dict
40 description: Content length.
41 suboptions:
42 action:
43 type: str
44 description: Action.
45 choices: ['allow', 'block']
46 length:
47 type: int
48 description: Length of HTTP content in bytes
49 log:
50 type: str
51 description: Enable/disable logging.
52 choices: ['disable', 'enable']
53 severity:
54 type: str
55 description: Severity.
56 choices: ['low', 'medium', 'high']
57 status:
58 type: str
59 description: Enable/disable the constraint.
60 choices: ['disable', 'enable']
61 exception:
62 type: list
63 elements: dict
64 description: Exception.
65 suboptions:
66 address:
67 type: str
68 description: Host address.
69 content_length:
70 aliases: ['content-length']
71 type: str
72 description: HTTP content length in request.
73 choices: ['disable', 'enable']
74 header_length:
75 aliases: ['header-length']
76 type: str
77 description: HTTP header length in request.
78 choices: ['disable', 'enable']
79 hostname:
80 type: str
81 description: Enable/disable hostname check.
82 choices: ['disable', 'enable']
83 id:
84 type: int
85 description: Exception ID.
86 line_length:
87 aliases: ['line-length']
88 type: str
89 description: HTTP line length in request.
90 choices: ['disable', 'enable']
91 malformed:
92 type: str
93 description: Enable/disable malformed HTTP request check.
94 choices: ['disable', 'enable']
95 max_cookie:
96 aliases: ['max-cookie']
97 type: str
98 description: Maximum number of cookies in HTTP request.
99 choices: ['disable', 'enable']
100 max_header_line:
101 aliases: ['max-header-line']
102 type: str
103 description: Maximum number of HTTP header line.
104 choices: ['disable', 'enable']
105 max_range_segment:
106 aliases: ['max-range-segment']
107 type: str
108 description: Maximum number of range segments in HTTP range line.
109 choices: ['disable', 'enable']
110 max_url_param:
111 aliases: ['max-url-param']
112 type: str
113 description: Maximum number of parameters in URL.
114 choices: ['disable', 'enable']
115 method:
116 type: str
117 description: Enable/disable HTTP method check.
118 choices: ['disable', 'enable']
119 param_length:
120 aliases: ['param-length']
121 type: str
122 description: Maximum length of parameter in URL, HTTP POST request or HTTP body.
123 choices: ['disable', 'enable']
124 pattern:
125 type: str
126 description: URL pattern.
127 regex:
128 type: str
129 description: Enable/disable regular expression based pattern match.
130 choices: ['disable', 'enable']
131 url_param_length:
132 aliases: ['url-param-length']
133 type: str
134 description: Maximum length of parameter in URL.
135 choices: ['disable', 'enable']
136 version:
137 type: str
138 description: Enable/disable HTTP version check.
139 choices: ['disable', 'enable']
140 header_length:
141 aliases: ['header-length']
142 type: dict
143 description: Header length.
144 suboptions:
145 action:
146 type: str
147 description: Action.
148 choices: ['allow', 'block']
149 length:
150 type: int
151 description: Length of HTTP header in bytes
152 log:
153 type: str
154 description: Enable/disable logging.
155 choices: ['disable', 'enable']
156 severity:
157 type: str
158 description: Severity.
159 choices: ['low', 'medium', 'high']
160 status:
161 type: str
162 description: Enable/disable the constraint.
163 choices: ['disable', 'enable']
164 hostname:
165 type: dict
166 description: Hostname.
167 suboptions:
168 action:
169 type: str
170 description: Action.
171 choices: ['allow', 'block']
172 log:
173 type: str
174 description: Enable/disable logging.
175 choices: ['disable', 'enable']
176 severity:
177 type: str
178 description: Severity.
179 choices: ['low', 'medium', 'high']
180 status:
181 type: str
182 description: Enable/disable the constraint.
183 choices: ['disable', 'enable']
184 line_length:
185 aliases: ['line-length']
186 type: dict
187 description: Line length.
188 suboptions:
189 action:
190 type: str
191 description: Action.
192 choices: ['allow', 'block']
193 length:
194 type: int
195 description: Length of HTTP line in bytes
196 log:
197 type: str
198 description: Enable/disable logging.
199 choices: ['disable', 'enable']
200 severity:
201 type: str
202 description: Severity.
203 choices: ['low', 'medium', 'high']
204 status:
205 type: str
206 description: Enable/disable the constraint.
207 choices: ['disable', 'enable']
208 malformed:
209 type: dict
210 description: Malformed.
211 suboptions:
212 action:
213 type: str
214 description: Action.
215 choices: ['allow', 'block']
216 log:
217 type: str
218 description: Enable/disable logging.
219 choices: ['disable', 'enable']
220 severity:
221 type: str
222 description: Severity.
223 choices: ['low', 'medium', 'high']
224 status:
225 type: str
226 description: Enable/disable the constraint.
227 choices: ['disable', 'enable']
228 max_cookie:
229 aliases: ['max-cookie']
230 type: dict
231 description: Max cookie.
232 suboptions:
233 action:
234 type: str
235 description: Action.
236 choices: ['allow', 'block']
237 log:
238 type: str
239 description: Enable/disable logging.
240 choices: ['disable', 'enable']
241 max_cookie:
242 aliases: ['max-cookie']
243 type: int
244 description: Maximum number of cookies in HTTP request
245 severity:
246 type: str
247 description: Severity.
248 choices: ['low', 'medium', 'high']
249 status:
250 type: str
251 description: Enable/disable the constraint.
252 choices: ['disable', 'enable']
253 max_header_line:
254 aliases: ['max-header-line']
255 type: dict
256 description: Max header line.
257 suboptions:
258 action:
259 type: str
260 description: Action.
261 choices: ['allow', 'block']
262 log:
263 type: str
264 description: Enable/disable logging.
265 choices: ['disable', 'enable']
266 max_header_line:
267 aliases: ['max-header-line']
268 type: int
269 description: Maximum number HTTP header lines
270 severity:
271 type: str
272 description: Severity.
273 choices: ['low', 'medium', 'high']
274 status:
275 type: str
276 description: Enable/disable the constraint.
277 choices: ['disable', 'enable']
278 max_range_segment:
279 aliases: ['max-range-segment']
280 type: dict
281 description: Max range segment.
282 suboptions:
283 action:
284 type: str
285 description: Action.
286 choices: ['allow', 'block']
287 log:
288 type: str
289 description: Enable/disable logging.
290 choices: ['disable', 'enable']
291 max_range_segment:
292 aliases: ['max-range-segment']
293 type: int
294 description: Maximum number of range segments in HTTP range line
295 severity:
296 type: str
297 description: Severity.
298 choices: ['low', 'medium', 'high']
299 status:
300 type: str
301 description: Enable/disable the constraint.
302 choices: ['disable', 'enable']
303 max_url_param:
304 aliases: ['max-url-param']
305 type: dict
306 description: Max url param.
307 suboptions:
308 action:
309 type: str
310 description: Action.
311 choices: ['allow', 'block']
312 log:
313 type: str
314 description: Enable/disable logging.
315 choices: ['disable', 'enable']
316 max_url_param:
317 aliases: ['max-url-param']
318 type: int
319 description: Maximum number of parameters in URL
320 severity:
321 type: str
322 description: Severity.
323 choices: ['low', 'medium', 'high']
324 status:
325 type: str
326 description: Enable/disable the constraint.
327 choices: ['disable', 'enable']
328 method:
329 type: dict
330 description: Method.
331 suboptions:
332 action:
333 type: str
334 description: Action.
335 choices: ['allow', 'block']
336 log:
337 type: str
338 description: Enable/disable logging.
339 choices: ['disable', 'enable']
340 severity:
341 type: str
342 description: Severity.
343 choices: ['low', 'medium', 'high']
344 status:
345 type: str
346 description: Enable/disable the constraint.
347 choices: ['disable', 'enable']
348 param_length:
349 aliases: ['param-length']
350 type: dict
351 description: Param length.
352 suboptions:
353 action:
354 type: str
355 description: Action.
356 choices: ['allow', 'block']
357 length:
358 type: int
359 description: Maximum length of parameter in URL, HTTP POST request or HTTP body in bytes
360 log:
361 type: str
362 description: Enable/disable logging.
363 choices: ['disable', 'enable']
364 severity:
365 type: str
366 description: Severity.
367 choices: ['low', 'medium', 'high']
368 status:
369 type: str
370 description: Enable/disable the constraint.
371 choices: ['disable', 'enable']
372 url_param_length:
373 aliases: ['url-param-length']
374 type: dict
375 description: Url param length.
376 suboptions:
377 action:
378 type: str
379 description: Action.
380 choices: ['allow', 'block']
381 length:
382 type: int
383 description: Maximum length of URL parameter in bytes
384 log:
385 type: str
386 description: Enable/disable logging.
387 choices: ['disable', 'enable']
388 severity:
389 type: str
390 description: Severity.
391 choices: ['low', 'medium', 'high']
392 status:
393 type: str
394 description: Enable/disable the constraint.
395 choices: ['disable', 'enable']
396 version:
397 type: dict
398 description: Version.
399 suboptions:
400 action:
401 type: str
402 description: Action.
403 choices: ['allow', 'block']
404 log:
405 type: str
406 description: Enable/disable logging.
407 choices: ['disable', 'enable']
408 severity:
409 type: str
410 description: Severity.
411 choices: ['low', 'medium', 'high']
412 status:
413 type: str
414 description: Enable/disable the constraint.
415 choices: ['disable', 'enable']
416 '''
417
418 EXAMPLES = '''
419 - name: Example playbook (generated based on argument schema)
420 hosts: fortimanagers
421 connection: httpapi
422 gather_facts: false
423 tasks:
424 - name: WAF HTTP protocol restrictions.
425 fortinet.fortimanager.fmgr_waf_profile_constraint:
426 # workspace_locking_adom: <global or your adom name>
427 adom: <your own value>
428 profile: <your own value>
429 waf_profile_constraint:
430 # content_length:
431 # action: <value in [allow, block]>
432 # length: <integer>
433 # log: <value in [disable, enable]>
434 # severity: <value in [low, medium, high]>
435 # status: <value in [disable, enable]>
436 # exception:
437 # - address: <string>
438 # content_length: <value in [disable, enable]>
439 # header_length: <value in [disable, enable]>
440 # hostname: <value in [disable, enable]>
441 # id: <integer>
442 # line_length: <value in [disable, enable]>
443 # malformed: <value in [disable, enable]>
444 # max_cookie: <value in [disable, enable]>
445 # max_header_line: <value in [disable, enable]>
446 # max_range_segment: <value in [disable, enable]>
447 # max_url_param: <value in [disable, enable]>
448 # method: <value in [disable, enable]>
449 # param_length: <value in [disable, enable]>
450 # pattern: <string>
451 # regex: <value in [disable, enable]>
452 # url_param_length: <value in [disable, enable]>
453 # version: <value in [disable, enable]>
454 # header_length:
455 # action: <value in [allow, block]>
456 # length: <integer>
457 # log: <value in [disable, enable]>
458 # severity: <value in [low, medium, high]>
459 # status: <value in [disable, enable]>
460 # hostname:
461 # action: <value in [allow, block]>
462 # log: <value in [disable, enable]>
463 # severity: <value in [low, medium, high]>
464 # status: <value in [disable, enable]>
465 # line_length:
466 # action: <value in [allow, block]>
467 # length: <integer>
468 # log: <value in [disable, enable]>
469 # severity: <value in [low, medium, high]>
470 # status: <value in [disable, enable]>
471 # malformed:
472 # action: <value in [allow, block]>
473 # log: <value in [disable, enable]>
474 # severity: <value in [low, medium, high]>
475 # status: <value in [disable, enable]>
476 # max_cookie:
477 # action: <value in [allow, block]>
478 # log: <value in [disable, enable]>
479 # max_cookie: <integer>
480 # severity: <value in [low, medium, high]>
481 # status: <value in [disable, enable]>
482 # max_header_line:
483 # action: <value in [allow, block]>
484 # log: <value in [disable, enable]>
485 # max_header_line: <integer>
486 # severity: <value in [low, medium, high]>
487 # status: <value in [disable, enable]>
488 # max_range_segment:
489 # action: <value in [allow, block]>
490 # log: <value in [disable, enable]>
491 # max_range_segment: <integer>
492 # severity: <value in [low, medium, high]>
493 # status: <value in [disable, enable]>
494 # max_url_param:
495 # action: <value in [allow, block]>
496 # log: <value in [disable, enable]>
497 # max_url_param: <integer>
498 # severity: <value in [low, medium, high]>
499 # status: <value in [disable, enable]>
500 # method:
501 # action: <value in [allow, block]>
502 # log: <value in [disable, enable]>
503 # severity: <value in [low, medium, high]>
504 # status: <value in [disable, enable]>
505 # param_length:
506 # action: <value in [allow, block]>
507 # length: <integer>
508 # log: <value in [disable, enable]>
509 # severity: <value in [low, medium, high]>
510 # status: <value in [disable, enable]>
511 # url_param_length:
512 # action: <value in [allow, block]>
513 # length: <integer>
514 # log: <value in [disable, enable]>
515 # severity: <value in [low, medium, high]>
516 # status: <value in [disable, enable]>
517 # version:
518 # action: <value in [allow, block]>
519 # log: <value in [disable, enable]>
520 # severity: <value in [low, medium, high]>
521 # status: <value in [disable, enable]>
522 '''
523
524 RETURN = '''
525 meta:
526 description: The result of the request.
527 type: dict
528 returned: always
529 contains:
530 request_url:
531 description: The full url requested.
532 returned: always
533 type: str
534 sample: /sys/login/user
535 response_code:
536 description: The status of api request.
537 returned: always
538 type: int
539 sample: 0
540 response_data:
541 description: The api response.
542 type: list
543 returned: always
544 response_message:
545 description: The descriptive message of the api response.
546 type: str
547 returned: always
548 sample: OK.
549 system_information:
550 description: The information of the target system.
551 type: dict
552 returned: always
553 rc:
554 description: The status the request.
555 type: int
556 returned: always
557 sample: 0
558 version_check_warning:
559 description: Warning if the parameters used in the playbook are not supported by the current FortiManager version.
560 type: list
561 returned: complex
562 '''
563 from ansible.module_utils.basic import AnsibleModule
564 from ansible.module_utils.connection import Connection
565 from ansible_collections.fortinet.fortimanager.plugins.module_utils.napi import NAPIManager, check_galaxy_version, check_parameter_bypass
566 from ansible_collections.fortinet.fortimanager.plugins.module_utils.common import get_module_arg_spec
567
568
569 def main():
570 urls_list = [
571 '/pm/config/adom/{adom}/obj/waf/profile/{profile}/constraint',
572 '/pm/config/global/obj/waf/profile/{profile}/constraint'
573 ]
574 module_arg_spec = {
575 'adom': {'required': True, 'type': 'str'},
576 'profile': {'required': True, 'type': 'str'},
577 'revision_note': {'type': 'str'},
578 'waf_profile_constraint': {
579 'type': 'dict', 'v_range': [['6.0.0', '']],
580 'options': {
581 'content-length': {
582 'type': 'dict',
583 'options': {
584 'action': {'choices': ['allow', 'block'], 'type': 'str'},
585 'length': {'type': 'int'},
586 'log': {'choices': ['disable', 'enable'], 'type': 'str'},
587 'severity': {'choices': ['low', 'medium', 'high'], 'type': 'str'},
588 'status': {'choices': ['disable', 'enable'], 'type': 'str'}
589 }
590 },
591 'exception': {
592 'type': 'list',
593 'options': {
594 'address': {'type': 'str'},
595 'content-length': {'choices': ['disable', 'enable'], 'type': 'str'},
596 'header-length': {'choices': ['disable', 'enable'], 'type': 'str'},
597 'hostname': {'choices': ['disable', 'enable'], 'type': 'str'},
598 'id': {'type': 'int'},
599 'line-length': {'choices': ['disable', 'enable'], 'type': 'str'},
600 'malformed': {'choices': ['disable', 'enable'], 'type': 'str'},
601 'max-cookie': {'choices': ['disable', 'enable'], 'type': 'str'},
602 'max-header-line': {'choices': ['disable', 'enable'], 'type': 'str'},
603 'max-range-segment': {'choices': ['disable', 'enable'], 'type': 'str'},
604 'max-url-param': {'choices': ['disable', 'enable'], 'type': 'str'},
605 'method': {'choices': ['disable', 'enable'], 'type': 'str'},
606 'param-length': {'choices': ['disable', 'enable'], 'type': 'str'},
607 'pattern': {'type': 'str'},
608 'regex': {'choices': ['disable', 'enable'], 'type': 'str'},
609 'url-param-length': {'choices': ['disable', 'enable'], 'type': 'str'},
610 'version': {'choices': ['disable', 'enable'], 'type': 'str'}
611 },
612 'elements': 'dict'
613 },
614 'header-length': {
615 'type': 'dict',
616 'options': {
617 'action': {'choices': ['allow', 'block'], 'type': 'str'},
618 'length': {'type': 'int'},
619 'log': {'choices': ['disable', 'enable'], 'type': 'str'},
620 'severity': {'choices': ['low', 'medium', 'high'], 'type': 'str'},
621 'status': {'choices': ['disable', 'enable'], 'type': 'str'}
622 }
623 },
624 'hostname': {
625 'type': 'dict',
626 'options': {
627 'action': {'choices': ['allow', 'block'], 'type': 'str'},
628 'log': {'choices': ['disable', 'enable'], 'type': 'str'},
629 'severity': {'choices': ['low', 'medium', 'high'], 'type': 'str'},
630 'status': {'choices': ['disable', 'enable'], 'type': 'str'}
631 }
632 },
633 'line-length': {
634 'type': 'dict',
635 'options': {
636 'action': {'choices': ['allow', 'block'], 'type': 'str'},
637 'length': {'type': 'int'},
638 'log': {'choices': ['disable', 'enable'], 'type': 'str'},
639 'severity': {'choices': ['low', 'medium', 'high'], 'type': 'str'},
640 'status': {'choices': ['disable', 'enable'], 'type': 'str'}
641 }
642 },
643 'malformed': {
644 'type': 'dict',
645 'options': {
646 'action': {'choices': ['allow', 'block'], 'type': 'str'},
647 'log': {'choices': ['disable', 'enable'], 'type': 'str'},
648 'severity': {'choices': ['low', 'medium', 'high'], 'type': 'str'},
649 'status': {'choices': ['disable', 'enable'], 'type': 'str'}
650 }
651 },
652 'max-cookie': {
653 'type': 'dict',
654 'options': {
655 'action': {'choices': ['allow', 'block'], 'type': 'str'},
656 'log': {'choices': ['disable', 'enable'], 'type': 'str'},
657 'max-cookie': {'type': 'int'},
658 'severity': {'choices': ['low', 'medium', 'high'], 'type': 'str'},
659 'status': {'choices': ['disable', 'enable'], 'type': 'str'}
660 }
661 },
662 'max-header-line': {
663 'type': 'dict',
664 'options': {
665 'action': {'choices': ['allow', 'block'], 'type': 'str'},
666 'log': {'choices': ['disable', 'enable'], 'type': 'str'},
667 'max-header-line': {'type': 'int'},
668 'severity': {'choices': ['low', 'medium', 'high'], 'type': 'str'},
669 'status': {'choices': ['disable', 'enable'], 'type': 'str'}
670 }
671 },
672 'max-range-segment': {
673 'type': 'dict',
674 'options': {
675 'action': {'choices': ['allow', 'block'], 'type': 'str'},
676 'log': {'choices': ['disable', 'enable'], 'type': 'str'},
677 'max-range-segment': {'type': 'int'},
678 'severity': {'choices': ['low', 'medium', 'high'], 'type': 'str'},
679 'status': {'choices': ['disable', 'enable'], 'type': 'str'}
680 }
681 },
682 'max-url-param': {
683 'type': 'dict',
684 'options': {
685 'action': {'choices': ['allow', 'block'], 'type': 'str'},
686 'log': {'choices': ['disable', 'enable'], 'type': 'str'},
687 'max-url-param': {'type': 'int'},
688 'severity': {'choices': ['low', 'medium', 'high'], 'type': 'str'},
689 'status': {'choices': ['disable', 'enable'], 'type': 'str'}
690 }
691 },
692 'method': {
693 'type': 'dict',
694 'options': {
695 'action': {'choices': ['allow', 'block'], 'type': 'str'},
696 'log': {'choices': ['disable', 'enable'], 'type': 'str'},
697 'severity': {'choices': ['low', 'medium', 'high'], 'type': 'str'},
698 'status': {'choices': ['disable', 'enable'], 'type': 'str'}
699 }
700 },
701 'param-length': {
702 'type': 'dict',
703 'options': {
704 'action': {'choices': ['allow', 'block'], 'type': 'str'},
705 'length': {'type': 'int'},
706 'log': {'choices': ['disable', 'enable'], 'type': 'str'},
707 'severity': {'choices': ['low', 'medium', 'high'], 'type': 'str'},
708 'status': {'choices': ['disable', 'enable'], 'type': 'str'}
709 }
710 },
711 'url-param-length': {
712 'type': 'dict',
713 'options': {
714 'action': {'choices': ['allow', 'block'], 'type': 'str'},
715 'length': {'type': 'int'},
716 'log': {'choices': ['disable', 'enable'], 'type': 'str'},
717 'severity': {'choices': ['low', 'medium', 'high'], 'type': 'str'},
718 'status': {'choices': ['disable', 'enable'], 'type': 'str'}
719 }
720 },
721 'version': {
722 'type': 'dict',
723 'options': {
724 'action': {'choices': ['allow', 'block'], 'type': 'str'},
725 'log': {'choices': ['disable', 'enable'], 'type': 'str'},
726 'severity': {'choices': ['low', 'medium', 'high'], 'type': 'str'},
727 'status': {'choices': ['disable', 'enable'], 'type': 'str'}
728 }
729 }
730 }
731 }
732 }
733
734 module_option_spec = get_module_arg_spec('partial crud')
735 module_arg_spec.update(module_option_spec)
736 check_galaxy_version(module_arg_spec)
737 module = AnsibleModule(argument_spec=check_parameter_bypass(module_arg_spec, 'waf_profile_constraint'),
738 supports_check_mode=True)
739 if not module._socket_path:
740 module.fail_json(msg='MUST RUN IN HTTPAPI MODE')
741 connection = Connection(module._socket_path)
742 fmgr = NAPIManager('partial crud', module_arg_spec, urls_list,
743 None, 'data', module, connection)
744 fmgr.process_partial_crud()
745 module.exit_json(meta=module.params)
746
747
748 if __name__ == '__main__':
749 main()