| 1 |
#!/usr/bin/python |
| 2 |
|
| 3 |
# Copyright (c) 2018, Stephan Schwarz <[email protected]> |
| 4 |
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 5 |
# SPDX-License-Identifier: GPL-3.0-or-later |
| 6 |
|
| 7 |
from __future__ import annotations |
| 8 |
|
| 9 |
DOCUMENTATION = r""" |
| 10 |
module: utm_proxy_auth_profile |
| 11 |
|
| 12 |
author: |
| 13 |
- Stephan Schwarz (@stearz) |
| 14 |
|
| 15 |
short_description: Create, update or destroy reverse_proxy auth_profile entry in Sophos UTM |
| 16 |
|
| 17 |
description: |
| 18 |
- Create, update or destroy a reverse_proxy auth_profile entry in SOPHOS UTM. |
| 19 |
- This module needs to have the REST Ability of the UTM to be activated. |
| 20 |
attributes: |
| 21 |
check_mode: |
| 22 |
support: none |
| 23 |
diff_mode: |
| 24 |
support: none |
| 25 |
|
| 26 |
options: |
| 27 |
name: |
| 28 |
type: str |
| 29 |
description: |
| 30 |
- The name of the object that identifies the entry. |
| 31 |
required: true |
| 32 |
aaa: |
| 33 |
type: list |
| 34 |
elements: str |
| 35 |
description: |
| 36 |
- List of references to utm_aaa objects (allowed users or groups). |
| 37 |
required: true |
| 38 |
basic_prompt: |
| 39 |
type: str |
| 40 |
description: |
| 41 |
- The message in the basic authentication prompt. |
| 42 |
required: true |
| 43 |
backend_mode: |
| 44 |
type: str |
| 45 |
description: |
| 46 |
- Specifies if the backend server needs authentication ([Basic|None]). |
| 47 |
default: None |
| 48 |
choices: |
| 49 |
- Basic |
| 50 |
- None |
| 51 |
backend_strip_basic_auth: |
| 52 |
description: |
| 53 |
- Should the login data be stripped when proxying the request to the backend host. |
| 54 |
type: bool |
| 55 |
default: true |
| 56 |
backend_user_prefix: |
| 57 |
type: str |
| 58 |
description: |
| 59 |
- Prefix string to prepend to the username for backend authentication. |
| 60 |
default: "" |
| 61 |
backend_user_suffix: |
| 62 |
type: str |
| 63 |
description: |
| 64 |
- Suffix string to append to the username for backend authentication. |
| 65 |
default: "" |
| 66 |
comment: |
| 67 |
type: str |
| 68 |
description: |
| 69 |
- Optional comment string. |
| 70 |
default: "" |
| 71 |
frontend_cookie: |
| 72 |
type: str |
| 73 |
description: |
| 74 |
- Frontend cookie name. |
| 75 |
frontend_cookie_secret: |
| 76 |
type: str |
| 77 |
description: |
| 78 |
- Frontend cookie secret. |
| 79 |
frontend_form: |
| 80 |
type: str |
| 81 |
description: |
| 82 |
- Frontend authentication form name. |
| 83 |
frontend_form_template: |
| 84 |
type: str |
| 85 |
description: |
| 86 |
- Frontend authentication form template. |
| 87 |
default: "" |
| 88 |
frontend_login: |
| 89 |
type: str |
| 90 |
description: |
| 91 |
- Frontend login name. |
| 92 |
frontend_logout: |
| 93 |
type: str |
| 94 |
description: |
| 95 |
- Frontend logout name. |
| 96 |
frontend_mode: |
| 97 |
type: str |
| 98 |
description: |
| 99 |
- Frontend authentication mode (Form|Basic). |
| 100 |
default: Basic |
| 101 |
choices: |
| 102 |
- Basic |
| 103 |
- Form |
| 104 |
frontend_realm: |
| 105 |
type: str |
| 106 |
description: |
| 107 |
- Frontend authentication realm. |
| 108 |
frontend_session_allow_persistency: |
| 109 |
description: |
| 110 |
- Allow session persistency. |
| 111 |
type: bool |
| 112 |
default: false |
| 113 |
frontend_session_lifetime: |
| 114 |
type: int |
| 115 |
description: |
| 116 |
- Session lifetime. |
| 117 |
required: true |
| 118 |
frontend_session_lifetime_limited: |
| 119 |
description: |
| 120 |
- Specifies if limitation of session lifetime is active. |
| 121 |
type: bool |
| 122 |
default: true |
| 123 |
frontend_session_lifetime_scope: |
| 124 |
type: str |
| 125 |
description: |
| 126 |
- Scope for frontend_session_lifetime (days|hours|minutes). |
| 127 |
default: hours |
| 128 |
choices: |
| 129 |
- days |
| 130 |
- hours |
| 131 |
- minutes |
| 132 |
frontend_session_timeout: |
| 133 |
type: int |
| 134 |
description: |
| 135 |
- Session timeout. |
| 136 |
required: true |
| 137 |
frontend_session_timeout_enabled: |
| 138 |
description: |
| 139 |
- Specifies if session timeout is active. |
| 140 |
type: bool |
| 141 |
default: true |
| 142 |
frontend_session_timeout_scope: |
| 143 |
type: str |
| 144 |
description: |
| 145 |
- Scope for frontend_session_timeout (days|hours|minutes). |
| 146 |
default: minutes |
| 147 |
choices: |
| 148 |
- days |
| 149 |
- hours |
| 150 |
- minutes |
| 151 |
logout_delegation_urls: |
| 152 |
type: list |
| 153 |
elements: str |
| 154 |
description: |
| 155 |
- List of logout URLs that logouts are delegated to. |
| 156 |
default: [] |
| 157 |
logout_mode: |
| 158 |
type: str |
| 159 |
description: |
| 160 |
- Mode of logout (None|Delegation). |
| 161 |
default: None |
| 162 |
choices: |
| 163 |
- None |
| 164 |
- Delegation |
| 165 |
redirect_to_requested_url: |
| 166 |
description: |
| 167 |
- Should a redirect to the requested URL be made. |
| 168 |
type: bool |
| 169 |
default: false |
| 170 |
|
| 171 |
extends_documentation_fragment: |
| 172 |
- community.general._utm |
| 173 |
- community.general._attributes |
| 174 |
""" |
| 175 |
|
| 176 |
EXAMPLES = r""" |
| 177 |
- name: Create UTM proxy_auth_profile |
| 178 |
community.general.utm_proxy_auth_profile: |
| 179 |
utm_host: sophos.host.name |
| 180 |
utm_token: abcdefghijklmno1234 |
| 181 |
name: TestAuthProfileEntry |
| 182 |
aaa: [REF_OBJECT_STRING, REF_ANOTHEROBJECT_STRING] |
| 183 |
basic_prompt: "Authentication required: Please login" |
| 184 |
frontend_session_lifetime: 1 |
| 185 |
frontend_session_timeout: 1 |
| 186 |
state: present |
| 187 |
|
| 188 |
- name: Remove UTM proxy_auth_profile |
| 189 |
community.general.utm_proxy_auth_profile: |
| 190 |
utm_host: sophos.host.name |
| 191 |
utm_token: abcdefghijklmno1234 |
| 192 |
name: TestAuthProfileEntry |
| 193 |
state: absent |
| 194 |
|
| 195 |
- name: Read UTM proxy_auth_profile |
| 196 |
community.general.utm_proxy_auth_profile: |
| 197 |
utm_host: sophos.host.name |
| 198 |
utm_token: abcdefghijklmno1234 |
| 199 |
name: TestAuthProfileEntry |
| 200 |
state: info |
| 201 |
""" |
| 202 |
|
| 203 |
RETURN = r""" |
| 204 |
result: |
| 205 |
description: The utm object that was created. |
| 206 |
returned: success |
| 207 |
type: complex |
| 208 |
contains: |
| 209 |
_ref: |
| 210 |
description: The reference name of the object. |
| 211 |
type: str |
| 212 |
_locked: |
| 213 |
description: Whether or not the object is currently locked. |
| 214 |
type: bool |
| 215 |
_type: |
| 216 |
description: The type of the object. |
| 217 |
type: str |
| 218 |
name: |
| 219 |
description: The name of the object. |
| 220 |
type: str |
| 221 |
aaa: |
| 222 |
description: List of references to utm_aaa objects (allowed users or groups). |
| 223 |
type: list |
| 224 |
basic_prompt: |
| 225 |
description: The message in the basic authentication prompt. |
| 226 |
type: str |
| 227 |
backend_mode: |
| 228 |
description: Specifies if the backend server needs authentication ([Basic|None]). |
| 229 |
type: str |
| 230 |
backend_strip_basic_auth: |
| 231 |
description: Should the login data be stripped when proxying the request to the backend host. |
| 232 |
type: bool |
| 233 |
backend_user_prefix: |
| 234 |
description: Prefix string to prepend to the username for backend authentication. |
| 235 |
type: str |
| 236 |
backend_user_suffix: |
| 237 |
description: Suffix string to append to the username for backend authentication. |
| 238 |
type: str |
| 239 |
comment: |
| 240 |
description: Optional comment string. |
| 241 |
type: str |
| 242 |
frontend_cookie: |
| 243 |
description: Frontend cookie name. |
| 244 |
type: str |
| 245 |
frontend_form: |
| 246 |
description: Frontend authentication form name. |
| 247 |
type: str |
| 248 |
frontend_form_template: |
| 249 |
description: Frontend authentication form template. |
| 250 |
type: str |
| 251 |
frontend_login: |
| 252 |
description: Frontend login name. |
| 253 |
type: str |
| 254 |
frontend_logout: |
| 255 |
description: Frontend logout name. |
| 256 |
type: str |
| 257 |
frontend_mode: |
| 258 |
description: Frontend authentication mode (Form|Basic). |
| 259 |
type: str |
| 260 |
frontend_realm: |
| 261 |
description: Frontend authentication realm. |
| 262 |
type: str |
| 263 |
frontend_session_allow_persistency: |
| 264 |
description: Allow session persistency. |
| 265 |
type: bool |
| 266 |
frontend_session_lifetime: |
| 267 |
description: Session lifetime. |
| 268 |
type: int |
| 269 |
frontend_session_lifetime_limited: |
| 270 |
description: Specifies if limitation of session lifetime is active. |
| 271 |
type: bool |
| 272 |
frontend_session_lifetime_scope: |
| 273 |
description: Scope for frontend_session_lifetime (days|hours|minutes). |
| 274 |
type: str |
| 275 |
frontend_session_timeout: |
| 276 |
description: Session timeout. |
| 277 |
type: int |
| 278 |
frontend_session_timeout_enabled: |
| 279 |
description: Specifies if session timeout is active. |
| 280 |
type: bool |
| 281 |
frontend_session_timeout_scope: |
| 282 |
description: Scope for frontend_session_timeout (days|hours|minutes). |
| 283 |
type: str |
| 284 |
logout_delegation_urls: |
| 285 |
description: List of logout URLs that logouts are delegated to. |
| 286 |
type: list |
| 287 |
logout_mode: |
| 288 |
description: Mode of logout (None|Delegation). |
| 289 |
type: str |
| 290 |
redirect_to_requested_url: |
| 291 |
description: Should a redirect to the requested URL be made. |
| 292 |
type: bool |
| 293 |
""" |
| 294 |
|
| 295 |
from ansible_collections.community.general.plugins.module_utils._utm_utils import UTM, UTMModule |
| 296 |
|
| 297 |
|
| 298 |
def main(): |
| 299 |
endpoint = "reverse_proxy/auth_profile" |
| 300 |
key_to_check_for_changes = [ |
| 301 |
"aaa", |
| 302 |
"basic_prompt", |
| 303 |
"backend_mode", |
| 304 |
"backend_strip_basic_auth", |
| 305 |
"backend_user_prefix", |
| 306 |
"backend_user_suffix", |
| 307 |
"comment", |
| 308 |
"frontend_cookie", |
| 309 |
"frontend_cookie_secret", |
| 310 |
"frontend_form", |
| 311 |
"frontend_form_template", |
| 312 |
"frontend_login", |
| 313 |
"frontend_logout", |
| 314 |
"frontend_mode", |
| 315 |
"frontend_realm", |
| 316 |
"frontend_session_allow_persistency", |
| 317 |
"frontend_session_lifetime", |
| 318 |
"frontend_session_lifetime_limited", |
| 319 |
"frontend_session_lifetime_scope", |
| 320 |
"frontend_session_timeout", |
| 321 |
"frontend_session_timeout_enabled", |
| 322 |
"frontend_session_timeout_scope", |
| 323 |
"logout_delegation_urls", |
| 324 |
"logout_mode", |
| 325 |
"redirect_to_requested_url", |
| 326 |
] |
| 327 |
|
| 328 |
module = UTMModule( |
| 329 |
argument_spec=dict( |
| 330 |
name=dict(type="str", required=True), |
| 331 |
aaa=dict(type="list", elements="str", required=True), |
| 332 |
basic_prompt=dict(type="str", required=True), |
| 333 |
backend_mode=dict(type="str", default="None", choices=["Basic", "None"]), |
| 334 |
backend_strip_basic_auth=dict(type="bool", default=True), |
| 335 |
backend_user_prefix=dict(type="str", default=""), |
| 336 |
backend_user_suffix=dict(type="str", default=""), |
| 337 |
comment=dict(type="str", default=""), |
| 338 |
frontend_cookie=dict(type="str"), |
| 339 |
frontend_cookie_secret=dict(type="str", no_log=True), |
| 340 |
frontend_form=dict(type="str"), |
| 341 |
frontend_form_template=dict(type="str", default=""), |
| 342 |
frontend_login=dict(type="str"), |
| 343 |
frontend_logout=dict(type="str"), |
| 344 |
frontend_mode=dict(type="str", default="Basic", choices=["Basic", "Form"]), |
| 345 |
frontend_realm=dict(type="str"), |
| 346 |
frontend_session_allow_persistency=dict(type="bool", default=False), |
| 347 |
frontend_session_lifetime=dict(type="int", required=True), |
| 348 |
frontend_session_lifetime_limited=dict(type="bool", default=True), |
| 349 |
frontend_session_lifetime_scope=dict(type="str", default="hours", choices=["days", "hours", "minutes"]), |
| 350 |
frontend_session_timeout=dict(type="int", required=True), |
| 351 |
frontend_session_timeout_enabled=dict(type="bool", default=True), |
| 352 |
frontend_session_timeout_scope=dict(type="str", default="minutes", choices=["days", "hours", "minutes"]), |
| 353 |
logout_delegation_urls=dict(type="list", elements="str", default=[]), |
| 354 |
logout_mode=dict(type="str", default="None", choices=["None", "Delegation"]), |
| 355 |
redirect_to_requested_url=dict(type="bool", default=False), |
| 356 |
) |
| 357 |
) |
| 358 |
try: |
| 359 |
UTM(module, endpoint, key_to_check_for_changes).execute() |
| 360 |
except Exception as e: |
| 361 |
module.fail_json(msg=f"{e}") |
| 362 |
|
| 363 |
|
| 364 |
if __name__ == "__main__": |
| 365 |
main() |