| 1 |
#!/usr/bin/python |
| 2 |
|
| 3 |
# (c) 2018-2025, NetApp, Inc |
| 4 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 5 |
from __future__ import absolute_import, division, print_function |
| 6 |
__metaclass__ = type |
| 7 |
|
| 8 |
ANSIBLE_METADATA = {'metadata_version': '1.1', |
| 9 |
'status': ['preview'], |
| 10 |
'supported_by': 'certified'} |
| 11 |
|
| 12 |
DOCUMENTATION = ''' |
| 13 |
--- |
| 14 |
module: na_ontap_vserver_cifs_security |
| 15 |
short_description: NetApp ONTAP vserver CIFS security modification |
| 16 |
extends_documentation_fragment: |
| 17 |
- netapp.ontap.netapp.na_ontap_zapi |
| 18 |
version_added: 2.9.0 |
| 19 |
author: NetApp Ansible Team (@carchi8py) <[email protected]> |
| 20 |
|
| 21 |
description: |
| 22 |
- modify vserver CIFS security. |
| 23 |
|
| 24 |
options: |
| 25 |
|
| 26 |
vserver: |
| 27 |
description: |
| 28 |
- name of the vserver. |
| 29 |
required: true |
| 30 |
type: str |
| 31 |
|
| 32 |
kerberos_clock_skew: |
| 33 |
description: |
| 34 |
- The clock skew in minutes is the tolerance for accepting tickets with time stamps that do not exactly match the host's system clock. |
| 35 |
type: int |
| 36 |
|
| 37 |
kerberos_ticket_age: |
| 38 |
description: |
| 39 |
- Determine the maximum amount of time in hours that a user's ticket may be used for the purpose of Kerberos authentication. |
| 40 |
type: int |
| 41 |
|
| 42 |
kerberos_renew_age: |
| 43 |
description: |
| 44 |
- Determine the maximum amount of time in days for which a ticket can be renewed. |
| 45 |
type: int |
| 46 |
|
| 47 |
kerberos_kdc_timeout: |
| 48 |
description: |
| 49 |
- Determine the timeout value in seconds for KDC connections. |
| 50 |
type: int |
| 51 |
|
| 52 |
is_signing_required: |
| 53 |
description: |
| 54 |
- Determine whether signing is required for incoming CIFS traffic. |
| 55 |
type: bool |
| 56 |
|
| 57 |
is_password_complexity_required: |
| 58 |
description: |
| 59 |
- Determine whether password complexity is required for local users. |
| 60 |
type: bool |
| 61 |
|
| 62 |
is_aes_encryption_enabled: |
| 63 |
description: |
| 64 |
- Determine whether AES-128 and AES-256 encryption mechanisms are enabled for Kerberos-related CIFS communication. |
| 65 |
type: bool |
| 66 |
|
| 67 |
is_smb_encryption_required: |
| 68 |
description: |
| 69 |
- Determine whether SMB encryption is required for incoming CIFS traffic. |
| 70 |
type: bool |
| 71 |
|
| 72 |
lm_compatibility_level: |
| 73 |
description: |
| 74 |
- Determine the LM compatibility level. |
| 75 |
choices: ['lm_ntlm_ntlmv2_krb', 'ntlm_ntlmv2_krb', 'ntlmv2_krb', 'krb'] |
| 76 |
type: str |
| 77 |
|
| 78 |
referral_enabled_for_ad_ldap: |
| 79 |
description: |
| 80 |
- Determine whether LDAP referral chasing is enabled or not for AD LDAP connections. |
| 81 |
type: bool |
| 82 |
|
| 83 |
session_security_for_ad_ldap: |
| 84 |
description: |
| 85 |
- Determine the level of security required for LDAP communications. |
| 86 |
choices: ['none', 'sign', 'seal'] |
| 87 |
type: str |
| 88 |
|
| 89 |
smb1_enabled_for_dc_connections: |
| 90 |
description: |
| 91 |
- Determine if SMB version 1 is used for connections to domain controllers. |
| 92 |
choices: ['false', 'true', 'system_default'] |
| 93 |
type: str |
| 94 |
|
| 95 |
smb2_enabled_for_dc_connections: |
| 96 |
description: |
| 97 |
- Determine if SMB version 2 is used for connections to domain controllers. |
| 98 |
choices: ['false', 'true', 'system_default'] |
| 99 |
type: str |
| 100 |
|
| 101 |
use_start_tls_for_ad_ldap: |
| 102 |
description: |
| 103 |
- Determine whether to use start_tls for AD LDAP connections. |
| 104 |
type: bool |
| 105 |
|
| 106 |
encryption_required_for_dc_connections: |
| 107 |
description: |
| 108 |
- Specifies whether encryption is required for domain controller connections. |
| 109 |
type: bool |
| 110 |
version_added: 21.20.0 |
| 111 |
|
| 112 |
use_ldaps_for_ad_ldap: |
| 113 |
description: |
| 114 |
- Determine whether to use LDAPS for secure Active Directory LDAP connections. |
| 115 |
type: bool |
| 116 |
version_added: 21.20.0 |
| 117 |
|
| 118 |
''' |
| 119 |
|
| 120 |
EXAMPLES = ''' |
| 121 |
- name: Modify cifs security |
| 122 |
netapp.ontap.na_ontap_vserver_cifs_security: |
| 123 |
hostname: "{{ netapp_hostname }}" |
| 124 |
username: "{{ netapp_username }}" |
| 125 |
password: "{{ netapp_password }}" |
| 126 |
vserver: ansible |
| 127 |
is_aes_encryption_enabled: false |
| 128 |
lm_compatibility_level: lm_ntlm_ntlmv2_krb |
| 129 |
smb1_enabled_for_dc_connections: system_default |
| 130 |
smb2_enabled_for_dc_connections: system_default |
| 131 |
use_start_tls_for_ad_ldap: false |
| 132 |
referral_enabled_for_ad_ldap: false |
| 133 |
session_security_for_ad_ldap: none |
| 134 |
is_signing_required: false |
| 135 |
is_password_complexity_required: false |
| 136 |
encryption_required_for_dc_connections: false |
| 137 |
use_ldaps_for_ad_ldap: false |
| 138 |
|
| 139 |
- name: modify cifs security is_smb_encryption_required |
| 140 |
netapp.ontap.na_ontap_vserver_cifs_security: |
| 141 |
hostname: "{{ netapp_hostname }}" |
| 142 |
username: "{{ netapp_username }}" |
| 143 |
password: "{{ netapp_password }}" |
| 144 |
vserver: ansible |
| 145 |
is_smb_encryption_required: false |
| 146 |
|
| 147 |
- name: modify cifs security int options |
| 148 |
netapp.ontap.na_ontap_vserver_cifs_security: |
| 149 |
hostname: "{{ netapp_hostname }}" |
| 150 |
username: "{{ netapp_username }}" |
| 151 |
password: "{{ netapp_password }}" |
| 152 |
vserver: ansible |
| 153 |
kerberos_clock_skew: 10 |
| 154 |
kerberos_ticket_age: 10 |
| 155 |
kerberos_renew_age: 5 |
| 156 |
kerberos_kdc_timeout: 3 |
| 157 |
''' |
| 158 |
|
| 159 |
RETURN = ''' |
| 160 |
''' |
| 161 |
|
| 162 |
import traceback |
| 163 |
from ansible.module_utils.basic import AnsibleModule |
| 164 |
from ansible.module_utils._text import to_native |
| 165 |
import ansible_collections.netapp.ontap.plugins.module_utils.netapp as netapp_utils |
| 166 |
from ansible_collections.netapp.ontap.plugins.module_utils.netapp_module import NetAppModule |
| 167 |
|
| 168 |
|
| 169 |
class NetAppONTAPCifsSecurity(object): |
| 170 |
''' |
| 171 |
modify vserver cifs security |
| 172 |
''' |
| 173 |
def __init__(self): |
| 174 |
|
| 175 |
self.argument_spec = netapp_utils.na_ontap_zapi_only_spec() |
| 176 |
self.argument_spec.update(dict( |
| 177 |
vserver=dict(required=True, type='str'), |
| 178 |
kerberos_clock_skew=dict(required=False, type='int'), |
| 179 |
kerberos_ticket_age=dict(required=False, type='int'), |
| 180 |
kerberos_renew_age=dict(required=False, type='int'), |
| 181 |
kerberos_kdc_timeout=dict(required=False, type='int'), |
| 182 |
is_signing_required=dict(required=False, type='bool'), |
| 183 |
is_password_complexity_required=dict(required=False, type='bool'), |
| 184 |
is_aes_encryption_enabled=dict(required=False, type='bool'), |
| 185 |
is_smb_encryption_required=dict(required=False, type='bool'), |
| 186 |
lm_compatibility_level=dict(required=False, choices=['lm_ntlm_ntlmv2_krb', 'ntlm_ntlmv2_krb', 'ntlmv2_krb', 'krb']), |
| 187 |
referral_enabled_for_ad_ldap=dict(required=False, type='bool'), |
| 188 |
session_security_for_ad_ldap=dict(required=False, choices=['none', 'sign', 'seal']), |
| 189 |
smb1_enabled_for_dc_connections=dict(required=False, choices=['false', 'true', 'system_default']), |
| 190 |
smb2_enabled_for_dc_connections=dict(required=False, choices=['false', 'true', 'system_default']), |
| 191 |
use_start_tls_for_ad_ldap=dict(required=False, type='bool'), |
| 192 |
encryption_required_for_dc_connections=dict(required=False, type='bool'), |
| 193 |
use_ldaps_for_ad_ldap=dict(required=False, type='bool') |
| 194 |
)) |
| 195 |
|
| 196 |
self.module = AnsibleModule( |
| 197 |
argument_spec=self.argument_spec, |
| 198 |
supports_check_mode=True, |
| 199 |
mutually_exclusive=[('use_ldaps_for_ad_ldap', 'use_start_tls_for_ad_ldap')] |
| 200 |
) |
| 201 |
|
| 202 |
self.na_helper = NetAppModule() |
| 203 |
self.parameters = self.na_helper.set_parameters(self.module.params) |
| 204 |
self.na_helper.module_replaces('na_ontap_cifs_server', self.module) |
| 205 |
msg = 'The module only supports ZAPI; refer to netapp.ontap.na_ontap_cifs_server module for RESTful equivalent.' |
| 206 |
self.na_helper.fall_back_to_zapi(self.module, msg, self.parameters) |
| 207 |
|
| 208 |
self.set_playbook_zapi_key_map() |
| 209 |
if not netapp_utils.has_netapp_lib(): |
| 210 |
self.module.fail_json(msg="the python NetApp-Lib module is required") |
| 211 |
else: |
| 212 |
self.server = netapp_utils.setup_na_ontap_zapi(module=self.module, vserver=self.parameters['vserver']) |
| 213 |
|
| 214 |
def set_playbook_zapi_key_map(self): |
| 215 |
|
| 216 |
self.na_helper.zapi_int_keys = { |
| 217 |
'kerberos_clock_skew': 'kerberos-clock-skew', |
| 218 |
'kerberos_ticket_age': 'kerberos-ticket-age', |
| 219 |
'kerberos_renew_age': 'kerberos-renew-age', |
| 220 |
'kerberos_kdc_timeout': 'kerberos-kdc-timeout' |
| 221 |
} |
| 222 |
self.na_helper.zapi_bool_keys = { |
| 223 |
'is_signing_required': 'is-signing-required', |
| 224 |
'is_password_complexity_required': 'is-password-complexity-required', |
| 225 |
'is_aes_encryption_enabled': 'is-aes-encryption-enabled', |
| 226 |
'is_smb_encryption_required': 'is-smb-encryption-required', |
| 227 |
'referral_enabled_for_ad_ldap': 'referral-enabled-for-ad-ldap', |
| 228 |
'use_start_tls_for_ad_ldap': 'use-start-tls-for-ad-ldap', |
| 229 |
'encryption_required_for_dc_connections': 'encryption-required-for-dc-connections', |
| 230 |
'use_ldaps_for_ad_ldap': 'use-ldaps-for-ad-ldap' |
| 231 |
} |
| 232 |
self.na_helper.zapi_str_keys = { |
| 233 |
'lm_compatibility_level': 'lm-compatibility-level', |
| 234 |
'session_security_for_ad_ldap': 'session-security-for-ad-ldap', |
| 235 |
'smb1_enabled_for_dc_connections': 'smb1-enabled-for-dc-connections', |
| 236 |
'smb2_enabled_for_dc_connections': 'smb2-enabled-for-dc-connections' |
| 237 |
} |
| 238 |
|
| 239 |
def cifs_security_get_iter(self): |
| 240 |
""" |
| 241 |
get current vserver cifs security. |
| 242 |
:return: a dict of vserver cifs security |
| 243 |
""" |
| 244 |
cifs_security_get = netapp_utils.zapi.NaElement('cifs-security-get-iter') |
| 245 |
query = netapp_utils.zapi.NaElement('query') |
| 246 |
cifs_security = netapp_utils.zapi.NaElement('cifs-security') |
| 247 |
cifs_security.add_new_child('vserver', self.parameters['vserver']) |
| 248 |
query.add_child_elem(cifs_security) |
| 249 |
cifs_security_get.add_child_elem(query) |
| 250 |
cifs_security_details = dict() |
| 251 |
try: |
| 252 |
result = self.server.invoke_successfully(cifs_security_get, enable_tunneling=True) |
| 253 |
except netapp_utils.zapi.NaApiError as error: |
| 254 |
self.module.fail_json(msg='Error fetching cifs security from %s: %s' |
| 255 |
% (self.parameters['vserver'], to_native(error)), |
| 256 |
exception=traceback.format_exc()) |
| 257 |
if result.get_child_by_name('num-records') and int(result.get_child_content('num-records')) > 0: |
| 258 |
cifs_security_info = result.get_child_by_name('attributes-list').get_child_by_name('cifs-security') |
| 259 |
for option, zapi_key in self.na_helper.zapi_int_keys.items(): |
| 260 |
cifs_security_details[option] = self.na_helper.get_value_for_int(from_zapi=True, value=cifs_security_info.get_child_content(zapi_key)) |
| 261 |
for option, zapi_key in self.na_helper.zapi_bool_keys.items(): |
| 262 |
cifs_security_details[option] = self.na_helper.get_value_for_bool(from_zapi=True, value=cifs_security_info.get_child_content(zapi_key)) |
| 263 |
for option, zapi_key in self.na_helper.zapi_str_keys.items(): |
| 264 |
if cifs_security_info.get_child_content(zapi_key) is None: |
| 265 |
cifs_security_details[option] = None |
| 266 |
else: |
| 267 |
cifs_security_details[option] = cifs_security_info.get_child_content(zapi_key) |
| 268 |
return cifs_security_details |
| 269 |
return None |
| 270 |
|
| 271 |
def cifs_security_modify(self, modify): |
| 272 |
""" |
| 273 |
:param modify: A list of attributes to modify |
| 274 |
:return: None |
| 275 |
""" |
| 276 |
cifs_security_modify = netapp_utils.zapi.NaElement('cifs-security-modify') |
| 277 |
for attribute in modify: |
| 278 |
cifs_security_modify.add_new_child(self.attribute_to_name(attribute), str(self.parameters[attribute])) |
| 279 |
try: |
| 280 |
self.server.invoke_successfully(cifs_security_modify, enable_tunneling=True) |
| 281 |
except netapp_utils.zapi.NaApiError as e: |
| 282 |
self.module.fail_json(msg='Error modifying cifs security on %s: %s' |
| 283 |
% (self.parameters['vserver'], to_native(e)), |
| 284 |
exception=traceback.format_exc()) |
| 285 |
|
| 286 |
@staticmethod |
| 287 |
def attribute_to_name(attribute): |
| 288 |
return str.replace(attribute, '_', '-') |
| 289 |
|
| 290 |
def apply(self): |
| 291 |
"""Call modify operations.""" |
| 292 |
current = self.cifs_security_get_iter() |
| 293 |
modify = self.na_helper.get_modified_attributes(current, self.parameters) |
| 294 |
if self.na_helper.changed: |
| 295 |
if self.module.check_mode: |
| 296 |
pass |
| 297 |
else: |
| 298 |
if modify: |
| 299 |
self.cifs_security_modify(modify) |
| 300 |
result = netapp_utils.generate_result(self.na_helper.changed, modify=modify) |
| 301 |
self.module.exit_json(**result) |
| 302 |
|
| 303 |
|
| 304 |
def main(): |
| 305 |
obj = NetAppONTAPCifsSecurity() |
| 306 |
obj.apply() |
| 307 |
|
| 308 |
|
| 309 |
if __name__ == '__main__': |
| 310 |
main() |