Debian Codegraph @

ansible_collections/check_point/mgmt/plugins/modules/cp_mgmt_access_rule.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 #
4 # Ansible module to manage Check Point Firewall (c) 2019
5 #
6 # Ansible is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
10 #
11 # Ansible is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
18 #
19
20 from __future__ import absolute_import, division, print_function
21
22 __metaclass__ = type
23
24 ANSIBLE_METADATA = {
25 "metadata_version": "1.1",
26 "status": ["preview"],
27 "supported_by": "community",
28 }
29
30 DOCUMENTATION = """
31 ---
32 module: cp_mgmt_access_rule
33 short_description: Manages access-rule objects on Check Point over Web Services API
34 description:
35 - Manages access-rule objects on Check Point devices including creating, updating and removing objects.
36 - All operations are performed over Web Services API.
37 - Available from R80 management version.
38 version_added: "1.0.0"
39 author: "Or Soffer (@chkp-orso)"
40 options:
41 layer:
42 description:
43 - Layer that the rule belongs to identified by the name or UID.
44 type: str
45 position:
46 description:
47 - Position in the rulebase. The use of values "top" and "bottom" may not be idempotent.
48 type: str
49 relative_position:
50 description:
51 - Position in the rulebase.
52 - Use of this field may not be idempotent.
53 type: dict
54 suboptions:
55 below:
56 description:
57 - Add rule below specific rule/section identified by name (limited to 50 rules if
58 search_entire_rulebase is False).
59 type: str
60 above:
61 description:
62 - Add rule above specific rule/section identified by name (limited to 50 rules if
63 search_entire_rulebase is False).
64 type: str
65 top:
66 description:
67 - Add rule to the top of a specific section identified by name (limited to 50 rules if
68 search_entire_rulebase is False).
69 type: str
70 bottom:
71 description:
72 - Add rule to the bottom of a specific section identified by name (limited to 50 rules if
73 search_entire_rulebase is False).
74 type: str
75 search_entire_rulebase:
76 description:
77 - Whether to search the entire rulebase for a rule that's been edited in its relative_position field to make sure
78 there indeed has been a change in its position or the section it might be in.
79 type: bool
80 default: False
81 name:
82 description:
83 - Object name.
84 type: str
85 required: True
86 action:
87 description:
88 - a "Accept", "Drop", "Ask", "Inform", "Reject", "User Auth", "Client Auth", "Apply Layer".
89 type: str
90 action_settings:
91 description:
92 - Action settings.
93 type: dict
94 suboptions:
95 enable_identity_captive_portal:
96 description:
97 - N/A
98 type: bool
99 limit:
100 description:
101 - N/A
102 type: str
103 content:
104 description:
105 - List of processed file types that this rule applies on.
106 - Available from R80.10 management version.
107 type: list
108 elements: dict
109 content_direction:
110 description:
111 - On which direction the file types processing is applied.
112 - Available from R80.10 management version.
113 type: str
114 choices: ['any', 'up', 'down']
115 content_negate:
116 description:
117 - True if negate is set for data.
118 - Available from R80.10 management version.
119 type: bool
120 custom_fields:
121 description:
122 - Custom fields.
123 type: dict
124 suboptions:
125 field_1:
126 description:
127 - First custom field.
128 type: str
129 field_2:
130 description:
131 - Second custom field.
132 type: str
133 field_3:
134 description:
135 - Third custom field.
136 type: str
137 destination:
138 description:
139 - Collection of Network objects identified by the name or UID.
140 type: list
141 elements: str
142 destination_negate:
143 description:
144 - True if negate is set for destination.
145 type: bool
146 enabled:
147 description:
148 - Enable/Disable the rule.
149 type: bool
150 inline_layer:
151 description:
152 - Inline Layer identified by the name or UID. Relevant only if "Action" was set to "Apply Layer".
153 type: str
154 install_on:
155 description:
156 - Which Gateways identified by the name or UID to install the policy on.
157 type: list
158 elements: str
159 service:
160 description:
161 - Collection of Network objects identified by the name or UID.
162 type: list
163 elements: str
164 service_negate:
165 description:
166 - True if negate is set for service.
167 type: bool
168 source:
169 description:
170 - Collection of Network objects identified by the name or UID.
171 type: list
172 elements: str
173 source_negate:
174 description:
175 - True if negate is set for source.
176 type: bool
177 time:
178 description:
179 - List of time objects. For example, "Weekend", "Off-Work", "Every-Day".
180 type: list
181 elements: str
182 track:
183 description:
184 - Track Settings.
185 - Available from R80.10 management version.
186 type: dict
187 suboptions:
188 accounting:
189 description:
190 - Turns accounting for track on and off.
191 type: bool
192 alert:
193 description:
194 - Type of alert for the track.
195 type: str
196 choices: ['none', 'alert', 'snmp', 'mail', 'user alert 1', 'user alert 2', 'user alert 3']
197 enable_firewall_session:
198 description:
199 - Determine whether to generate session log to firewall only connections.
200 - Available from R80.20 management version.
201 type: bool
202 per_connection:
203 description:
204 - Determines whether to perform the log per connection.
205 type: bool
206 per_session:
207 description:
208 - Determines whether to perform the log per session.
209 type: bool
210 type:
211 description:
212 - a "Log", "Extended Log", "Detailed Log", "None".
213 type: str
214 user_check:
215 description:
216 - User check settings.
217 type: dict
218 suboptions:
219 confirm:
220 description:
221 - N/A
222 type: str
223 choices: ['per rule', 'per category', 'per application/site', 'per data type']
224 custom_frequency:
225 description:
226 - N/A
227 type: dict
228 suboptions:
229 every:
230 description:
231 - N/A
232 type: int
233 unit:
234 description:
235 - N/A
236 type: str
237 choices: ['hours', 'days', 'weeks', 'months']
238 frequency:
239 description:
240 - N/A
241 type: str
242 choices: ['once a day', 'once a week', 'once a month', 'custom frequency...']
243 interaction:
244 description:
245 - N/A
246 type: str
247 vpn_list:
248 description:
249 - Communities or Directional.
250 type: list
251 elements: dict
252 suboptions:
253 community:
254 description:
255 - List of community name or UID.
256 type: list
257 elements: str
258 directional:
259 description:
260 - Communities directional match condition.
261 type: list
262 elements: dict
263 suboptions:
264 from:
265 description:
266 - From community name or UID.
267 type: str
268 to:
269 description:
270 - To community name or UID.
271 type: str
272 vpn:
273 description:
274 - Any or All_GwToGw.
275 type: str
276 choices: ['Any', 'All_GwToGw']
277 comments:
278 description:
279 - Comments string.
280 type: str
281 details_level:
282 description:
283 - The level of detail for some of the fields in the response can vary from showing only the UID value of the object to a fully detailed
284 representation of the object.
285 type: str
286 choices: ['uid', 'standard', 'full']
287 ignore_warnings:
288 description:
289 - Apply changes ignoring warnings.
290 type: bool
291 ignore_errors:
292 description:
293 - Apply changes ignoring errors. You won't be able to publish such a changes. If ignore-warnings flag was omitted - warnings will also be ignored.
294 type: bool
295 extends_documentation_fragment: check_point.mgmt.checkpoint_objects
296 """
297
298 EXAMPLES = """
299 - name: add-access-rule
300 cp_mgmt_access_rule:
301 layer: Network
302 name: Rule 1
303 position: 1
304 service:
305 - SMTP
306 - AOL
307 vpn: All_GwToGw
308 state: present
309
310 - name: set-access-rule
311 cp_mgmt_access_rule:
312 action: Ask
313 action_settings:
314 enable_identity_captive_portal: true
315 limit: Upload_1Gbps
316 layer: Network
317 name: Rule 1
318 state: present
319
320 - name: delete-access-rule
321 cp_mgmt_access_rule:
322 layer: Network
323 name: Rule 2
324 state: absent
325 """
326
327 RETURN = """
328 cp_mgmt_access_rule:
329 description: The checkpoint object created or updated.
330 returned: always, except when deleting the object.
331 type: dict
332 """
333
334 from ansible.module_utils.basic import AnsibleModule
335 from ansible_collections.check_point.mgmt.plugins.module_utils.checkpoint import (
336 checkpoint_argument_spec_for_objects,
337 api_call,
338 api_call_for_rule,
339 )
340
341
342 def main():
343 argument_spec = dict(
344 layer=dict(type="str"),
345 position=dict(type="str"),
346 relative_position=dict(
347 type="dict",
348 options=dict(
349 below=dict(type="str"),
350 above=dict(type="str"),
351 top=dict(type="str"),
352 bottom=dict(type="str"),
353 ),
354 ),
355 search_entire_rulebase=dict(type="bool", default=False),
356 name=dict(type="str", required=True),
357 action=dict(type="str"),
358 action_settings=dict(
359 type="dict",
360 options=dict(
361 enable_identity_captive_portal=dict(type="bool"),
362 limit=dict(type="str"),
363 ),
364 ),
365 content=dict(type="list", elements="dict"),
366 content_direction=dict(type="str", choices=["any", "up", "down"]),
367 content_negate=dict(type="bool"),
368 custom_fields=dict(
369 type="dict",
370 options=dict(
371 field_1=dict(type="str"),
372 field_2=dict(type="str"),
373 field_3=dict(type="str"),
374 ),
375 ),
376 destination=dict(type="list", elements="str"),
377 destination_negate=dict(type="bool"),
378 enabled=dict(type="bool"),
379 inline_layer=dict(type="str"),
380 install_on=dict(type="list", elements="str"),
381 service=dict(type="list", elements="str"),
382 service_negate=dict(type="bool"),
383 source=dict(type="list", elements="str"),
384 source_negate=dict(type="bool"),
385 time=dict(type="list", elements="str"),
386 track=dict(
387 type="dict",
388 options=dict(
389 accounting=dict(type="bool"),
390 alert=dict(
391 type="str",
392 choices=[
393 "none",
394 "alert",
395 "snmp",
396 "mail",
397 "user alert 1",
398 "user alert 2",
399 "user alert 3",
400 ],
401 ),
402 enable_firewall_session=dict(type="bool"),
403 per_connection=dict(type="bool"),
404 per_session=dict(type="bool"),
405 type=dict(type="str"),
406 ),
407 ),
408 user_check=dict(
409 type="dict",
410 options=dict(
411 confirm=dict(
412 type="str",
413 choices=[
414 "per rule",
415 "per category",
416 "per application/site",
417 "per data type",
418 ],
419 ),
420 custom_frequency=dict(
421 type="dict",
422 options=dict(
423 every=dict(type="int"),
424 unit=dict(
425 type="str",
426 choices=["hours", "days", "weeks", "months"],
427 ),
428 ),
429 ),
430 frequency=dict(
431 type="str",
432 choices=[
433 "once a day",
434 "once a week",
435 "once a month",
436 "custom frequency...",
437 ],
438 ),
439 interaction=dict(type="str"),
440 ),
441 ),
442 vpn_list=dict(
443 type="list",
444 elements="dict",
445 options=dict(
446 community=dict(type="list", elements="str"),
447 directional=dict(
448 type="list",
449 elements="dict",
450 options=dict(to=dict(type="str")),
451 ),
452 ),
453 ),
454 vpn=dict(type="str", choices=["Any", "All_GwToGw"]),
455 comments=dict(type="str"),
456 details_level=dict(type="str", choices=["uid", "standard", "full"]),
457 ignore_warnings=dict(type="bool"),
458 ignore_errors=dict(type="bool"),
459 )
460 argument_spec["vpn_list"]["options"]["directional"]["options"][
461 "from"
462 ] = dict(type="str")
463 argument_spec.update(checkpoint_argument_spec_for_objects)
464
465 module = AnsibleModule(
466 argument_spec=argument_spec, supports_check_mode=True
467 )
468 api_call_object = "access-rule"
469
470 if module.params["vpn_list"] is not None:
471 if module.params["vpn"] is not None:
472 raise AssertionError(
473 "The use of both 'vpn_list' and 'vpn' arguments isn't allowed"
474 )
475 module.params["vpn"] = module.params["vpn_list"]
476 module.params.pop("vpn_list")
477
478 if module.params["relative_position"] is not None:
479 if module.params["position"] is not None:
480 raise AssertionError(
481 "The use of both 'relative_position' and 'position' arguments isn't allowed"
482 )
483 module.params["position"] = module.params["relative_position"]
484 module.params.pop("relative_position")
485
486 if module.params["action"] is None and module.params["position"] is None:
487 module.params.pop("search_entire_rulebase")
488 result = api_call(module, api_call_object)
489 else:
490 result = api_call_for_rule(module, api_call_object)
491
492 module.exit_json(**result)
493
494
495 if __name__ == "__main__":
496 main()