| 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_service_udp |
| 33 |
short_description: Manages service-udp objects on Check Point over Web Services API |
| 34 |
description: |
| 35 |
- Manages service-udp 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 |
name: |
| 42 |
description: |
| 43 |
- Object name. |
| 44 |
type: str |
| 45 |
required: True |
| 46 |
accept_replies: |
| 47 |
description: |
| 48 |
- N/A |
| 49 |
type: bool |
| 50 |
aggressive_aging: |
| 51 |
description: |
| 52 |
- Sets short (aggressive) timeouts for idle connections. |
| 53 |
type: dict |
| 54 |
suboptions: |
| 55 |
default_timeout: |
| 56 |
description: |
| 57 |
- Default aggressive aging timeout in seconds. |
| 58 |
type: int |
| 59 |
enable: |
| 60 |
description: |
| 61 |
- N/A |
| 62 |
type: bool |
| 63 |
timeout: |
| 64 |
description: |
| 65 |
- Aggressive aging timeout in seconds. |
| 66 |
type: int |
| 67 |
use_default_timeout: |
| 68 |
description: |
| 69 |
- N/A |
| 70 |
type: bool |
| 71 |
keep_connections_open_after_policy_installation: |
| 72 |
description: |
| 73 |
- Keep connections open after policy has been installed even if they are not allowed under the new policy. This overrides the settings in the |
| 74 |
Connection Persistence page. If you change this property, the change will not affect open connections, but only future connections. |
| 75 |
type: bool |
| 76 |
match_by_protocol_signature: |
| 77 |
description: |
| 78 |
- A value of true enables matching by the selected protocol's signature - the signature identifies the protocol as genuine. Select this option |
| 79 |
to limit the port to the specified protocol. If the selected protocol does not support matching by signature, this field cannot be set to true. |
| 80 |
- Available from R80.10 management version. |
| 81 |
type: bool |
| 82 |
match_for_any: |
| 83 |
description: |
| 84 |
- Indicates whether this service is used when 'Any' is set as the rule's service and there are several service objects with the same source port |
| 85 |
and protocol. |
| 86 |
type: bool |
| 87 |
override_default_settings: |
| 88 |
description: |
| 89 |
- Indicates whether this service is a Data Domain service which has been overridden. |
| 90 |
- Available from R80.10 management version. |
| 91 |
type: bool |
| 92 |
port: |
| 93 |
description: |
| 94 |
- The number of the port used to provide this service. To specify a port range, place a hyphen between the lowest and highest port numbers, for |
| 95 |
example 44-55. |
| 96 |
type: str |
| 97 |
protocol: |
| 98 |
description: |
| 99 |
- Select the protocol type associated with the service, and by implication, the management server (if any) that enforces Content Security and |
| 100 |
Authentication for the service. Selecting a Protocol Type invokes the specific protocol handlers for each protocol type, thus enabling higher level of |
| 101 |
security by parsing the protocol, and higher level of connectivity by tracking dynamic actions (such as opening of ports). |
| 102 |
- Available from R80.10 management version. |
| 103 |
type: str |
| 104 |
session_timeout: |
| 105 |
description: |
| 106 |
- Time (in seconds) before the session times out. |
| 107 |
type: int |
| 108 |
source_port: |
| 109 |
description: |
| 110 |
- Port number for the client side service. If specified, only those Source port Numbers will be Accepted, Dropped, or Rejected during packet |
| 111 |
inspection. Otherwise, the source port is not inspected. |
| 112 |
type: str |
| 113 |
sync_connections_on_cluster: |
| 114 |
description: |
| 115 |
- Enables state-synchronized High Availability or Load Sharing on a ClusterXL or OPSEC-certified cluster. |
| 116 |
type: bool |
| 117 |
tags: |
| 118 |
description: |
| 119 |
- Collection of tag identifiers. |
| 120 |
type: list |
| 121 |
elements: str |
| 122 |
use_default_session_timeout: |
| 123 |
description: |
| 124 |
- Use default virtual session timeout. |
| 125 |
- Available from R80.10 management version. |
| 126 |
type: bool |
| 127 |
color: |
| 128 |
description: |
| 129 |
- Color of the object. Should be one of existing colors. |
| 130 |
type: str |
| 131 |
choices: ['aquamarine', 'black', 'blue', 'crete blue', 'burlywood', 'cyan', 'dark green', 'khaki', 'orchid', 'dark orange', 'dark sea green', |
| 132 |
'pink', 'turquoise', 'dark blue', 'firebrick', 'brown', 'forest green', 'gold', 'dark gold', 'gray', 'dark gray', 'light green', 'lemon chiffon', |
| 133 |
'coral', 'sea green', 'sky blue', 'magenta', 'purple', 'slate blue', 'violet red', 'navy blue', 'olive', 'orange', 'red', 'sienna', 'yellow'] |
| 134 |
comments: |
| 135 |
description: |
| 136 |
- Comments string. |
| 137 |
type: str |
| 138 |
details_level: |
| 139 |
description: |
| 140 |
- 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 |
| 141 |
representation of the object. |
| 142 |
type: str |
| 143 |
choices: ['uid', 'standard', 'full'] |
| 144 |
groups: |
| 145 |
description: |
| 146 |
- Collection of group identifiers. |
| 147 |
type: list |
| 148 |
elements: str |
| 149 |
ignore_warnings: |
| 150 |
description: |
| 151 |
- Apply changes ignoring warnings. |
| 152 |
type: bool |
| 153 |
ignore_errors: |
| 154 |
description: |
| 155 |
- 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. |
| 156 |
type: bool |
| 157 |
extends_documentation_fragment: check_point.mgmt.checkpoint_objects |
| 158 |
""" |
| 159 |
|
| 160 |
EXAMPLES = """ |
| 161 |
- name: add-service-udp |
| 162 |
cp_mgmt_service_udp: |
| 163 |
accept_replies: false |
| 164 |
aggressive_aging: |
| 165 |
enable: true |
| 166 |
timeout: 360 |
| 167 |
use_default_timeout: false |
| 168 |
keep_connections_open_after_policy_installation: false |
| 169 |
match_for_any: true |
| 170 |
name: New_UDP_Service_1 |
| 171 |
port: 5669 |
| 172 |
session_timeout: 0 |
| 173 |
state: present |
| 174 |
sync_connections_on_cluster: true |
| 175 |
|
| 176 |
- name: set-service-udp |
| 177 |
cp_mgmt_service_udp: |
| 178 |
accept_replies: true |
| 179 |
aggressive_aging: |
| 180 |
default_timeout: 3600 |
| 181 |
color: green |
| 182 |
name: New_UDP_Service_1 |
| 183 |
port: 5656 |
| 184 |
state: present |
| 185 |
|
| 186 |
- name: delete-service-udp |
| 187 |
cp_mgmt_service_udp: |
| 188 |
name: New_UDP_Service_2 |
| 189 |
state: absent |
| 190 |
""" |
| 191 |
|
| 192 |
RETURN = """ |
| 193 |
cp_mgmt_service_udp: |
| 194 |
description: The checkpoint object created or updated. |
| 195 |
returned: always, except when deleting the object. |
| 196 |
type: dict |
| 197 |
""" |
| 198 |
|
| 199 |
from ansible.module_utils.basic import AnsibleModule |
| 200 |
from ansible_collections.check_point.mgmt.plugins.module_utils.checkpoint import ( |
| 201 |
checkpoint_argument_spec_for_objects, |
| 202 |
api_call, |
| 203 |
) |
| 204 |
|
| 205 |
|
| 206 |
def main(): |
| 207 |
argument_spec = dict( |
| 208 |
name=dict(type="str", required=True), |
| 209 |
accept_replies=dict(type="bool"), |
| 210 |
aggressive_aging=dict( |
| 211 |
type="dict", |
| 212 |
options=dict( |
| 213 |
default_timeout=dict(type="int"), |
| 214 |
enable=dict(type="bool"), |
| 215 |
timeout=dict(type="int"), |
| 216 |
use_default_timeout=dict(type="bool"), |
| 217 |
), |
| 218 |
), |
| 219 |
keep_connections_open_after_policy_installation=dict(type="bool"), |
| 220 |
match_by_protocol_signature=dict(type="bool"), |
| 221 |
match_for_any=dict(type="bool"), |
| 222 |
override_default_settings=dict(type="bool"), |
| 223 |
port=dict(type="str"), |
| 224 |
protocol=dict(type="str"), |
| 225 |
session_timeout=dict(type="int"), |
| 226 |
source_port=dict(type="str"), |
| 227 |
sync_connections_on_cluster=dict(type="bool"), |
| 228 |
tags=dict(type="list", elements="str"), |
| 229 |
use_default_session_timeout=dict(type="bool"), |
| 230 |
color=dict( |
| 231 |
type="str", |
| 232 |
choices=[ |
| 233 |
"aquamarine", |
| 234 |
"black", |
| 235 |
"blue", |
| 236 |
"crete blue", |
| 237 |
"burlywood", |
| 238 |
"cyan", |
| 239 |
"dark green", |
| 240 |
"khaki", |
| 241 |
"orchid", |
| 242 |
"dark orange", |
| 243 |
"dark sea green", |
| 244 |
"pink", |
| 245 |
"turquoise", |
| 246 |
"dark blue", |
| 247 |
"firebrick", |
| 248 |
"brown", |
| 249 |
"forest green", |
| 250 |
"gold", |
| 251 |
"dark gold", |
| 252 |
"gray", |
| 253 |
"dark gray", |
| 254 |
"light green", |
| 255 |
"lemon chiffon", |
| 256 |
"coral", |
| 257 |
"sea green", |
| 258 |
"sky blue", |
| 259 |
"magenta", |
| 260 |
"purple", |
| 261 |
"slate blue", |
| 262 |
"violet red", |
| 263 |
"navy blue", |
| 264 |
"olive", |
| 265 |
"orange", |
| 266 |
"red", |
| 267 |
"sienna", |
| 268 |
"yellow", |
| 269 |
], |
| 270 |
), |
| 271 |
comments=dict(type="str"), |
| 272 |
details_level=dict(type="str", choices=["uid", "standard", "full"]), |
| 273 |
groups=dict(type="list", elements="str"), |
| 274 |
ignore_warnings=dict(type="bool"), |
| 275 |
ignore_errors=dict(type="bool"), |
| 276 |
) |
| 277 |
argument_spec.update(checkpoint_argument_spec_for_objects) |
| 278 |
|
| 279 |
module = AnsibleModule( |
| 280 |
argument_spec=argument_spec, supports_check_mode=True |
| 281 |
) |
| 282 |
api_call_object = "service-udp" |
| 283 |
|
| 284 |
result = api_call(module, api_call_object) |
| 285 |
module.exit_json(**result) |
| 286 |
|
| 287 |
|
| 288 |
if __name__ == "__main__": |
| 289 |
main() |