| 1 |
#!/usr/bin/python |
| 2 |
# -*- coding: utf-8 -*- |
| 3 |
# |
| 4 |
# Ansible module to manage CheckPoint 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 = {'metadata_version': '1.1', |
| 25 |
'status': ['preview'], |
| 26 |
'supported_by': 'community'} |
| 27 |
|
| 28 |
DOCUMENTATION = """ |
| 29 |
--- |
| 30 |
module: cp_mgmt_resource_uri |
| 31 |
short_description: Manages resource-uri objects on Checkpoint over Web Services API |
| 32 |
description: |
| 33 |
- Manages resource-uri objects on Checkpoint devices including creating, updating and removing objects. |
| 34 |
- All operations are performed over Web Services API. |
| 35 |
- Available from R82 management version. |
| 36 |
version_added: "6.0.0" |
| 37 |
author: "Eden Brillant (@chkp-edenbr)" |
| 38 |
options: |
| 39 |
name: |
| 40 |
description: |
| 41 |
- Object name. |
| 42 |
type: str |
| 43 |
required: True |
| 44 |
use_this_resource_to: |
| 45 |
description: |
| 46 |
- Select the use of the URI resource. |
| 47 |
type: str |
| 48 |
choices: ['enforce_uri_capabilities', 'optimize_url_logging', 'enhance_ufp_performance'] |
| 49 |
connection_methods: |
| 50 |
description: |
| 51 |
- Connection methods. |
| 52 |
type: dict |
| 53 |
suboptions: |
| 54 |
transparent: |
| 55 |
description: |
| 56 |
- The security server is invisible to the client that originates the connection, and to the server. The Transparent connection method is |
| 57 |
the most secure. |
| 58 |
type: bool |
| 59 |
proxy: |
| 60 |
description: |
| 61 |
- The Resource is applied when people specify the Check Point Security Gateway as a proxy in their browser. |
| 62 |
type: bool |
| 63 |
tunneling: |
| 64 |
description: |
| 65 |
- The Resource is applied when people specify the Security Gateway as a proxy in their browser, and is used for connections where |
| 66 |
Security Gateway cannot examine the contents of the packets, not even the URL. |
| 67 |
type: bool |
| 68 |
uri_match_specification_type: |
| 69 |
description: |
| 70 |
- The type can be Wild Cards or UFP, where a UFP server holds categories of forbidden web sites. |
| 71 |
type: str |
| 72 |
choices: ['wildcards', 'ufp'] |
| 73 |
exception_track: |
| 74 |
description: |
| 75 |
- Configures how to track connections that match this rule but fail the content security checks. An example of an exception is a connection with |
| 76 |
an unsupported scheme or method. |
| 77 |
type: str |
| 78 |
choices: ['none', 'exception log', 'exception alert'] |
| 79 |
match_ufp: |
| 80 |
description: |
| 81 |
- Match-Ufp settings. |
| 82 |
type: dict |
| 83 |
suboptions: |
| 84 |
server: |
| 85 |
description: |
| 86 |
- The UID or Name of the UFP server that is an OPSEC certified third party application that checks URLs against a list of permitted categories. |
| 87 |
type: str |
| 88 |
caching_control: |
| 89 |
description: |
| 90 |
- Specifies if and how caching is to be enabled. |
| 91 |
type: str |
| 92 |
choices: ['security_gateway_one_request', 'security_gateway_two_requests', 'no_caching', 'ufp_server'] |
| 93 |
ignore_ufp_server_after_failure: |
| 94 |
description: |
| 95 |
- The UFP server will be ignored after numerous UFP server connections were unsuccessful. |
| 96 |
type: bool |
| 97 |
number_of_failures_before_ignore: |
| 98 |
description: |
| 99 |
- Signifies at what point the UFP server should be ignored. |
| 100 |
type: int |
| 101 |
timeout_before_reconnecting: |
| 102 |
description: |
| 103 |
- The amount of time that must pass before a UFP server connection should be attempted. |
| 104 |
type: int |
| 105 |
match_wildcards: |
| 106 |
description: |
| 107 |
- Match-Wildcards settings. |
| 108 |
type: dict |
| 109 |
suboptions: |
| 110 |
schemes: |
| 111 |
description: |
| 112 |
- Select the URI Schemes to which this resource applies. |
| 113 |
type: dict |
| 114 |
suboptions: |
| 115 |
http: |
| 116 |
description: |
| 117 |
- Http scheme. |
| 118 |
type: bool |
| 119 |
ftp: |
| 120 |
description: |
| 121 |
- Ftp scheme. |
| 122 |
type: bool |
| 123 |
gopher: |
| 124 |
description: |
| 125 |
- Gopher scheme. |
| 126 |
type: bool |
| 127 |
mailto: |
| 128 |
description: |
| 129 |
- Mailto scheme. |
| 130 |
type: bool |
| 131 |
news: |
| 132 |
description: |
| 133 |
- News scheme. |
| 134 |
type: bool |
| 135 |
wais: |
| 136 |
description: |
| 137 |
- Wais scheme. |
| 138 |
type: bool |
| 139 |
other: |
| 140 |
description: |
| 141 |
- You can specify another scheme in the Other field. You can use wildcards. |
| 142 |
type: str |
| 143 |
methods: |
| 144 |
description: |
| 145 |
- Select the URI Schemes to which this resource applies. |
| 146 |
type: dict |
| 147 |
suboptions: |
| 148 |
get: |
| 149 |
description: |
| 150 |
- GET method. |
| 151 |
type: bool |
| 152 |
post: |
| 153 |
description: |
| 154 |
- POST method. |
| 155 |
type: bool |
| 156 |
head: |
| 157 |
description: |
| 158 |
- HEAD method. |
| 159 |
type: bool |
| 160 |
put: |
| 161 |
description: |
| 162 |
- PUT method. |
| 163 |
type: bool |
| 164 |
other: |
| 165 |
description: |
| 166 |
- You can specify another method in the Other field. You can use wildcards. |
| 167 |
type: str |
| 168 |
host: |
| 169 |
description: |
| 170 |
- The functionality of the Host parameter depends on the DNS setup of the addressed server. For the host, only the IP address or the |
| 171 |
full DNS name should be used. |
| 172 |
type: str |
| 173 |
path: |
| 174 |
description: |
| 175 |
- Name matching is based on appending the file name in the request to the current working directory (unless the file name is already a |
| 176 |
full path name) and comparing the result to the path specified in the Resource definition. |
| 177 |
type: str |
| 178 |
query: |
| 179 |
description: |
| 180 |
- The parameters that are sent to the URI when it is accessed. |
| 181 |
type: str |
| 182 |
action: |
| 183 |
description: |
| 184 |
- Action settings. |
| 185 |
type: dict |
| 186 |
suboptions: |
| 187 |
replacement_uri: |
| 188 |
description: |
| 189 |
- If the Action in a rule which uses this resource is Drop or Reject, then the Replacement URI is displayed instead of the one requested by the user. |
| 190 |
type: str |
| 191 |
strip_script_tags: |
| 192 |
description: |
| 193 |
- Strip JAVA scripts. |
| 194 |
type: bool |
| 195 |
strip_applet_tags: |
| 196 |
description: |
| 197 |
- Strip JAVA applets. |
| 198 |
type: bool |
| 199 |
strip_activex_tags: |
| 200 |
description: |
| 201 |
- Strip activeX tags. |
| 202 |
type: bool |
| 203 |
strip_ftp_links: |
| 204 |
description: |
| 205 |
- Strip ftp links. |
| 206 |
type: bool |
| 207 |
strip_port_strings: |
| 208 |
description: |
| 209 |
- Strip ports. |
| 210 |
type: bool |
| 211 |
cvp: |
| 212 |
description: |
| 213 |
- CVP settings. |
| 214 |
type: dict |
| 215 |
suboptions: |
| 216 |
enable_cvp: |
| 217 |
description: |
| 218 |
- Select to enable the Content Vectoring Protocol. |
| 219 |
type: bool |
| 220 |
server: |
| 221 |
description: |
| 222 |
- The UID or Name of the CVP server, make sure the CVP server is already be defined as an OPSEC Application. |
| 223 |
type: str |
| 224 |
allowed_to_modify_content: |
| 225 |
description: |
| 226 |
- Configures the CVP server to inspect but not modify content. |
| 227 |
type: bool |
| 228 |
send_http_headers_to_cvp: |
| 229 |
description: |
| 230 |
- Select, if you would like the CVP server to check the HTTP headers of the message packets. |
| 231 |
type: bool |
| 232 |
reply_order: |
| 233 |
description: |
| 234 |
- Designates when the CVP server returns data to the Security Gateway security server. |
| 235 |
type: str |
| 236 |
choices: ['return_data_after_content_is_approved', 'return_data_before_content_is_approved'] |
| 237 |
send_http_request_to_cvp: |
| 238 |
description: |
| 239 |
- Used to protect against undesirable content in the HTTP request, for example, when inspecting peer-to-peer connections. |
| 240 |
type: bool |
| 241 |
send_only_unsafe_file_types: |
| 242 |
description: |
| 243 |
- Improves the performance of the CVP server. This option does not send to the CVP server traffic that is considered safe. |
| 244 |
type: bool |
| 245 |
soap: |
| 246 |
description: |
| 247 |
- SOAP settings. |
| 248 |
type: dict |
| 249 |
suboptions: |
| 250 |
inspection: |
| 251 |
description: |
| 252 |
- Allow all SOAP Requests, or Allow only SOAP requests specified in the following file-id. |
| 253 |
type: str |
| 254 |
choices: ['allow_all_soap_requests', 'allow_soap_requests_as_specified_in_file'] |
| 255 |
file_id: |
| 256 |
description: |
| 257 |
- A file containing SOAP requests. |
| 258 |
type: str |
| 259 |
choices: ['scheme1', 'scheme2', 'scheme3', 'scheme4', 'scheme5', 'scheme6', 'scheme7', 'scheme8', 'scheme9', 'scheme10'] |
| 260 |
track_connections: |
| 261 |
description: |
| 262 |
- The method of tracking SOAP connections. |
| 263 |
type: str |
| 264 |
choices: ['none', 'log', 'popup_alert', 'mail_alert', 'snmp_trap_alert', 'user_defined_alert_no', 'user_defined_alert_no', 'user_defined_alert_no'] |
| 265 |
tags: |
| 266 |
description: |
| 267 |
- Collection of tag identifiers. |
| 268 |
type: list |
| 269 |
elements: str |
| 270 |
color: |
| 271 |
description: |
| 272 |
- Color of the object. Should be one of existing colors. |
| 273 |
type: str |
| 274 |
choices: ['aquamarine', 'black', 'blue', 'crete blue', 'burlywood', 'cyan', 'dark green', 'khaki', 'orchid', 'dark orange', 'dark sea green', |
| 275 |
'pink', 'turquoise', 'dark blue', 'firebrick', 'brown', 'forest green', 'gold', 'dark gold', 'gray', 'dark gray', 'light green', 'lemon chiffon', |
| 276 |
'coral', 'sea green', 'sky blue', 'magenta', 'purple', 'slate blue', 'violet red', 'navy blue', 'olive', 'orange', 'red', 'sienna', 'yellow'] |
| 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-resource-uri |
| 300 |
cp_mgmt_resource_uri: |
| 301 |
connection_methods: |
| 302 |
transparent: 'false' |
| 303 |
tunneling: 'true' |
| 304 |
match_wildcards: |
| 305 |
host: hostName |
| 306 |
path: pathName |
| 307 |
name: newUriResource |
| 308 |
state: present |
| 309 |
uri_match_specification_type: wildcards |
| 310 |
use_this_resource_to: optimize_url_logging |
| 311 |
|
| 312 |
- name: set-resource-uri |
| 313 |
cp_mgmt_resource_uri: |
| 314 |
connection_methods: |
| 315 |
transparent: 'false' |
| 316 |
tunneling: 'true' |
| 317 |
match_wildcards: |
| 318 |
host: hostName |
| 319 |
path: pathName |
| 320 |
name: newUriResource |
| 321 |
state: present |
| 322 |
uri_match_specification_type: wildcards |
| 323 |
use_this_resource_to: optimize_url_logging |
| 324 |
|
| 325 |
- name: delete-resource-uri |
| 326 |
cp_mgmt_resource_uri: |
| 327 |
name: newUriResource |
| 328 |
state: absent |
| 329 |
""" |
| 330 |
|
| 331 |
RETURN = """ |
| 332 |
cp_mgmt_resource_uri: |
| 333 |
description: The checkpoint object created or updated. |
| 334 |
returned: always, except when deleting the object. |
| 335 |
type: dict |
| 336 |
""" |
| 337 |
|
| 338 |
from ansible.module_utils.basic import AnsibleModule |
| 339 |
from ansible_collections.check_point.mgmt.plugins.module_utils.checkpoint import checkpoint_argument_spec_for_objects, api_call |
| 340 |
|
| 341 |
|
| 342 |
def main(): |
| 343 |
argument_spec = dict( |
| 344 |
name=dict(type='str', required=True), |
| 345 |
use_this_resource_to=dict(type='str', choices=['enforce_uri_capabilities', 'optimize_url_logging', 'enhance_ufp_performance']), |
| 346 |
connection_methods=dict(type='dict', options=dict( |
| 347 |
transparent=dict(type='bool'), |
| 348 |
proxy=dict(type='bool'), |
| 349 |
tunneling=dict(type='bool') |
| 350 |
)), |
| 351 |
uri_match_specification_type=dict(type='str', choices=['wildcards', 'ufp']), |
| 352 |
exception_track=dict(type='str', choices=['none', 'exception log', 'exception alert']), |
| 353 |
match_ufp=dict(type='dict', options=dict( |
| 354 |
server=dict(type='str'), |
| 355 |
caching_control=dict(type='str', choices=['security_gateway_one_request', 'security_gateway_two_requests', 'no_caching', 'ufp_server']), |
| 356 |
ignore_ufp_server_after_failure=dict(type='bool'), |
| 357 |
number_of_failures_before_ignore=dict(type='int'), |
| 358 |
timeout_before_reconnecting=dict(type='int') |
| 359 |
)), |
| 360 |
match_wildcards=dict(type='dict', options=dict( |
| 361 |
schemes=dict(type='dict', options=dict( |
| 362 |
http=dict(type='bool'), |
| 363 |
ftp=dict(type='bool'), |
| 364 |
gopher=dict(type='bool'), |
| 365 |
mailto=dict(type='bool'), |
| 366 |
news=dict(type='bool'), |
| 367 |
wais=dict(type='bool'), |
| 368 |
other=dict(type='str') |
| 369 |
)), |
| 370 |
methods=dict(type='dict', options=dict( |
| 371 |
get=dict(type='bool'), |
| 372 |
post=dict(type='bool'), |
| 373 |
head=dict(type='bool'), |
| 374 |
put=dict(type='bool'), |
| 375 |
other=dict(type='str') |
| 376 |
)), |
| 377 |
host=dict(type='str'), |
| 378 |
path=dict(type='str'), |
| 379 |
query=dict(type='str') |
| 380 |
)), |
| 381 |
action=dict(type='dict', options=dict( |
| 382 |
replacement_uri=dict(type='str'), |
| 383 |
strip_script_tags=dict(type='bool'), |
| 384 |
strip_applet_tags=dict(type='bool'), |
| 385 |
strip_activex_tags=dict(type='bool'), |
| 386 |
strip_ftp_links=dict(type='bool'), |
| 387 |
strip_port_strings=dict(type='bool') |
| 388 |
)), |
| 389 |
cvp=dict(type='dict', options=dict( |
| 390 |
enable_cvp=dict(type='bool'), |
| 391 |
server=dict(type='str'), |
| 392 |
allowed_to_modify_content=dict(type='bool'), |
| 393 |
send_http_headers_to_cvp=dict(type='bool'), |
| 394 |
reply_order=dict(type='str', choices=['return_data_after_content_is_approved', 'return_data_before_content_is_approved']), |
| 395 |
send_http_request_to_cvp=dict(type='bool'), |
| 396 |
send_only_unsafe_file_types=dict(type='bool') |
| 397 |
)), |
| 398 |
soap=dict(type='dict', options=dict( |
| 399 |
inspection=dict(type='str', choices=['allow_all_soap_requests', 'allow_soap_requests_as_specified_in_file']), |
| 400 |
file_id=dict(type='str', choices=['scheme1', 'scheme2', 'scheme3', 'scheme4', 'scheme5', 'scheme6', 'scheme7', 'scheme8', 'scheme9', 'scheme10']), |
| 401 |
track_connections=dict(type='str', choices=['none', 'log', 'popup_alert', 'mail_alert', |
| 402 |
'snmp_trap_alert', 'user_defined_alert_no', 'user_defined_alert_no', 'user_defined_alert_no']) |
| 403 |
)), |
| 404 |
tags=dict(type='list', elements='str'), |
| 405 |
color=dict(type='str', choices=['aquamarine', 'black', 'blue', 'crete blue', 'burlywood', 'cyan', 'dark green', |
| 406 |
'khaki', 'orchid', 'dark orange', 'dark sea green', 'pink', 'turquoise', 'dark blue', 'firebrick', 'brown', |
| 407 |
'forest green', 'gold', 'dark gold', 'gray', 'dark gray', 'light green', 'lemon chiffon', 'coral', 'sea green', |
| 408 |
'sky blue', 'magenta', 'purple', 'slate blue', 'violet red', 'navy blue', 'olive', 'orange', 'red', 'sienna', |
| 409 |
'yellow']), |
| 410 |
comments=dict(type='str'), |
| 411 |
details_level=dict(type='str', choices=['uid', 'standard', 'full']), |
| 412 |
ignore_warnings=dict(type='bool'), |
| 413 |
ignore_errors=dict(type='bool') |
| 414 |
) |
| 415 |
argument_spec.update(checkpoint_argument_spec_for_objects) |
| 416 |
|
| 417 |
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) |
| 418 |
api_call_object = 'resource-uri' |
| 419 |
|
| 420 |
result = api_call(module, api_call_object) |
| 421 |
module.exit_json(**result) |
| 422 |
|
| 423 |
|
| 424 |
if __name__ == '__main__': |
| 425 |
main() |