2020-03-09 10:11:07 +01:00
|
|
|
#!/usr/bin/python
|
2021-08-08 10:40:22 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2020-03-09 10:11:07 +01:00
|
|
|
|
2022-08-05 12:28:29 +02:00
|
|
|
# Copyright (c) 2018, Stephan Schwarz <stearz@gmx.de>
|
|
|
|
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
|
|
|
|
__metaclass__ = type
|
|
|
|
|
|
|
|
DOCUMENTATION = '''
|
|
|
|
---
|
|
|
|
module: utm_proxy_auth_profile
|
|
|
|
|
|
|
|
author:
|
|
|
|
- Stephan Schwarz (@stearz)
|
|
|
|
|
2022-11-09 21:09:09 +01:00
|
|
|
short_description: Create, update or destroy reverse_proxy auth_profile entry in Sophos UTM
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
description:
|
|
|
|
- Create, update or destroy a reverse_proxy auth_profile entry in SOPHOS UTM.
|
|
|
|
- This module needs to have the REST Ability of the UTM to be activated.
|
|
|
|
|
2023-02-24 09:23:28 +01:00
|
|
|
attributes:
|
|
|
|
check_mode:
|
|
|
|
support: none
|
|
|
|
diff_mode:
|
|
|
|
support: none
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
options:
|
|
|
|
name:
|
2020-11-22 12:17:46 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- The name of the object. Will be used to identify the entry
|
|
|
|
required: true
|
|
|
|
aaa:
|
2020-11-22 12:17:46 +01:00
|
|
|
type: list
|
|
|
|
elements: str
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- List of references to utm_aaa objects (allowed users or groups)
|
|
|
|
required: true
|
|
|
|
basic_prompt:
|
2020-11-22 12:17:46 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- The message in the basic authentication prompt
|
|
|
|
required: true
|
|
|
|
backend_mode:
|
2020-11-22 12:17:46 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- Specifies if the backend server needs authentication ([Basic|None])
|
|
|
|
default: None
|
|
|
|
choices:
|
|
|
|
- Basic
|
|
|
|
- None
|
|
|
|
backend_strip_basic_auth:
|
|
|
|
description:
|
|
|
|
- Should the login data be stripped when proxying the request to the backend host
|
|
|
|
type: bool
|
2022-09-06 20:42:17 +02:00
|
|
|
default: true
|
2020-03-09 10:11:07 +01:00
|
|
|
backend_user_prefix:
|
2020-11-22 12:17:46 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- Prefix string to prepend to the username for backend authentication
|
|
|
|
default: ""
|
|
|
|
backend_user_suffix:
|
2020-11-22 12:17:46 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- Suffix string to append to the username for backend authentication
|
|
|
|
default: ""
|
|
|
|
comment:
|
2020-11-22 12:17:46 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- Optional comment string
|
|
|
|
default: ""
|
|
|
|
frontend_cookie:
|
2020-11-22 12:17:46 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- Frontend cookie name
|
|
|
|
frontend_cookie_secret:
|
2020-11-22 12:17:46 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- Frontend cookie secret
|
|
|
|
frontend_form:
|
2020-11-22 12:17:46 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- Frontend authentication form name
|
|
|
|
frontend_form_template:
|
2020-11-22 12:17:46 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- Frontend authentication form template
|
|
|
|
default: ""
|
|
|
|
frontend_login:
|
2020-11-22 12:17:46 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- Frontend login name
|
|
|
|
frontend_logout:
|
2020-11-22 12:17:46 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- Frontend logout name
|
|
|
|
frontend_mode:
|
2020-11-22 12:17:46 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- Frontend authentication mode (Form|Basic)
|
|
|
|
default: Basic
|
|
|
|
choices:
|
|
|
|
- Basic
|
|
|
|
- Form
|
|
|
|
frontend_realm:
|
2020-11-22 12:17:46 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- Frontend authentication realm
|
|
|
|
frontend_session_allow_persistency:
|
|
|
|
description:
|
|
|
|
- Allow session persistency
|
|
|
|
type: bool
|
2022-09-06 20:42:17 +02:00
|
|
|
default: false
|
2020-03-09 10:11:07 +01:00
|
|
|
frontend_session_lifetime:
|
2020-11-22 12:17:46 +01:00
|
|
|
type: int
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- session lifetime
|
|
|
|
required: true
|
|
|
|
frontend_session_lifetime_limited:
|
|
|
|
description:
|
|
|
|
- Specifies if limitation of session lifetime is active
|
|
|
|
type: bool
|
2022-09-06 20:42:17 +02:00
|
|
|
default: true
|
2020-03-09 10:11:07 +01:00
|
|
|
frontend_session_lifetime_scope:
|
2020-11-22 12:17:46 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- scope for frontend_session_lifetime (days|hours|minutes)
|
|
|
|
default: hours
|
|
|
|
choices:
|
|
|
|
- days
|
|
|
|
- hours
|
|
|
|
- minutes
|
|
|
|
frontend_session_timeout:
|
2020-11-22 12:17:46 +01:00
|
|
|
type: int
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- session timeout
|
|
|
|
required: true
|
|
|
|
frontend_session_timeout_enabled:
|
|
|
|
description:
|
|
|
|
- Specifies if session timeout is active
|
|
|
|
type: bool
|
2022-09-06 20:42:17 +02:00
|
|
|
default: true
|
2020-03-09 10:11:07 +01:00
|
|
|
frontend_session_timeout_scope:
|
2020-11-22 12:17:46 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- scope for frontend_session_timeout (days|hours|minutes)
|
|
|
|
default: minutes
|
|
|
|
choices:
|
|
|
|
- days
|
|
|
|
- hours
|
|
|
|
- minutes
|
|
|
|
logout_delegation_urls:
|
2020-11-22 12:17:46 +01:00
|
|
|
type: list
|
|
|
|
elements: str
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- List of logout URLs that logouts are delegated to
|
|
|
|
default: []
|
|
|
|
logout_mode:
|
2020-11-22 12:17:46 +01:00
|
|
|
type: str
|
2020-03-09 10:11:07 +01:00
|
|
|
description:
|
|
|
|
- Mode of logout (None|Delegation)
|
|
|
|
default: None
|
|
|
|
choices:
|
|
|
|
- None
|
|
|
|
- Delegation
|
|
|
|
redirect_to_requested_url:
|
|
|
|
description:
|
|
|
|
- Should a redirect to the requested URL be made
|
|
|
|
type: bool
|
2022-09-06 20:42:17 +02:00
|
|
|
default: false
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
extends_documentation_fragment:
|
|
|
|
- community.general.utm
|
2023-02-24 09:23:28 +01:00
|
|
|
- community.general.attributes
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
'''
|
|
|
|
|
|
|
|
EXAMPLES = """
|
|
|
|
- name: Create UTM proxy_auth_profile
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.utm_proxy_auth_profile:
|
2020-03-09 10:11:07 +01:00
|
|
|
utm_host: sophos.host.name
|
|
|
|
utm_token: abcdefghijklmno1234
|
|
|
|
name: TestAuthProfileEntry
|
|
|
|
aaa: [REF_OBJECT_STRING,REF_ANOTHEROBJECT_STRING]
|
|
|
|
basic_prompt: "Authentication required: Please login"
|
|
|
|
frontend_session_lifetime: 1
|
|
|
|
frontend_session_timeout: 1
|
|
|
|
state: present
|
|
|
|
|
|
|
|
- name: Remove UTM proxy_auth_profile
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.utm_proxy_auth_profile:
|
2020-03-09 10:11:07 +01:00
|
|
|
utm_host: sophos.host.name
|
|
|
|
utm_token: abcdefghijklmno1234
|
|
|
|
name: TestAuthProfileEntry
|
|
|
|
state: absent
|
|
|
|
|
|
|
|
- name: Read UTM proxy_auth_profile
|
2020-07-13 21:50:31 +02:00
|
|
|
community.general.utm_proxy_auth_profile:
|
2020-03-09 10:11:07 +01:00
|
|
|
utm_host: sophos.host.name
|
|
|
|
utm_token: abcdefghijklmno1234
|
|
|
|
name: TestAuthProfileEntry
|
|
|
|
state: info
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
RETURN = """
|
|
|
|
result:
|
|
|
|
description: The utm object that was created
|
|
|
|
returned: success
|
|
|
|
type: complex
|
|
|
|
contains:
|
|
|
|
_ref:
|
|
|
|
description: The reference name of the object
|
|
|
|
type: str
|
|
|
|
_locked:
|
|
|
|
description: Whether or not the object is currently locked
|
|
|
|
type: bool
|
|
|
|
_type:
|
|
|
|
description: The type of the object
|
|
|
|
type: str
|
|
|
|
name:
|
|
|
|
description: The name of the object
|
|
|
|
type: str
|
|
|
|
aaa:
|
|
|
|
description: List of references to utm_aaa objects (allowed users or groups)
|
|
|
|
type: list
|
|
|
|
basic_prompt:
|
|
|
|
description: The message in the basic authentication prompt
|
|
|
|
type: str
|
|
|
|
backend_mode:
|
|
|
|
description: Specifies if the backend server needs authentication ([Basic|None])
|
|
|
|
type: str
|
|
|
|
backend_strip_basic_auth:
|
|
|
|
description: Should the login data be stripped when proxying the request to the backend host
|
|
|
|
type: bool
|
|
|
|
backend_user_prefix:
|
|
|
|
description: Prefix string to prepend to the username for backend authentication
|
|
|
|
type: str
|
|
|
|
backend_user_suffix:
|
|
|
|
description: Suffix string to append to the username for backend authentication
|
|
|
|
type: str
|
|
|
|
comment:
|
|
|
|
description: Optional comment string
|
|
|
|
type: str
|
|
|
|
frontend_cookie:
|
|
|
|
description: Frontend cookie name
|
|
|
|
type: str
|
|
|
|
frontend_form:
|
|
|
|
description: Frontend authentication form name
|
|
|
|
type: str
|
|
|
|
frontend_form_template:
|
|
|
|
description: Frontend authentication form template
|
|
|
|
type: str
|
|
|
|
frontend_login:
|
|
|
|
description: Frontend login name
|
|
|
|
type: str
|
|
|
|
frontend_logout:
|
|
|
|
description: Frontend logout name
|
|
|
|
type: str
|
|
|
|
frontend_mode:
|
|
|
|
description: Frontend authentication mode (Form|Basic)
|
|
|
|
type: str
|
|
|
|
frontend_realm:
|
|
|
|
description: Frontend authentication realm
|
|
|
|
type: str
|
|
|
|
frontend_session_allow_persistency:
|
|
|
|
description: Allow session persistency
|
|
|
|
type: bool
|
|
|
|
frontend_session_lifetime:
|
|
|
|
description: session lifetime
|
|
|
|
type: int
|
|
|
|
frontend_session_lifetime_limited:
|
|
|
|
description: Specifies if limitation of session lifetime is active
|
|
|
|
type: bool
|
|
|
|
frontend_session_lifetime_scope:
|
|
|
|
description: scope for frontend_session_lifetime (days|hours|minutes)
|
|
|
|
type: str
|
|
|
|
frontend_session_timeout:
|
|
|
|
description: session timeout
|
|
|
|
type: int
|
|
|
|
frontend_session_timeout_enabled:
|
|
|
|
description: Specifies if session timeout is active
|
|
|
|
type: bool
|
|
|
|
frontend_session_timeout_scope:
|
|
|
|
description: scope for frontend_session_timeout (days|hours|minutes)
|
|
|
|
type: str
|
|
|
|
logout_delegation_urls:
|
|
|
|
description: List of logout URLs that logouts are delegated to
|
|
|
|
type: list
|
|
|
|
logout_mode:
|
|
|
|
description: Mode of logout (None|Delegation)
|
|
|
|
type: str
|
|
|
|
redirect_to_requested_url:
|
|
|
|
description: Should a redirect to the requested URL be made
|
|
|
|
type: bool
|
|
|
|
"""
|
|
|
|
|
|
|
|
from ansible_collections.community.general.plugins.module_utils.utm_utils import UTM, UTMModule
|
2021-06-26 23:59:11 +02:00
|
|
|
from ansible.module_utils.common.text.converters import to_native
|
2020-03-09 10:11:07 +01:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
endpoint = "reverse_proxy/auth_profile"
|
|
|
|
key_to_check_for_changes = ["aaa", "basic_prompt", "backend_mode", "backend_strip_basic_auth",
|
|
|
|
"backend_user_prefix", "backend_user_suffix", "comment", "frontend_cookie",
|
|
|
|
"frontend_cookie_secret", "frontend_form", "frontend_form_template",
|
|
|
|
"frontend_login", "frontend_logout", "frontend_mode", "frontend_realm",
|
|
|
|
"frontend_session_allow_persistency", "frontend_session_lifetime",
|
|
|
|
"frontend_session_lifetime_limited", "frontend_session_lifetime_scope",
|
|
|
|
"frontend_session_timeout", "frontend_session_timeout_enabled",
|
|
|
|
"frontend_session_timeout_scope", "logout_delegation_urls", "logout_mode",
|
|
|
|
"redirect_to_requested_url"]
|
|
|
|
|
|
|
|
module = UTMModule(
|
|
|
|
argument_spec=dict(
|
|
|
|
name=dict(type='str', required=True),
|
|
|
|
aaa=dict(type='list', elements='str', required=True),
|
|
|
|
basic_prompt=dict(type='str', required=True),
|
|
|
|
backend_mode=dict(type='str', required=False, default="None", choices=['Basic', 'None']),
|
2023-03-06 23:02:24 +01:00
|
|
|
backend_strip_basic_auth=dict(type='bool', required=False, default=True),
|
2020-03-09 10:11:07 +01:00
|
|
|
backend_user_prefix=dict(type='str', required=False, default=""),
|
|
|
|
backend_user_suffix=dict(type='str', required=False, default=""),
|
|
|
|
comment=dict(type='str', required=False, default=""),
|
|
|
|
frontend_cookie=dict(type='str', required=False),
|
2021-02-04 21:02:21 +01:00
|
|
|
frontend_cookie_secret=dict(type='str', required=False, no_log=True),
|
2020-03-09 10:11:07 +01:00
|
|
|
frontend_form=dict(type='str', required=False),
|
|
|
|
frontend_form_template=dict(type='str', required=False, default=""),
|
|
|
|
frontend_login=dict(type='str', required=False),
|
|
|
|
frontend_logout=dict(type='str', required=False),
|
|
|
|
frontend_mode=dict(type='str', required=False, default="Basic", choices=['Basic', 'Form']),
|
|
|
|
frontend_realm=dict(type='str', required=False),
|
2023-03-06 23:02:24 +01:00
|
|
|
frontend_session_allow_persistency=dict(type='bool', required=False, default=False),
|
2020-03-09 10:11:07 +01:00
|
|
|
frontend_session_lifetime=dict(type='int', required=True),
|
2023-03-06 23:02:24 +01:00
|
|
|
frontend_session_lifetime_limited=dict(type='bool', required=False, default=True),
|
2020-03-09 10:11:07 +01:00
|
|
|
frontend_session_lifetime_scope=dict(type='str', required=False, default="hours", choices=['days', 'hours', 'minutes']),
|
|
|
|
frontend_session_timeout=dict(type='int', required=True),
|
2023-03-06 23:02:24 +01:00
|
|
|
frontend_session_timeout_enabled=dict(type='bool', required=False, default=True),
|
2020-03-09 10:11:07 +01:00
|
|
|
frontend_session_timeout_scope=dict(type='str', required=False, default="minutes", choices=['days', 'hours', 'minutes']),
|
|
|
|
logout_delegation_urls=dict(type='list', elements='str', required=False, default=[]),
|
|
|
|
logout_mode=dict(type='str', required=False, default="None", choices=['None', 'Delegation']),
|
2023-03-06 23:02:24 +01:00
|
|
|
redirect_to_requested_url=dict(type='bool', required=False, default=False)
|
2020-03-09 10:11:07 +01:00
|
|
|
)
|
|
|
|
)
|
|
|
|
try:
|
|
|
|
UTM(module, endpoint, key_to_check_for_changes).execute()
|
|
|
|
except Exception as e:
|
|
|
|
module.fail_json(msg=to_native(e))
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|