| 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_opsec_trusted_ca |
| 31 |
short_description: Manages opsec-trusted-ca objects on Checkpoint over Web Services API |
| 32 |
description: |
| 33 |
- Manages opsec-trusted-ca 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 |
base64_certificate: |
| 45 |
description: |
| 46 |
- Certificate file encoded in base64. |
| 47 |
type: str |
| 48 |
automatic_enrollment: |
| 49 |
description: |
| 50 |
- Certificate automatic enrollment. |
| 51 |
type: dict |
| 52 |
suboptions: |
| 53 |
automatically_enroll_certificate: |
| 54 |
description: |
| 55 |
- Whether to automatically enroll certificate. |
| 56 |
type: bool |
| 57 |
protocol: |
| 58 |
description: |
| 59 |
- Protocol that communicates with the certificate authority. Available only if "automatically-enroll-certificate" parameter is set to true. |
| 60 |
type: str |
| 61 |
choices: ['scep', 'cmpv2', 'cmpv1'] |
| 62 |
scep_settings: |
| 63 |
description: |
| 64 |
- Scep protocol settings. Available only if "protocol" is set to "scep". |
| 65 |
type: dict |
| 66 |
suboptions: |
| 67 |
ca_identifier: |
| 68 |
description: |
| 69 |
- Certificate authority identifier. |
| 70 |
type: str |
| 71 |
url: |
| 72 |
description: |
| 73 |
- Certificate authority URL. |
| 74 |
type: str |
| 75 |
cmpv1_settings: |
| 76 |
description: |
| 77 |
- Cmpv1 protocol settings. Available only if "protocol" is set to "cmpv1". |
| 78 |
type: dict |
| 79 |
suboptions: |
| 80 |
direct_tcp_settings: |
| 81 |
description: |
| 82 |
- Direct tcp transport layer settings. |
| 83 |
type: dict |
| 84 |
suboptions: |
| 85 |
ip_address: |
| 86 |
description: |
| 87 |
- Certificate authority IP address. |
| 88 |
type: str |
| 89 |
port: |
| 90 |
description: |
| 91 |
- Port number. |
| 92 |
type: int |
| 93 |
cmpv2_settings: |
| 94 |
description: |
| 95 |
- Cmpv2 protocol settings. Available only if "protocol" is set to "cmpv1". |
| 96 |
type: dict |
| 97 |
suboptions: |
| 98 |
transport_layer: |
| 99 |
description: |
| 100 |
- Transport layer. |
| 101 |
type: str |
| 102 |
choices: ['http', 'direct-tcp'] |
| 103 |
direct_tcp_settings: |
| 104 |
description: |
| 105 |
- Direct tcp transport layer settings. |
| 106 |
type: dict |
| 107 |
suboptions: |
| 108 |
ip_address: |
| 109 |
description: |
| 110 |
- Certificate authority IP address. |
| 111 |
type: str |
| 112 |
port: |
| 113 |
description: |
| 114 |
- Port number. |
| 115 |
type: int |
| 116 |
http_settings: |
| 117 |
description: |
| 118 |
- Http transport layer settings. |
| 119 |
type: dict |
| 120 |
suboptions: |
| 121 |
url: |
| 122 |
description: |
| 123 |
- Certificate authority URL. |
| 124 |
type: str |
| 125 |
retrieve_crl_from_http_servers: |
| 126 |
description: |
| 127 |
- Whether to retrieve Certificate Revocation List from http servers. |
| 128 |
type: bool |
| 129 |
retrieve_crl_from_ldap_servers: |
| 130 |
description: |
| 131 |
- Whether to retrieve Certificate Revocation List from ldap servers. |
| 132 |
type: bool |
| 133 |
cache_crl: |
| 134 |
description: |
| 135 |
- Cache Certificate Revocation List on the Security Gateway. |
| 136 |
type: bool |
| 137 |
crl_cache_method: |
| 138 |
description: |
| 139 |
- Weather to retrieve new Certificate Revocation List after the certificate expires or after a fixed period. |
| 140 |
type: str |
| 141 |
choices: ['timeout', 'expiration date'] |
| 142 |
crl_cache_timeout: |
| 143 |
description: |
| 144 |
- When to fetch new Certificate Revocation List (in minutes). |
| 145 |
type: int |
| 146 |
allow_certificates_from_branches: |
| 147 |
description: |
| 148 |
- Allow only certificates from listed branches. |
| 149 |
type: bool |
| 150 |
branches: |
| 151 |
description: |
| 152 |
- Branches to allow certificates from. Required only if "allow-certificates-from-branches" set to "true". |
| 153 |
type: list |
| 154 |
elements: str |
| 155 |
tags: |
| 156 |
description: |
| 157 |
- Collection of tag identifiers. |
| 158 |
type: list |
| 159 |
elements: str |
| 160 |
color: |
| 161 |
description: |
| 162 |
- Color of the object. Should be one of existing colors. |
| 163 |
type: str |
| 164 |
choices: ['aquamarine', 'black', 'blue', 'crete blue', 'burlywood', 'cyan', 'dark green', 'khaki', 'orchid', 'dark orange', 'dark sea green', |
| 165 |
'pink', 'turquoise', 'dark blue', 'firebrick', 'brown', 'forest green', 'gold', 'dark gold', 'gray', 'dark gray', 'light green', 'lemon chiffon', |
| 166 |
'coral', 'sea green', 'sky blue', 'magenta', 'purple', 'slate blue', 'violet red', 'navy blue', 'olive', 'orange', 'red', 'sienna', 'yellow'] |
| 167 |
comments: |
| 168 |
description: |
| 169 |
- Comments string. |
| 170 |
type: str |
| 171 |
details_level: |
| 172 |
description: |
| 173 |
- 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 |
| 174 |
representation of the object. |
| 175 |
type: str |
| 176 |
choices: ['uid', 'standard', 'full'] |
| 177 |
domains_to_process: |
| 178 |
description: |
| 179 |
- Indicates which domains to process the commands on. It cannot be used with the details-level full, must be run from the System Domain only and |
| 180 |
with ignore-warnings true. Valid values are, CURRENT_DOMAIN, ALL_DOMAINS_ON_THIS_SERVER. |
| 181 |
type: list |
| 182 |
elements: str |
| 183 |
ignore_warnings: |
| 184 |
description: |
| 185 |
- Apply changes ignoring warnings. |
| 186 |
type: bool |
| 187 |
ignore_errors: |
| 188 |
description: |
| 189 |
- 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. |
| 190 |
type: bool |
| 191 |
extends_documentation_fragment: check_point.mgmt.checkpoint_objects |
| 192 |
""" |
| 193 |
|
| 194 |
EXAMPLES = """ |
| 195 |
- name: add-opsec-trusted-ca |
| 196 |
cp_mgmt_opsec_trusted_ca: |
| 197 |
base64_certificate: |
| 198 |
"MIICwjCCAaqgAwIBAgIILdexblpVEMIwDQYJKoZIhvcNAQELBQAwGDEWMBQGA1UEAxMNd3d3Lm9wc2VjLmNvbTAeFw0yMzA2MjUwOTE3MDBaFw0yNTAzMzExNjAwMDBaMBgxFjAUBgNVBAMTDXd3dy5vcH |
| 199 |
lYy5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQCjpqCxDaVg+I1b+wqnmjjYtL3v7Tlu/YpMbsKnv+M1gRz6QFUOoSVnxKLo0A7Y4kCqa1OPcHO/LtXuok43F1YZPVKm3xWpY8FmqGqf5 |
| 200 |
uGmSwm1HPObcMjwGOyFgwpwEDF5e0UMZ7xtJF8BZ5KKBh3ZfQ1FbmbVqSUPcmOi+NE4JspPlHxX+m6es/yeSGR1A2ezKY7KePTlwVtDe8hiLrYyKG92nka5rkD1QyEIVJ0W5wrnU4nGEDIHeOfT09zroQx |
| 201 |
NLkb51sl4Tog/qw+EraVGIBe/iFnSJoDF37i2mLJqI/t8bel+aGDAxgMx1pO85OClgjPSWL0UIXGI2xrR+JAgMBAAGjEDAOMAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcNAQELBQADggEBAHTs1AutAmSLHF2 |
| 202 |
RLJtrRNkso0lMyA7XI7k1TNpTk7TCZLNY0VbUliGbcl+POH4EG8ARUrftnwRDCTBd2BdJTqG2CyNADi+bw8aLvbxok7KH0GlQvGjyfq+sHK12wTl4ULNyYoAPZ01GhXOvkobROdSyjxvBVhxdVo90kj7mH |
| 203 |
v3N83huNhfstDFUBcQCmMkbLuzDUZrl2a1OtqlOdNC6mNvb7Jq9W9vRxGA514e7jqyoM+PwHu5fILx/jmGT8suOUnvbtcDdFhjqixAPer6uSPR0CSbiJvuDy72DPH5mjZK5dQKewNYOZ/BQEsRIBe+Q6eG |
| 204 |
oJqi+cD63cwlw0DCc=" |
| 205 |
name: opsec_ca |
| 206 |
state: present |
| 207 |
|
| 208 |
- name: set-opsec-trusted-ca |
| 209 |
cp_mgmt_opsec_trusted_ca: |
| 210 |
name: opsec_ca |
| 211 |
automatic_enrollment: |
| 212 |
automatically_enroll_certificate: true |
| 213 |
protocol: "cmpv1" |
| 214 |
cmpv1_settings: |
| 215 |
direct_tcp_settings: |
| 216 |
ip_address: "1.1.1.1" |
| 217 |
state: present |
| 218 |
|
| 219 |
- name: delete-opsec-trusted-ca |
| 220 |
cp_mgmt_opsec_trusted_ca: |
| 221 |
name: opsec_ca |
| 222 |
state: absent |
| 223 |
""" |
| 224 |
|
| 225 |
RETURN = """ |
| 226 |
cp_mgmt_opsec_trusted_ca: |
| 227 |
description: The checkpoint object created or updated. |
| 228 |
returned: always, except when deleting the object. |
| 229 |
type: dict |
| 230 |
""" |
| 231 |
|
| 232 |
from ansible.module_utils.basic import AnsibleModule |
| 233 |
from ansible_collections.check_point.mgmt.plugins.module_utils.checkpoint import checkpoint_argument_spec_for_objects, api_call |
| 234 |
|
| 235 |
|
| 236 |
def main(): |
| 237 |
argument_spec = dict( |
| 238 |
name=dict(type='str', required=True), |
| 239 |
base64_certificate=dict(type='str'), |
| 240 |
automatic_enrollment=dict(type='dict', options=dict( |
| 241 |
automatically_enroll_certificate=dict(type='bool'), |
| 242 |
protocol=dict(type='str', choices=['scep', 'cmpv2', 'cmpv1']), |
| 243 |
scep_settings=dict(type='dict', options=dict( |
| 244 |
ca_identifier=dict(type='str'), |
| 245 |
url=dict(type='str') |
| 246 |
)), |
| 247 |
cmpv1_settings=dict(type='dict', options=dict( |
| 248 |
direct_tcp_settings=dict(type='dict', options=dict( |
| 249 |
ip_address=dict(type='str'), |
| 250 |
port=dict(type='int') |
| 251 |
)) |
| 252 |
)), |
| 253 |
cmpv2_settings=dict(type='dict', options=dict( |
| 254 |
transport_layer=dict(type='str', choices=['http', 'direct-tcp']), |
| 255 |
direct_tcp_settings=dict(type='dict', options=dict( |
| 256 |
ip_address=dict(type='str'), |
| 257 |
port=dict(type='int') |
| 258 |
)), |
| 259 |
http_settings=dict(type='dict', options=dict( |
| 260 |
url=dict(type='str') |
| 261 |
)) |
| 262 |
)) |
| 263 |
)), |
| 264 |
retrieve_crl_from_http_servers=dict(type='bool'), |
| 265 |
retrieve_crl_from_ldap_servers=dict(type='bool'), |
| 266 |
cache_crl=dict(type='bool'), |
| 267 |
crl_cache_method=dict(type='str', choices=['timeout', 'expiration date']), |
| 268 |
crl_cache_timeout=dict(type='int'), |
| 269 |
allow_certificates_from_branches=dict(type='bool'), |
| 270 |
branches=dict(type='list', elements='str'), |
| 271 |
tags=dict(type='list', elements='str'), |
| 272 |
color=dict(type='str', choices=['aquamarine', 'black', 'blue', 'crete blue', 'burlywood', 'cyan', 'dark green', |
| 273 |
'khaki', 'orchid', 'dark orange', 'dark sea green', 'pink', 'turquoise', 'dark blue', 'firebrick', 'brown', |
| 274 |
'forest green', 'gold', 'dark gold', 'gray', 'dark gray', 'light green', 'lemon chiffon', 'coral', 'sea green', |
| 275 |
'sky blue', 'magenta', 'purple', 'slate blue', 'violet red', 'navy blue', 'olive', 'orange', 'red', 'sienna', |
| 276 |
'yellow']), |
| 277 |
comments=dict(type='str'), |
| 278 |
details_level=dict(type='str', choices=['uid', 'standard', 'full']), |
| 279 |
domains_to_process=dict(type='list', elements='str'), |
| 280 |
ignore_warnings=dict(type='bool'), |
| 281 |
ignore_errors=dict(type='bool') |
| 282 |
) |
| 283 |
argument_spec.update(checkpoint_argument_spec_for_objects) |
| 284 |
|
| 285 |
module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True) |
| 286 |
api_call_object = 'opsec-trusted-ca' |
| 287 |
|
| 288 |
result = api_call(module, api_call_object) |
| 289 |
module.exit_json(**result) |
| 290 |
|
| 291 |
|
| 292 |
if __name__ == '__main__': |
| 293 |
main() |