Debian Codegraph @

ansible_collections/community/zabbix/plugins/modules/zabbix_authentication.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 #
4 # Copyright: (c) 2022, ONODERA Masaru <[email protected]>
5 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 from __future__ import absolute_import, division, print_function
8
9 __metaclass__ = type
10
11
12 DOCUMENTATION = """
13 ---
14 module: zabbix_authentication
15
16 short_description: Update Zabbix authentication
17
18 description:
19 - This module allows you to modify Zabbix authentication setting.
20
21 author:
22 - ONODERA Masaru(@masa-orca)
23
24 requirements:
25 - "python >= 3.9"
26
27 version_added: 1.6.0
28
29 options:
30 authentication_type:
31 description:
32 - Choose default authentication type.
33 required: false
34 type: str
35 choices: [ "internal", "ldap" ]
36 http_auth_enabled:
37 description:
38 - HTTP authentication will be enabled if C(true).
39 required: false
40 type: bool
41 http_login_form:
42 description:
43 - Choose default login form.
44 required: false
45 type: str
46 choices: [ "zabbix_login_form", "http_login_form" ]
47 http_strip_domains:
48 description:
49 - A list of domain names that should be removed from the username.
50 required: false
51 type: list
52 elements: str
53 http_case_sensitive:
54 description:
55 - Case sensitive login for HTTP authentication will be enabled if C(true).
56 required: false
57 type: bool
58 ldap_configured:
59 description:
60 - LDAP authentication will be enabled if C(true).
61 - Works only with Zabbix = 6.0 and is silently ignored in higher versions.
62 required: false
63 type: bool
64 ldap_auth_enabled:
65 description:
66 - LDAP authentication will be enabled if C(true).
67 - This parameter is available since Zabbix 6.4.
68 required: false
69 type: bool
70 ldap_host:
71 description:
72 - LDAP server name.
73 - e.g. C(ldap://ldap.zabbix.com)
74 - This setting is required if current value of I(ldap_configured) is C(false).
75 - Works only with Zabbix <= 6.0 and is silently ignored in higher versions.
76 - Please use community.zabbix.zabbix_user_directory module instead of this parameter with Zabbix >= 7.0.
77 required: false
78 type: str
79 ldap_port:
80 description:
81 - A port number of LDAP server.
82 - This setting is required if current value of I(ldap_configured) is C(false).
83 - Works only with Zabbix <= 6.0 and is silently ignored in higher versions.
84 - Please use community.zabbix.zabbix_user_directory module instead of this parameter with Zabbix >= 7.0.
85 required: false
86 type: int
87 ldap_base_dn:
88 description:
89 - Base DN of LDAP.
90 - This setting is required if current value of I(ldap_configured) is C(false).
91 - Works only with Zabbix <= 6.0 and is silently ignored in higher versions.
92 - Please use community.zabbix.zabbix_user_directory module instead of this parameter with Zabbix >= 7.0.
93 required: false
94 type: str
95 ldap_search_attribute:
96 description:
97 - Search attribute of LDAP.
98 - This setting is required if current value of I(ldap_configured) is C(false).
99 - Works only with Zabbix <= 6.0 and is silently ignored in higher versions.
100 - Please use community.zabbix.zabbix_user_directory module instead of this parameter with Zabbix >= 7.0.
101 required: false
102 type: str
103 ldap_bind_dn:
104 description:
105 - Bind DN of LDAP.
106 - Works only with Zabbix <= 6.0 and is silently ignored in higher versions.
107 - Please use community.zabbix.zabbix_user_directory module instead of this parameter with Zabbix >= 7.0.
108 required: false
109 type: str
110 ldap_case_sensitive:
111 description:
112 - case sensitive login for LDAP authentication will be enabled if C(true).
113 required: false
114 type: bool
115 ldap_bind_password:
116 description:
117 - Bind password of LDAP.
118 - Works only with Zabbix <= 6.0 and is silently ignored in higher versions.
119 - Please use community.zabbix.zabbix_user_directory module instead of this parameter with Zabbix >= 7.0.
120 required: false
121 type: str
122 ldap_userdirectory:
123 description:
124 - LDAP authentication default user directory name for user groups with gui_access set to LDAP or System default.
125 - Required to be set when C(ldap_configured) / C(ldap_auth_enabled) is set to 1.
126 required: false
127 type: str
128 ldap_jit_status:
129 description:
130 - Status of LDAP provisioning.
131 - This parameter is available since Zabbix 6.4.
132 required: false
133 type: bool
134 jit_provision_interval:
135 description:
136 - Time interval between JIT provision requests for logged-in user.
137 - Accepts seconds and time unit with suffix with month and year support (3600s,60m,1h,1d,1M,1y). Minimum value 1h.
138 - Available only for LDAP provisioning.
139 - This parameter is available since Zabbix 6.4.
140 required: false
141 type: str
142 default: 1h
143 disabled_usrgroup:
144 description:
145 - User group name to assign the deprovisioned user to.
146 - The user group must be disabled and cannot be enabled or deleted when configured.
147 - Required if C(ldap_jit_status) for C(saml_jit_status) enabled.
148 - This parameter is available since Zabbix 6.4.
149 required: false
150 type: str
151 saml_auth_enabled:
152 description:
153 - SAML authentication will be enabled if C(true).
154 required: false
155 type: bool
156 saml_idp_entityid:
157 description:
158 - SAML identify provider's entity ID.
159 - This setting is required if current value of I(saml_auth_enabled) is C(false).
160 - Works only with Zabbix = 6.0 and is silently ignored in higher versions.
161 required: false
162 type: str
163 saml_sso_url:
164 description:
165 - URL for single sign on service of SAML.
166 - This setting is required if current value of I(saml_auth_enabled) is C(false).
167 - Works only with Zabbix = 6.0 and is silently ignored in higher versions.
168 required: false
169 type: str
170 saml_slo_url:
171 description:
172 - URL for SAML single logout service.
173 - Works only with Zabbix = 6.0 and is silently ignored in higher versions.
174 required: false
175 type: str
176 saml_username_attribute:
177 description:
178 - User name attribute of SAML.
179 - This setting is required if current value of I(saml_auth_enabled) is C(false).
180 - Works only with Zabbix = 6.0 and is silently ignored in higher versions.
181 required: false
182 type: str
183 saml_sp_entityid:
184 description:
185 - Entity ID of SAML service provider.
186 - This setting is required if current value of I(saml_auth_enabled) is C(false).
187 - Works only with Zabbix = 6.0 and is silently ignored in higher versions.
188 required: false
189 type: str
190 saml_nameid_format:
191 description:
192 - Name identifier format of SAML service provider.
193 - Works only with Zabbix = 6.0 and is silently ignored in higher versions.
194 required: false
195 type: str
196 saml_sign_messages:
197 description:
198 - SAML sign messages will be enabled if C(true).
199 - Works only with Zabbix = 6.0 and is silently ignored in higher versions.
200 required: false
201 type: bool
202 saml_sign_assertions:
203 description:
204 - SAML sign assertions will be enabled if C(true).
205 - Works only with Zabbix = 6.0 and is silently ignored in higher versions.
206 required: false
207 type: bool
208 saml_sign_authn_requests:
209 description:
210 - SAML sign AuthN requests will be enabled if C(true).
211 - Works only with Zabbix = 6.0 and is silently ignored in higher versions.
212 required: false
213 type: bool
214 saml_sign_logout_requests:
215 description:
216 - SAML sign logout requests will be enabled if C(true).
217 - Works only with Zabbix = 6.0 and is silently ignored in higher versions.
218 required: false
219 type: bool
220 saml_sign_logout_responses:
221 description:
222 - SAML sign logout responses will be enabled if C(true).
223 - Works only with Zabbix = 6.0 and is silently ignored in higher versions.
224 required: false
225 type: bool
226 saml_encrypt_nameid:
227 description:
228 - SAML encrypt name ID will be enabled if C(true).
229 - Works only with Zabbix = 6.0 and is silently ignored in higher versions.
230 required: false
231 type: bool
232 saml_encrypt_assertions:
233 description:
234 - SAML encrypt assertions will be enabled if C(true).
235 - Works only with Zabbix = 6.0 and is silently ignored in higher versions.
236 required: false
237 type: bool
238 saml_case_sensitive:
239 description:
240 - Case sensitive login for SAML authentication will be enabled if C(true).
241 required: false
242 type: bool
243 saml_jit_status:
244 description:
245 - Status of SAML provisioning.
246 - This parameter is available since Zabbix 6.4.
247 required: false
248 type: bool
249 passwd_min_length:
250 description:
251 - Minimal length of password.
252 - Choose from 1-70.
253 - This parameter is available since Zabbix 6.0.
254 required: false
255 type: int
256 passwd_check_rules:
257 description:
258 - Checking password rules.
259 - Select multiple from C(contain_uppercase_and_lowercase_letters),
260 C(contain_digits). C(contain_special_characters) and C(avoid_easy_to_guess).
261 - This parameter is available since Zabbix 6.0.
262 required: false
263 type: list
264 elements: str
265
266 extends_documentation_fragment:
267 - community.zabbix.zabbix
268 """
269
270 EXAMPLES = """
271 # If you want to use Username and Password to be authenticated by Zabbix Server
272 - name: Set credentials to access Zabbix Server API
273 ansible.builtin.set_fact:
274 ansible_user: Admin
275 ansible_httpapi_pass: zabbix
276
277 # If you want to use API token to be authenticated by Zabbix Server
278 # https://www.zabbix.com/documentation/current/en/manual/web_interface/frontend_sections/administration/general#api-tokens
279 - name: Set API token
280 ansible.builtin.set_fact:
281 ansible_zabbix_auth_key: 8ec0d52432c15c91fcafe9888500cf9a607f44091ab554dbee860f6b44fac895
282
283 - name: Update all authentication setting (Zabbix <= 6.0)
284 # set task level variables as we change ansible_connection plugin here
285 vars:
286 ansible_network_os: community.zabbix.zabbix
287 ansible_connection: httpapi
288 ansible_httpapi_port: 443
289 ansible_httpapi_use_ssl: true
290 ansible_httpapi_validate_certs: false
291 ansible_zabbix_url_path: "zabbixeu" # If Zabbix WebUI runs on non-default (zabbix) path ,e.g. http://<FQDN>/zabbixeu
292 ansible_host: zabbix-example-fqdn.org
293 community.zabbix.zabbix_authentication:
294 authentication_type: internal
295 http_auth_enabled: true
296 http_login_form: zabbix_login_form
297 http_strip_domains:
298 - comp
299 - any
300 http_case_sensitive: true
301 ldap_configured: true
302 ldap_host: "ldap://localhost"
303 ldap_port: 389
304 ldap_base_dn: "ou=Users,ou=system"
305 ldap_search_attribute: "uid"
306 ldap_bind_dn: "uid=ldap_search,ou=system"
307 ldap_case_sensitive: true
308 ldap_bind_password: "password"
309 saml_auth_enabled: true
310 saml_idp_entityid: ""
311 saml_sso_url: "https://localhost/SAML2/SSO"
312 saml_slo_url: "https://localhost/SAML2/SLO"
313 saml_username_attribute: "uid"
314 saml_sp_entityid: "https://localhost"
315 saml_nameid_format: "urn:oasis:names:tc:SAML:2.0:nameid-format:entity"
316 saml_sign_messages: true
317 saml_sign_assertions: true
318 saml_sign_authn_requests: true
319 saml_sign_logout_requests: true
320 saml_sign_logout_responses: true
321 saml_encrypt_nameid: true
322 saml_encrypt_assertions: true
323 saml_case_sensitive: true
324 passwd_min_length: 70
325 passwd_check_rules:
326 - contain_uppercase_and_lowercase_letters
327 - contain_digits
328 - contain_special_characters
329 - avoid_easy_to_guess
330
331 - name: Update all authentication setting (Zabbix = 6.0)
332 # set task level variables as we change ansible_connection plugin here
333 vars:
334 ansible_network_os: community.zabbix.zabbix
335 ansible_connection: httpapi
336 ansible_httpapi_port: 443
337 ansible_httpapi_use_ssl: true
338 ansible_httpapi_validate_certs: false
339 ansible_zabbix_url_path: "zabbixeu" # If Zabbix WebUI runs on non-default (zabbix) path ,e.g. http://<FQDN>/zabbixeu
340 ansible_host: zabbix-example-fqdn.org
341 community.zabbix.zabbix_authentication:
342 authentication_type: internal
343 http_auth_enabled: true
344 http_login_form: zabbix_login_form
345 http_strip_domains:
346 - comp
347 - any
348 http_case_sensitive: true
349 ldap_configured: true
350 ldap_case_sensitive: true
351 saml_auth_enabled: true
352 saml_idp_entityid: ""
353 saml_sso_url: "https://localhost/SAML2/SSO"
354 saml_slo_url: "https://localhost/SAML2/SLO"
355 saml_username_attribute: "uid"
356 saml_sp_entityid: "https://localhost"
357 saml_nameid_format: "urn:oasis:names:tc:SAML:2.0:nameid-format:entity"
358 saml_sign_messages: true
359 saml_sign_assertions: true
360 saml_sign_authn_requests: true
361 saml_sign_logout_requests: true
362 saml_sign_logout_responses: true
363 saml_encrypt_nameid: true
364 saml_encrypt_assertions: true
365 saml_case_sensitive: true
366 passwd_min_length: 70
367 passwd_check_rules:
368 - contain_uppercase_and_lowercase_letters
369 - contain_digits
370 - contain_special_characters
371 - avoid_easy_to_guess
372
373 - name: Update all authentication setting (Zabbix >= 7.0)
374 # set task level variables as we change ansible_connection plugin here
375 vars:
376 ansible_network_os: community.zabbix.zabbix
377 ansible_connection: httpapi
378 ansible_httpapi_port: 443
379 ansible_httpapi_use_ssl: true
380 ansible_httpapi_validate_certs: false
381 ansible_zabbix_url_path: "zabbixeu" # If Zabbix WebUI runs on non-default (zabbix) path ,e.g. http://<FQDN>/zabbixeu
382 ansible_host: zabbix-example-fqdn.org
383 community.zabbix.zabbix_authentication:
384 authentication_type: internal
385 http_auth_enabled: true
386 http_login_form: zabbix_login_form
387 http_strip_domains:
388 - comp
389 - any
390 http_case_sensitive: true
391 ldap_auth_enabled: true
392 ldap_userdirectory: TestUserDirectory
393 ldap_case_sensitive: true
394 saml_auth_enabled: true
395 saml_case_sensitive: true
396 ldap_jit_status: true
397 saml_jit_status: true
398 jit_provision_interval: 1h
399 disabled_usrgrp: Disabled
400 passwd_min_length: 70
401 passwd_check_rules:
402 - contain_uppercase_and_lowercase_letters
403 - contain_digits
404 - contain_special_characters
405 - avoid_easy_to_guess
406 """
407
408 RETURN = """
409 msg:
410 description: The result of the operation
411 returned: success
412 type: str
413 sample: "Successfully update authentication setting"
414 """
415
416 from ansible.module_utils.basic import AnsibleModule
417
418 from ansible_collections.community.zabbix.plugins.module_utils.base import ZabbixBase
419 from ansible.module_utils.compat.version import LooseVersion
420 import ansible_collections.community.zabbix.plugins.module_utils.helpers as zabbix_utils
421
422
423 class Authentication(ZabbixBase):
424
425 # get authentication setting
426 def get_authentication(self):
427 try:
428 return self._zapi.authentication.get({"output": "extend"})
429 except Exception as e:
430 self._module.fail_json(msg="Failed to get authentication setting: %s" % e)
431
432 # update authentication setting
433 def update_authentication(
434 self,
435 current_authentication,
436 authentication_type,
437 http_auth_enabled,
438 http_login_form,
439 http_strip_domains,
440 http_case_sensitive,
441 ldap_configured,
442 ldap_auth_enabled,
443 ldap_host,
444 ldap_port,
445 ldap_base_dn,
446 ldap_search_attribute,
447 ldap_bind_dn,
448 ldap_case_sensitive,
449 ldap_bind_password,
450 ldap_userdirectory,
451 saml_auth_enabled,
452 saml_idp_entityid,
453 saml_sso_url,
454 saml_slo_url,
455 saml_username_attribute,
456 saml_sp_entityid,
457 saml_nameid_format,
458 saml_sign_messages,
459 saml_sign_assertions,
460 saml_sign_authn_requests,
461 saml_sign_logout_requests,
462 saml_sign_logout_responses,
463 saml_encrypt_nameid,
464 saml_encrypt_assertions,
465 saml_case_sensitive,
466 passwd_min_length,
467 passwd_check_rules,
468 ldap_jit_status,
469 saml_jit_status,
470 jit_provision_interval,
471 disabled_usrgroup,
472 ):
473 try:
474 params = {}
475
476 if authentication_type:
477 params["authentication_type"] = str(
478 zabbix_utils.helper_to_numeric_value(
479 ["internal", "ldap"], authentication_type
480 )
481 )
482
483 if isinstance(http_auth_enabled, bool):
484 params["http_auth_enabled"] = str(int(http_auth_enabled))
485
486 if http_login_form:
487 params["http_login_form"] = str(
488 zabbix_utils.helper_to_numeric_value(
489 ["zabbix_login_form", "http_login_form"], http_login_form
490 )
491 )
492
493 if http_strip_domains:
494 params["http_strip_domains"] = ",".join(http_strip_domains)
495
496 if isinstance(http_case_sensitive, bool):
497 params["http_case_sensitive"] = str(int(http_case_sensitive))
498
499 if LooseVersion(self._zbx_api_version) < LooseVersion("7.0"):
500 if isinstance(ldap_configured, bool):
501 params["ldap_configured"] = str(int(ldap_configured))
502 else:
503 if isinstance(ldap_auth_enabled, bool):
504 params["ldap_auth_enabled"] = str(int(ldap_auth_enabled))
505
506 if LooseVersion(self._zbx_api_version) < LooseVersion("7.0"):
507 if ldap_host:
508 params["ldap_host"] = ldap_host
509
510 if ldap_port:
511 params["ldap_port"] = str(ldap_port)
512
513 if ldap_base_dn:
514 params["ldap_base_dn"] = ldap_base_dn
515
516 if ldap_search_attribute:
517 params["ldap_search_attribute"] = ldap_search_attribute
518
519 if ldap_bind_dn:
520 params["ldap_bind_dn"] = ldap_bind_dn
521
522 if ldap_bind_password:
523 params["ldap_bind_password"] = ldap_bind_password
524 else:
525 if ldap_userdirectory:
526 directory = self._zapi.userdirectory.get(
527 {"search": {"name": ldap_userdirectory}}
528 )
529 if not directory:
530 self._module.fail_json(
531 msg="Canot find user directory with name: %s"
532 % ldap_userdirectory
533 )
534 params["ldap_userdirectoryid"] = directory[0]["userdirectoryid"]
535
536 if isinstance(ldap_case_sensitive, bool):
537 params["ldap_case_sensitive"] = str(int(ldap_case_sensitive))
538
539 if isinstance(saml_auth_enabled, bool):
540 params["saml_auth_enabled"] = str(int(saml_auth_enabled))
541
542 if LooseVersion(self._zbx_api_version) < LooseVersion("7.0"):
543 if saml_idp_entityid:
544 params["saml_idp_entityid"] = saml_idp_entityid
545
546 if saml_sso_url:
547 params["saml_sso_url"] = saml_sso_url
548
549 if saml_slo_url:
550 params["saml_slo_url"] = saml_slo_url
551
552 if saml_username_attribute:
553 params["saml_username_attribute"] = saml_username_attribute
554
555 if saml_sp_entityid:
556 params["saml_sp_entityid"] = saml_sp_entityid
557
558 if saml_nameid_format:
559 params["saml_nameid_format"] = saml_nameid_format
560
561 if isinstance(saml_sign_messages, bool):
562 params["saml_sign_messages"] = str(int(saml_sign_messages))
563
564 if isinstance(saml_sign_assertions, bool):
565 params["saml_sign_assertions"] = str(int(saml_sign_assertions))
566
567 if isinstance(saml_sign_authn_requests, bool):
568 params["saml_sign_authn_requests"] = str(
569 int(saml_sign_authn_requests)
570 )
571
572 if isinstance(saml_sign_logout_requests, bool):
573 params["saml_sign_logout_requests"] = str(
574 int(saml_sign_logout_requests)
575 )
576
577 if isinstance(saml_sign_logout_responses, bool):
578 params["saml_sign_logout_responses"] = str(
579 int(saml_sign_logout_responses)
580 )
581
582 if isinstance(saml_encrypt_nameid, bool):
583 params["saml_encrypt_nameid"] = str(int(saml_encrypt_nameid))
584
585 if isinstance(saml_encrypt_assertions, bool):
586 params["saml_encrypt_assertions"] = str(
587 int(saml_encrypt_assertions)
588 )
589
590 if isinstance(saml_case_sensitive, bool):
591 params["saml_case_sensitive"] = str(int(saml_case_sensitive))
592 else:
593 if isinstance(ldap_jit_status, bool):
594 params["ldap_jit_status"] = str(int(ldap_jit_status))
595
596 if isinstance(saml_jit_status, bool):
597 params["saml_jit_status"] = str(int(saml_jit_status))
598
599 if isinstance(jit_provision_interval, str):
600 params["jit_provision_interval"] = jit_provision_interval
601
602 if isinstance(disabled_usrgroup, str):
603 usrgrpids = self._zapi.usergroup.get(
604 {"filter": {"name": disabled_usrgroup}}
605 )
606 if not usrgrpids:
607 self._module.fail_json(
608 "User group '%s' cannot be found" % disabled_usrgroup
609 )
610 params["disabled_usrgrpid"] = str(int(usrgrpids[0]["usrgrpid"]))
611
612 if (ldap_jit_status or saml_jit_status) and not disabled_usrgroup:
613 self._module.fail_json(
614 "'disabled_usrgroup' must be provided if 'ldap_jit_status' or 'saml_jit_status' enabled"
615 )
616
617 if passwd_min_length:
618 if passwd_min_length < 1 or passwd_min_length > 70:
619 self._module.fail_json(msg="Please set 0-70 to passwd_min_length.")
620 else:
621 params["passwd_min_length"] = str(passwd_min_length)
622
623 if passwd_check_rules is not None:
624 passwd_check_rules_values = [
625 "contain_uppercase_and_lowercase_letters",
626 "contain_digits",
627 "contain_special_characters",
628 "avoid_easy_to_guess",
629 ]
630 params["passwd_check_rules"] = 0
631 if isinstance(passwd_check_rules, str):
632 if passwd_check_rules not in passwd_check_rules_values:
633 self._module.fail_json(
634 msg="%s is invalid value for passwd_check_rules."
635 % passwd_check_rules
636 )
637 params[
638 "passwd_check_rules"
639 ] += 2 ** zabbix_utils.helper_to_numeric_value(
640 passwd_check_rules_values, passwd_check_rules
641 )
642 elif isinstance(passwd_check_rules, list):
643 for _passwd_check_rules_value in passwd_check_rules:
644 if (
645 _passwd_check_rules_value
646 not in passwd_check_rules_values
647 ):
648 self._module.fail_json(
649 msg="%s is invalid value for passwd_check_rules."
650 % _passwd_check_rules_value
651 )
652 params[
653 "passwd_check_rules"
654 ] += 2 ** zabbix_utils.helper_to_numeric_value(
655 passwd_check_rules_values, _passwd_check_rules_value
656 )
657
658 params["passwd_check_rules"] = str(params["passwd_check_rules"])
659
660 future_authentication = current_authentication.copy()
661 future_authentication.update(params)
662
663 if LooseVersion(self._zbx_api_version) < LooseVersion("7.0"):
664 if (
665 current_authentication["ldap_configured"] == "0"
666 and future_authentication["ldap_configured"] == "1"
667 ):
668 if LooseVersion(self._zbx_api_version) < LooseVersion("7.0"):
669 if (
670 not ldap_host
671 or not ldap_port
672 or not ldap_search_attribute
673 or not ldap_base_dn
674 ):
675 self._module.fail_json(
676 msg="Please set ldap_host, ldap_search_attribute and ldap_base_dn when you change a value of ldap_configured to true."
677 )
678 else:
679 if not ldap_userdirectory:
680 self._module.fail_json(
681 msg="Please set ldap_userdirectory when you change a value of ldap_configured to true."
682 )
683 else:
684 if (
685 current_authentication["ldap_auth_enabled"] == "0"
686 and future_authentication["ldap_auth_enabled"] == "1"
687 ):
688 if not ldap_userdirectory:
689 self._module.fail_json(
690 msg="Please set ldap_userdirectory when you change a value of ldap_auth_enabled to true."
691 )
692
693 if LooseVersion(self._zbx_api_version) < LooseVersion("7.0"):
694 if (
695 current_authentication["saml_auth_enabled"] == "0"
696 and future_authentication["saml_auth_enabled"] == "1"
697 and not saml_idp_entityid
698 and not saml_sso_url
699 and not saml_username_attribute
700 and not saml_sp_entityid
701 ):
702 self._module.fail_json(
703 msg=" ".join(
704 [
705 "Please set saml_idp_entityid, saml_sso_url, saml_username_attribute and saml_sp_entityid",
706 "when you change a value of saml_auth_enabled to true.",
707 ]
708 )
709 )
710
711 if future_authentication != current_authentication:
712 if self._module.check_mode:
713 self._module.exit_json(changed=True)
714
715 self._zapi.authentication.update(params)
716 self._module.exit_json(
717 changed=True, result="Successfully update authentication setting"
718 )
719 else:
720 self._module.exit_json(
721 changed=False, result="Authentication setting is already up to date"
722 )
723 except Exception as e:
724 self._module.fail_json(
725 msg="Failed to update authentication setting, Exception: %s" % e
726 )
727
728
729 def main():
730 argument_spec = zabbix_utils.zabbix_common_argument_spec()
731 argument_spec.update(
732 dict(
733 authentication_type=dict(type="str", choices=["internal", "ldap"]),
734 http_auth_enabled=dict(type="bool"),
735 http_login_form=dict(
736 type="str", choices=["zabbix_login_form", "http_login_form"]
737 ),
738 http_strip_domains=dict(type="list", elements="str"),
739 http_case_sensitive=dict(type="bool"),
740 ldap_configured=dict(type="bool"),
741 ldap_auth_enabled=dict(type="bool"),
742 ldap_host=dict(type="str"),
743 ldap_port=dict(type="int"),
744 ldap_base_dn=dict(type="str"),
745 ldap_search_attribute=dict(type="str"),
746 ldap_bind_dn=dict(type="str"),
747 ldap_case_sensitive=dict(type="bool"),
748 ldap_bind_password=dict(type="str", no_log=True),
749 ldap_userdirectory=dict(type="str"),
750 ldap_jit_status=dict(type="bool"),
751 saml_auth_enabled=dict(type="bool"),
752 saml_idp_entityid=dict(type="str"),
753 saml_sso_url=dict(type="str"),
754 saml_slo_url=dict(type="str"),
755 saml_username_attribute=dict(type="str"),
756 saml_sp_entityid=dict(type="str"),
757 saml_nameid_format=dict(type="str"),
758 saml_sign_messages=dict(type="bool"),
759 saml_sign_assertions=dict(type="bool"),
760 saml_sign_authn_requests=dict(type="bool"),
761 saml_sign_logout_requests=dict(type="bool"),
762 saml_sign_logout_responses=dict(type="bool"),
763 saml_encrypt_nameid=dict(type="bool"),
764 saml_encrypt_assertions=dict(type="bool"),
765 saml_case_sensitive=dict(type="bool"),
766 saml_jit_status=dict(type="bool"),
767 jit_provision_interval=dict(type="str", default="1h"),
768 disabled_usrgroup=dict(type="str"),
769 passwd_min_length=dict(type="int", no_log=False),
770 passwd_check_rules=dict(type="list", elements="str", no_log=False),
771 )
772 )
773 module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True)
774
775 authentication_type = module.params["authentication_type"]
776 http_auth_enabled = module.params["http_auth_enabled"]
777 http_login_form = module.params["http_login_form"]
778 http_strip_domains = module.params["http_strip_domains"]
779 http_case_sensitive = module.params["http_case_sensitive"]
780 ldap_configured = module.params["ldap_configured"]
781 ldap_auth_enabled = module.params["ldap_auth_enabled"]
782 ldap_host = module.params["ldap_host"]
783 ldap_port = module.params["ldap_port"]
784 ldap_base_dn = module.params["ldap_base_dn"]
785 ldap_search_attribute = module.params["ldap_search_attribute"]
786 ldap_bind_dn = module.params["ldap_bind_dn"]
787 ldap_case_sensitive = module.params["ldap_case_sensitive"]
788 ldap_bind_password = module.params["ldap_bind_password"]
789 ldap_userdirectory = module.params["ldap_userdirectory"]
790 saml_auth_enabled = module.params["saml_auth_enabled"]
791 saml_idp_entityid = module.params["saml_idp_entityid"]
792 saml_sso_url = module.params["saml_sso_url"]
793 saml_slo_url = module.params["saml_slo_url"]
794 saml_username_attribute = module.params["saml_username_attribute"]
795 saml_sp_entityid = module.params["saml_sp_entityid"]
796 saml_nameid_format = module.params["saml_nameid_format"]
797 saml_sign_messages = module.params["saml_sign_messages"]
798 saml_sign_assertions = module.params["saml_sign_assertions"]
799 saml_sign_authn_requests = module.params["saml_sign_authn_requests"]
800 saml_sign_logout_requests = module.params["saml_sign_logout_requests"]
801 saml_sign_logout_responses = module.params["saml_sign_logout_responses"]
802 saml_encrypt_nameid = module.params["saml_encrypt_nameid"]
803 saml_encrypt_assertions = module.params["saml_encrypt_assertions"]
804 saml_case_sensitive = module.params["saml_case_sensitive"]
805 passwd_min_length = module.params["passwd_min_length"]
806 passwd_check_rules = module.params["passwd_check_rules"]
807 ldap_jit_status = module.params["ldap_jit_status"]
808 saml_jit_status = module.params["saml_jit_status"]
809 jit_provision_interval = module.params["jit_provision_interval"]
810 disabled_usrgroup = module.params["disabled_usrgroup"]
811
812 authentication = Authentication(module)
813
814 current_authentication = authentication.get_authentication()
815 authentication.update_authentication(
816 current_authentication,
817 authentication_type,
818 http_auth_enabled,
819 http_login_form,
820 http_strip_domains,
821 http_case_sensitive,
822 ldap_configured,
823 ldap_auth_enabled,
824 ldap_host,
825 ldap_port,
826 ldap_base_dn,
827 ldap_search_attribute,
828 ldap_bind_dn,
829 ldap_case_sensitive,
830 ldap_bind_password,
831 ldap_userdirectory,
832 saml_auth_enabled,
833 saml_idp_entityid,
834 saml_sso_url,
835 saml_slo_url,
836 saml_username_attribute,
837 saml_sp_entityid,
838 saml_nameid_format,
839 saml_sign_messages,
840 saml_sign_assertions,
841 saml_sign_authn_requests,
842 saml_sign_logout_requests,
843 saml_sign_logout_responses,
844 saml_encrypt_nameid,
845 saml_encrypt_assertions,
846 saml_case_sensitive,
847 passwd_min_length,
848 passwd_check_rules,
849 ldap_jit_status,
850 saml_jit_status,
851 jit_provision_interval,
852 disabled_usrgroup,
853 )
854
855
856 if __name__ == "__main__":
857 main()