| 1 |
#!/usr/bin/python |
| 2 |
|
| 3 |
# (c) 2025, NetApp Inc |
| 4 |
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) |
| 5 |
|
| 6 |
"""NetApp StorageGRID - Manage audit log destinations""" |
| 7 |
|
| 8 |
from __future__ import absolute_import, division, print_function |
| 9 |
|
| 10 |
__metaclass__ = type |
| 11 |
|
| 12 |
|
| 13 |
ANSIBLE_METADATA = { |
| 14 |
"metadata_version": "1.0", |
| 15 |
"status": ["preview"], |
| 16 |
"supported_by": "community", |
| 17 |
} |
| 18 |
|
| 19 |
|
| 20 |
DOCUMENTATION = """ |
| 21 |
module: na_sg_grid_audit_destination |
| 22 |
short_description: Configure audit log destinations on StorageGRID. |
| 23 |
extends_documentation_fragment: |
| 24 |
- netapp.storagegrid.netapp.sg |
| 25 |
version_added: '21.15.0' |
| 26 |
author: NetApp Ansible Team (@vinaykus) <[email protected]> |
| 27 |
description: |
| 28 |
- Configure audit log destinations on NetApp StorageGRID. |
| 29 |
options: |
| 30 |
state: |
| 31 |
description: |
| 32 |
- The audit destination should be present. |
| 33 |
choices: ['present'] |
| 34 |
default: 'present' |
| 35 |
type: str |
| 36 |
defaults: |
| 37 |
description: |
| 38 |
- The defaults will be used to configure audit destinations on all nodes which are not in the nodes array. |
| 39 |
type: dict |
| 40 |
suboptions: |
| 41 |
admin_nodes: |
| 42 |
description: |
| 43 |
- Configuration for traditional audit log export to admin nodes. |
| 44 |
type: dict |
| 45 |
suboptions: |
| 46 |
enabled: |
| 47 |
description: |
| 48 |
- If true, traditional audit log export to admin nodes is enabled. |
| 49 |
type: bool |
| 50 |
default: True |
| 51 |
remote_syslog_server: |
| 52 |
description: |
| 53 |
- Configuration for sending audit logs to an external syslog server. |
| 54 |
type: dict |
| 55 |
suboptions: |
| 56 |
enabled: |
| 57 |
description: |
| 58 |
- If true, the external syslog server destination is enabled. |
| 59 |
type: bool |
| 60 |
default: False |
| 61 |
protocol: |
| 62 |
description: |
| 63 |
- The IP protocol to use for sending to the external syslog server. |
| 64 |
choices: ['udp', 'tcp', 'tls', 'relp+tcp', 'relp+tls'] |
| 65 |
default: 'udp' |
| 66 |
type: str |
| 67 |
server_ca_cert: |
| 68 |
description: |
| 69 |
- One or more trusted CA certificates for verifying the external syslog server (in PEM encoding). |
| 70 |
- If omitted, the operating system CA certificates will be used. |
| 71 |
type: str |
| 72 |
insecure_TLS: |
| 73 |
description: |
| 74 |
- Flag to permit insecure Transport Layer Security (TLS) for external syslog server connections. |
| 75 |
type: bool |
| 76 |
default: False |
| 77 |
client_cert: |
| 78 |
description: |
| 79 |
- Client certificate for authentication to external syslog server (in PEM encoding). |
| 80 |
type: str |
| 81 |
client_key: |
| 82 |
description: |
| 83 |
- Private key for the client certificate (in PEM encoding). |
| 84 |
- If encrypted, must use traditional format (cannot use PKCS #8 format). |
| 85 |
type: str |
| 86 |
client_key_passphrase: |
| 87 |
description: |
| 88 |
- Passphrase for decrypting the client private key; omit the passphrase if the private key is not encrypted. |
| 89 |
type: str |
| 90 |
tls_configuration_parameters: |
| 91 |
description: |
| 92 |
- OpenSSL configuration commands, only used when C(protocol) is tls. |
| 93 |
type: str |
| 94 |
hostname: |
| 95 |
description: |
| 96 |
- The IP or DNS hostname to send syslog messages to. |
| 97 |
type: str |
| 98 |
required: True |
| 99 |
port: |
| 100 |
description: |
| 101 |
- The port number to send syslog messages to. |
| 102 |
type: int |
| 103 |
default: 514 |
| 104 |
auth_events_send: |
| 105 |
description: |
| 106 |
- If true, send security events to the external syslog server. |
| 107 |
type: bool |
| 108 |
default: True |
| 109 |
auth_events_facility: |
| 110 |
description: |
| 111 |
- Syslog facility to use for security events sent to external syslog server, or -1 to preserve the local facility. |
| 112 |
type: int |
| 113 |
default: -1 |
| 114 |
auth_events_severity: |
| 115 |
description: |
| 116 |
- Syslog severity to use for security events sent to external syslog server, or -1 to preserve the local severity. |
| 117 |
type: int |
| 118 |
default: -1 |
| 119 |
audit_logs_send: |
| 120 |
description: |
| 121 |
- If true, send audit logs to the external syslog server. |
| 122 |
type: bool |
| 123 |
default: True |
| 124 |
audit_logs_facility: |
| 125 |
description: |
| 126 |
- Syslog facility to use for audit logs sent to external syslog server, or -1 to preserve the local facility. |
| 127 |
type: int |
| 128 |
default: 23 |
| 129 |
audit_logs_severity: |
| 130 |
description: |
| 131 |
- Syslog severity to use for audit logs sent to external syslog server, or -1 to preserve the local severity. |
| 132 |
type: int |
| 133 |
default: 6 |
| 134 |
application_logs_send: |
| 135 |
description: |
| 136 |
- If true, send application logs to the external syslog server. |
| 137 |
type: bool |
| 138 |
default: True |
| 139 |
application_logs_facility: |
| 140 |
description: |
| 141 |
- Syslog facility to use for application logs sent to external syslog server, or -1 to preserve the local facility. |
| 142 |
type: int |
| 143 |
default: -1 |
| 144 |
application_logs_severity: |
| 145 |
description: |
| 146 |
- Syslog severity to use for application logs sent to external syslog server, or -1 to preserve the local severity. |
| 147 |
type: int |
| 148 |
default: -1 |
| 149 |
access_logs_send: |
| 150 |
description: |
| 151 |
- If true, send access logs to the external syslog server. |
| 152 |
type: bool |
| 153 |
default: True |
| 154 |
version_added: 21.16.0 |
| 155 |
access_logs_facility: |
| 156 |
description: |
| 157 |
- Syslog facility to use for access logs sent to external syslog server, or -1 to preserve the local facility. |
| 158 |
type: int |
| 159 |
default: -1 |
| 160 |
version_added: 21.16.0 |
| 161 |
access_logs_severity: |
| 162 |
description: |
| 163 |
- Syslog severity to use for access logs sent to external syslog server, or -1 to preserve the local severity. |
| 164 |
type: int |
| 165 |
default: -1 |
| 166 |
version_added: 21.16.0 |
| 167 |
remote_syslog_server_test: |
| 168 |
description: |
| 169 |
- Configuration for sending audit test messages to an external syslog server. |
| 170 |
type: dict |
| 171 |
suboptions: |
| 172 |
enabled: |
| 173 |
description: |
| 174 |
- If true, the external syslog server destination is enabled. |
| 175 |
type: bool |
| 176 |
default: False |
| 177 |
protocol: |
| 178 |
description: |
| 179 |
- The IP protocol to use for sending to the external syslog server. |
| 180 |
choices: ['udp', 'tcp', 'tls', 'relp+tcp', 'relp+tls'] |
| 181 |
default: 'udp' |
| 182 |
type: str |
| 183 |
server_ca_cert: |
| 184 |
description: |
| 185 |
- One or more trusted CA certificates for verifying the external syslog server (in PEM encoding). |
| 186 |
- If omitted, the operating system CA certificates will be used. |
| 187 |
type: str |
| 188 |
insecure_TLS: |
| 189 |
description: |
| 190 |
- Flag to permit insecure Transport Layer Security (TLS) for external syslog server connections. |
| 191 |
type: bool |
| 192 |
default: False |
| 193 |
client_cert: |
| 194 |
description: |
| 195 |
- Client certificate for authentication to external syslog server (in PEM encoding). |
| 196 |
type: str |
| 197 |
client_key: |
| 198 |
description: |
| 199 |
- Private key for the client certificate (in PEM encoding). |
| 200 |
- If encrypted, must use traditional format (cannot use PKCS #8 format). |
| 201 |
type: str |
| 202 |
client_key_passphrase: |
| 203 |
description: |
| 204 |
- Passphrase for decrypting the client private key; omit the passphrase if the private key is not encrypted. |
| 205 |
type: str |
| 206 |
tls_configuration_parameters: |
| 207 |
description: |
| 208 |
- OpenSSL configuration commands, only used when C(protocol) is tls. |
| 209 |
type: str |
| 210 |
hostname: |
| 211 |
description: |
| 212 |
- The IP or DNS hostname to send syslog messages to. |
| 213 |
type: str |
| 214 |
required: True |
| 215 |
port: |
| 216 |
description: |
| 217 |
- The port number to send syslog messages to. |
| 218 |
type: int |
| 219 |
default: 514 |
| 220 |
auth_events_send: |
| 221 |
description: |
| 222 |
- If true, send security events to the external syslog server. |
| 223 |
type: bool |
| 224 |
default: True |
| 225 |
auth_events_facility: |
| 226 |
description: |
| 227 |
- Syslog facility to use for security events sent to external syslog server, or -1 to preserve the local facility. |
| 228 |
type: int |
| 229 |
default: -1 |
| 230 |
auth_events_severity: |
| 231 |
description: |
| 232 |
- Syslog severity to use for security events sent to external syslog server, or -1 to preserve the local severity. |
| 233 |
type: int |
| 234 |
default: -1 |
| 235 |
audit_logs_send: |
| 236 |
description: |
| 237 |
- If true, send audit logs to the external syslog server. |
| 238 |
type: bool |
| 239 |
default: True |
| 240 |
audit_logs_facility: |
| 241 |
description: |
| 242 |
- Syslog facility to use for audit logs sent to external syslog server, or -1 to preserve the local facility. |
| 243 |
type: int |
| 244 |
default: 23 |
| 245 |
audit_logs_severity: |
| 246 |
description: |
| 247 |
- Syslog severity to use for audit logs sent to external syslog server, or -1 to preserve the local severity. |
| 248 |
type: int |
| 249 |
default: 6 |
| 250 |
application_logs_send: |
| 251 |
description: |
| 252 |
- If true, send application logs to the external syslog server. |
| 253 |
type: bool |
| 254 |
default: True |
| 255 |
application_logs_facility: |
| 256 |
description: |
| 257 |
- Syslog facility to use for application logs sent to external syslog server, or -1 to preserve the local facility. |
| 258 |
type: int |
| 259 |
default: -1 |
| 260 |
application_logs_severity: |
| 261 |
description: |
| 262 |
- Syslog severity to use for application logs sent to external syslog server, or -1 to preserve the local severity. |
| 263 |
type: int |
| 264 |
default: -1 |
| 265 |
access_logs_send: |
| 266 |
description: |
| 267 |
- If true, send access logs to the external syslog server. |
| 268 |
type: bool |
| 269 |
default: True |
| 270 |
version_added: 21.16.0 |
| 271 |
access_logs_facility: |
| 272 |
description: |
| 273 |
- Syslog facility to use for access logs sent to external syslog server, or -1 to preserve the local facility. |
| 274 |
type: int |
| 275 |
default: -1 |
| 276 |
version_added: 21.16.0 |
| 277 |
access_logs_severity: |
| 278 |
description: |
| 279 |
- Syslog severity to use for access logs sent to external syslog server, or -1 to preserve the local severity. |
| 280 |
type: int |
| 281 |
default: -1 |
| 282 |
version_added: 21.16.0 |
| 283 |
nodes: |
| 284 |
description: |
| 285 |
- Optional per-node configuration stanzas in the nodes array override the default configuration. |
| 286 |
type: list |
| 287 |
elements: dict |
| 288 |
suboptions: |
| 289 |
node_id: |
| 290 |
description: |
| 291 |
- An optional map of node UUIDs to their audit log destination configurations. |
| 292 |
type: str |
| 293 |
admin_nodes: |
| 294 |
description: |
| 295 |
- Configuration for traditional audit log export to admin nodes. |
| 296 |
type: dict |
| 297 |
suboptions: |
| 298 |
enabled: |
| 299 |
description: |
| 300 |
- If true, traditional audit log export to admin nodes is enabled. |
| 301 |
type: bool |
| 302 |
default: True |
| 303 |
remote_syslog_server: |
| 304 |
description: |
| 305 |
- Configuration for sending audit logs to an external syslog server. |
| 306 |
type: dict |
| 307 |
suboptions: |
| 308 |
enabled: |
| 309 |
description: |
| 310 |
- If true, the external syslog server destination is enabled. |
| 311 |
type: bool |
| 312 |
default: False |
| 313 |
protocol: |
| 314 |
description: |
| 315 |
- The IP protocol to use for sending to the external syslog server. |
| 316 |
choices: ['udp', 'tcp', 'tls', 'relp+tcp', 'relp+tls'] |
| 317 |
default: 'udp' |
| 318 |
type: str |
| 319 |
server_ca_cert: |
| 320 |
description: |
| 321 |
- One or more trusted CA certificates for verifying the external syslog server (in PEM encoding). |
| 322 |
- If omitted, the operating system CA certificates will be used. |
| 323 |
type: str |
| 324 |
insecure_TLS: |
| 325 |
description: |
| 326 |
- Flag to permit insecure Transport Layer Security (TLS) for external syslog server connections. |
| 327 |
type: bool |
| 328 |
default: False |
| 329 |
client_cert: |
| 330 |
description: |
| 331 |
- Client certificate for authentication to external syslog server (in PEM encoding). |
| 332 |
type: str |
| 333 |
client_key: |
| 334 |
description: |
| 335 |
- Private key for the client certificate (in PEM encoding). |
| 336 |
- If encrypted, must use traditional format (cannot use PKCS #8 format). |
| 337 |
type: str |
| 338 |
client_key_passphrase: |
| 339 |
description: |
| 340 |
- Passphrase for decrypting the client private key; omit the passphrase if the private key is not encrypted. |
| 341 |
type: str |
| 342 |
tls_configuration_parameters: |
| 343 |
description: |
| 344 |
- OpenSSL configuration commands, only used when C(protocol) is tls. |
| 345 |
type: str |
| 346 |
hostname: |
| 347 |
description: |
| 348 |
- The IP or DNS hostname to send syslog messages to. |
| 349 |
type: str |
| 350 |
required: True |
| 351 |
port: |
| 352 |
description: |
| 353 |
- The port number to send syslog messages to. |
| 354 |
type: int |
| 355 |
default: 514 |
| 356 |
auth_events_send: |
| 357 |
description: |
| 358 |
- If true, send security events to the external syslog server. |
| 359 |
type: bool |
| 360 |
default: True |
| 361 |
auth_events_facility: |
| 362 |
description: |
| 363 |
- Syslog facility to use for security events sent to external syslog server, or -1 to preserve the local facility. |
| 364 |
type: int |
| 365 |
default: -1 |
| 366 |
auth_events_severity: |
| 367 |
description: |
| 368 |
- Syslog severity to use for security events sent to external syslog server, or -1 to preserve the local severity. |
| 369 |
type: int |
| 370 |
default: -1 |
| 371 |
audit_logs_send: |
| 372 |
description: |
| 373 |
- If true, send audit logs to the external syslog server. |
| 374 |
type: bool |
| 375 |
default: True |
| 376 |
audit_logs_facility: |
| 377 |
description: |
| 378 |
- Syslog facility to use for audit logs sent to external syslog server, or -1 to preserve the local facility. |
| 379 |
type: int |
| 380 |
default: 23 |
| 381 |
audit_logs_severity: |
| 382 |
description: |
| 383 |
- Syslog severity to use for audit logs sent to external syslog server, or -1 to preserve the local severity. |
| 384 |
type: int |
| 385 |
default: 6 |
| 386 |
application_logs_send: |
| 387 |
description: |
| 388 |
- If true, send application logs to the external syslog server. |
| 389 |
type: bool |
| 390 |
default: True |
| 391 |
application_logs_facility: |
| 392 |
description: |
| 393 |
- Syslog facility to use for application logs sent to external syslog server, or -1 to preserve the local facility. |
| 394 |
type: int |
| 395 |
default: -1 |
| 396 |
application_logs_severity: |
| 397 |
description: |
| 398 |
- Syslog severity to use for application logs sent to external syslog server, or -1 to preserve the local severity. |
| 399 |
type: int |
| 400 |
default: -1 |
| 401 |
access_logs_send: |
| 402 |
description: |
| 403 |
- If true, send access logs to the external syslog server. |
| 404 |
type: bool |
| 405 |
default: True |
| 406 |
version_added: 21.16.0 |
| 407 |
access_logs_facility: |
| 408 |
description: |
| 409 |
- Syslog facility to use for access logs sent to external syslog server, or -1 to preserve the local facility. |
| 410 |
type: int |
| 411 |
default: -1 |
| 412 |
version_added: 21.16.0 |
| 413 |
access_logs_severity: |
| 414 |
description: |
| 415 |
- Syslog severity to use for access logs sent to external syslog server, or -1 to preserve the local severity. |
| 416 |
type: int |
| 417 |
default: -1 |
| 418 |
version_added: 21.16.0 |
| 419 |
remote_syslog_server_test: |
| 420 |
description: |
| 421 |
- Configuration for sending audit test messages to an external syslog server. |
| 422 |
type: dict |
| 423 |
suboptions: |
| 424 |
enabled: |
| 425 |
description: |
| 426 |
- If true, the external syslog server destination is enabled. |
| 427 |
type: bool |
| 428 |
default: False |
| 429 |
protocol: |
| 430 |
description: |
| 431 |
- The IP protocol to use for sending to the external syslog server. |
| 432 |
choices: ['udp', 'tcp', 'tls', 'relp+tcp', 'relp+tls'] |
| 433 |
default: 'udp' |
| 434 |
type: str |
| 435 |
server_ca_cert: |
| 436 |
description: |
| 437 |
- One or more trusted CA certificates for verifying the external syslog server (in PEM encoding). |
| 438 |
- If omitted, the operating system CA certificates will be used. |
| 439 |
type: str |
| 440 |
insecure_TLS: |
| 441 |
description: |
| 442 |
- Flag to permit insecure Transport Layer Security (TLS) for external syslog server connections. |
| 443 |
type: bool |
| 444 |
default: False |
| 445 |
client_cert: |
| 446 |
description: |
| 447 |
- Client certificate for authentication to external syslog server (in PEM encoding). |
| 448 |
type: str |
| 449 |
client_key: |
| 450 |
description: |
| 451 |
- Private key for the client certificate (in PEM encoding). |
| 452 |
- If encrypted, must use traditional format (cannot use PKCS #8 format). |
| 453 |
type: str |
| 454 |
client_key_passphrase: |
| 455 |
description: |
| 456 |
- Passphrase for decrypting the client private key; omit the passphrase if the private key is not encrypted. |
| 457 |
type: str |
| 458 |
tls_configuration_parameters: |
| 459 |
description: |
| 460 |
- OpenSSL configuration commands, only used when C(protocol) is tls. |
| 461 |
type: str |
| 462 |
hostname: |
| 463 |
description: |
| 464 |
- The IP or DNS hostname to send syslog messages to. |
| 465 |
type: str |
| 466 |
required: True |
| 467 |
port: |
| 468 |
description: |
| 469 |
- The port number to send syslog messages to. |
| 470 |
type: int |
| 471 |
default: 514 |
| 472 |
auth_events_send: |
| 473 |
description: |
| 474 |
- If true, send security events to the external syslog server. |
| 475 |
type: bool |
| 476 |
default: True |
| 477 |
auth_events_facility: |
| 478 |
description: |
| 479 |
- Syslog facility to use for security events sent to external syslog server, or -1 to preserve the local facility. |
| 480 |
type: int |
| 481 |
default: -1 |
| 482 |
auth_events_severity: |
| 483 |
description: |
| 484 |
- Syslog severity to use for security events sent to external syslog server, or -1 to preserve the local severity. |
| 485 |
type: int |
| 486 |
default: -1 |
| 487 |
audit_logs_send: |
| 488 |
description: |
| 489 |
- If true, send audit logs to the external syslog server. |
| 490 |
type: bool |
| 491 |
default: True |
| 492 |
audit_logs_facility: |
| 493 |
description: |
| 494 |
- Syslog facility to use for audit logs sent to external syslog server, or -1 to preserve the local facility. |
| 495 |
type: int |
| 496 |
default: 23 |
| 497 |
audit_logs_severity: |
| 498 |
description: |
| 499 |
- Syslog severity to use for audit logs sent to external syslog server, or -1 to preserve the local severity. |
| 500 |
type: int |
| 501 |
default: 6 |
| 502 |
application_logs_send: |
| 503 |
description: |
| 504 |
- If true, send application logs to the external syslog server. |
| 505 |
type: bool |
| 506 |
default: True |
| 507 |
application_logs_facility: |
| 508 |
description: |
| 509 |
- Syslog facility to use for application logs sent to external syslog server, or -1 to preserve the local facility. |
| 510 |
type: int |
| 511 |
default: -1 |
| 512 |
application_logs_severity: |
| 513 |
description: |
| 514 |
- Syslog severity to use for application logs sent to external syslog server, or -1 to preserve the local severity. |
| 515 |
type: int |
| 516 |
default: -1 |
| 517 |
access_logs_send: |
| 518 |
description: |
| 519 |
- If true, send access logs to the external syslog server. |
| 520 |
type: bool |
| 521 |
default: True |
| 522 |
version_added: 21.16.0 |
| 523 |
access_logs_facility: |
| 524 |
description: |
| 525 |
- Syslog facility to use for access logs sent to external syslog server, or -1 to preserve the local facility. |
| 526 |
type: int |
| 527 |
default: -1 |
| 528 |
version_added: 21.16.0 |
| 529 |
access_logs_severity: |
| 530 |
description: |
| 531 |
- Syslog severity to use for access logs sent to external syslog server, or -1 to preserve the local severity. |
| 532 |
type: int |
| 533 |
default: -1 |
| 534 |
version_added: 21.16.0 |
| 535 |
""" |
| 536 |
|
| 537 |
EXAMPLES = """ |
| 538 |
- name: Configure audit destination defaults |
| 539 |
netapp.storagegrid.na_sg_grid_audit_destination: |
| 540 |
state: present |
| 541 |
api_url: "https://gmi.example.com" |
| 542 |
auth_token: "01234567-5678-9abc-78de-9fgabc123def" |
| 543 |
validate_certs: false |
| 544 |
defaults: |
| 545 |
admin_nodes: |
| 546 |
enabled: true |
| 547 |
remote_syslog_server: |
| 548 |
enabled: true |
| 549 |
protocol: udp |
| 550 |
hostname: "syslog.example.com" |
| 551 |
port: 514 |
| 552 |
auth_events_send: true |
| 553 |
auth_events_facility: -1 |
| 554 |
auth_events_severity: -1 |
| 555 |
audit_logs_send: true |
| 556 |
audit_logs_facility: 23 |
| 557 |
audit_logs_severity: 6 |
| 558 |
application_logs_send: true |
| 559 |
application_logs_facility: -1 |
| 560 |
application_logs_severity: -1 |
| 561 |
access_logs_send: true |
| 562 |
access_logs_facility: -1 |
| 563 |
access_logs_severity: -1 |
| 564 |
|
| 565 |
- name: Configure audit destination for specific nodes |
| 566 |
netapp.storagegrid.na_sg_grid_audit_destination: |
| 567 |
state: present |
| 568 |
api_url: "https://gmi.example.com" |
| 569 |
auth_token: "01234567-5678-9abc-78de-9fgabc123def" |
| 570 |
validate_certs: false |
| 571 |
nodes: |
| 572 |
- node_id: "6562d5d8-f218-45ff-a466-5bb39e729288" |
| 573 |
admin_nodes: |
| 574 |
enabled: true |
| 575 |
remote_syslog_server: |
| 576 |
enabled: true |
| 577 |
protocol: udp |
| 578 |
hostname: "syslog.example.com" |
| 579 |
port: 514 |
| 580 |
auth_events_send: true |
| 581 |
auth_events_facility: -1 |
| 582 |
auth_events_severity: -1 |
| 583 |
audit_logs_send: true |
| 584 |
audit_logs_facility: 23 |
| 585 |
audit_logs_severity: 6 |
| 586 |
application_logs_send: true |
| 587 |
application_logs_facility: -1 |
| 588 |
application_logs_severity: -1 |
| 589 |
access_logs_send: true |
| 590 |
access_logs_facility: -1 |
| 591 |
access_logs_severity: -1 |
| 592 |
""" |
| 593 |
|
| 594 |
RETURN = """ |
| 595 |
resp: |
| 596 |
description: Returns information about the StorageGRID Audit destination. |
| 597 |
returned: If state is 'present'. |
| 598 |
type: dict |
| 599 |
sample: { |
| 600 |
"defaults": { |
| 601 |
"adminNodes": { |
| 602 |
"enabled": true |
| 603 |
}, |
| 604 |
"remoteSyslogServerA": { |
| 605 |
"enabled": true, |
| 606 |
"protocol": "tls", |
| 607 |
"serverCaCert": "<CA bundle in PEM-encoding>", |
| 608 |
"insecureTLS": false, |
| 609 |
"clientCert": "<Client certificate in PEM-encoding>", |
| 610 |
"clientKey": "<Client private key in PEM-encoding>", |
| 611 |
"clientKeyPassphrase": "<Client private key passphrase>", |
| 612 |
"tlsConfigurationParameters": "<OpenSSL configuration commands>", |
| 613 |
"hostname": "syslog.example.com", |
| 614 |
"port": 514, |
| 615 |
"authEventsSend": true, |
| 616 |
"authEventsFacility": -1, |
| 617 |
"authEventsSeverity": -1, |
| 618 |
"auditLogsSend": true, |
| 619 |
"auditLogsFacility": 23, |
| 620 |
"auditLogsSeverity": 6, |
| 621 |
"applicationLogsSend": true, |
| 622 |
"applicationLogsFacility": -1, |
| 623 |
"applicationLogsSeverity": -1, |
| 624 |
"accessLogsSend": true, |
| 625 |
"accessLogsFacility": -1, |
| 626 |
"accessLogsSeverity": -1 |
| 627 |
}, |
| 628 |
"remoteSyslogServerATest": { |
| 629 |
"enabled": true, |
| 630 |
"protocol": "tls", |
| 631 |
"serverCaCert": "<CA bundle in PEM-encoding>", |
| 632 |
"insecureTLS": false, |
| 633 |
"clientCert": "<Client certificate in PEM-encoding>", |
| 634 |
"clientKey": "<Client private key in PEM-encoding>", |
| 635 |
"clientKeyPassphrase": "<Client private key passphrase>", |
| 636 |
"tlsConfigurationParameters": "<OpenSSL configuration commands>", |
| 637 |
"hostname": "syslog.example.com", |
| 638 |
"port": 514, |
| 639 |
"authEventsSend": true, |
| 640 |
"authEventsFacility": -1, |
| 641 |
"authEventsSeverity": -1, |
| 642 |
"auditLogsSend": true, |
| 643 |
"auditLogsFacility": 23, |
| 644 |
"auditLogsSeverity": 6, |
| 645 |
"applicationLogsSend": true, |
| 646 |
"applicationLogsFacility": -1, |
| 647 |
"applicationLogsSeverity": -1, |
| 648 |
"accessLogsSend": true, |
| 649 |
"accessLogsFacility": -1, |
| 650 |
"accessLogsSeverity": -1 |
| 651 |
} |
| 652 |
}, |
| 653 |
"nodes": { |
| 654 |
"6562d5d8-f218-45ff-a466-5bb39e729288": { |
| 655 |
"adminNodes": { |
| 656 |
"enabled": true |
| 657 |
}, |
| 658 |
"remoteSyslogServerA": { |
| 659 |
"enabled": true, |
| 660 |
"protocol": "tls", |
| 661 |
"serverCaCert": "<CA bundle in PEM-encoding>", |
| 662 |
"insecureTLS": false, |
| 663 |
"clientCert": "<Client certificate in PEM-encoding>", |
| 664 |
"clientKey": "<Client private key in PEM-encoding>", |
| 665 |
"clientKeyPassphrase": "<Client private key passphrase>", |
| 666 |
"tlsConfigurationParameters": "<OpenSSL configuration commands>", |
| 667 |
"hostname": "syslog.example.com", |
| 668 |
"port": 514, |
| 669 |
"authEventsSend": true, |
| 670 |
"authEventsFacility": -1, |
| 671 |
"authEventsSeverity": -1, |
| 672 |
"auditLogsSend": true, |
| 673 |
"auditLogsFacility": 23, |
| 674 |
"auditLogsSeverity": 6, |
| 675 |
"applicationLogsSend": true, |
| 676 |
"applicationLogsFacility": -1, |
| 677 |
"applicationLogsSeverity": -1, |
| 678 |
"accessLogsSend": true, |
| 679 |
"accessLogsFacility": -1, |
| 680 |
"accessLogsSeverity": -1 |
| 681 |
}, |
| 682 |
"remoteSyslogServerATest": { |
| 683 |
"enabled": true, |
| 684 |
"protocol": "tls", |
| 685 |
"serverCaCert": "<CA bundle in PEM-encoding>", |
| 686 |
"insecureTLS": false, |
| 687 |
"clientCert": "<Client certificate in PEM-encoding>", |
| 688 |
"clientKey": "<Client private key in PEM-encoding>", |
| 689 |
"clientKeyPassphrase": "<Client private key passphrase>", |
| 690 |
"tlsConfigurationParameters": "<OpenSSL configuration commands>", |
| 691 |
"hostname": "syslog.example.com", |
| 692 |
"port": 514, |
| 693 |
"authEventsSend": true, |
| 694 |
"authEventsFacility": -1, |
| 695 |
"authEventsSeverity": -1, |
| 696 |
"auditLogsSend": true, |
| 697 |
"auditLogsFacility": 23, |
| 698 |
"auditLogsSeverity": 6, |
| 699 |
"applicationLogsSend": true, |
| 700 |
"applicationLogsFacility": -1, |
| 701 |
"applicationLogsSeverity": -1, |
| 702 |
"accessLogsSend": true, |
| 703 |
"accessLogsFacility": -1, |
| 704 |
"accessLogsSeverity": -1 |
| 705 |
} |
| 706 |
} |
| 707 |
} |
| 708 |
} |
| 709 |
""" |
| 710 |
|
| 711 |
import ansible_collections.netapp.storagegrid.plugins.module_utils.netapp as netapp_utils |
| 712 |
from ansible.module_utils.basic import AnsibleModule |
| 713 |
from ansible_collections.netapp.storagegrid.plugins.module_utils.netapp_module import NetAppModule |
| 714 |
from ansible_collections.netapp.storagegrid.plugins.module_utils.netapp import SGRestAPI |
| 715 |
from ansible_collections.netapp.storagegrid.plugins.module_utils.tools import first_inside_second_dict_or_list |
| 716 |
|
| 717 |
|
| 718 |
class SgAuditDestination: |
| 719 |
""" |
| 720 |
Configure audit destination on NetApp StorageGRID |
| 721 |
""" |
| 722 |
|
| 723 |
def __init__(self): |
| 724 |
""" |
| 725 |
Parse arguments, setup state variables, |
| 726 |
check parameters and ensure request module is installed |
| 727 |
""" |
| 728 |
self.argument_spec = netapp_utils.na_storagegrid_host_argument_spec() |
| 729 |
self.argument_spec.update( |
| 730 |
dict( |
| 731 |
state=dict(type="str", choices=["present"], default="present"), |
| 732 |
defaults=dict( |
| 733 |
required=False, |
| 734 |
type="dict", |
| 735 |
options=dict( |
| 736 |
admin_nodes=dict( |
| 737 |
required=False, |
| 738 |
type="dict", |
| 739 |
options=dict( |
| 740 |
enabled=dict(type="bool", default=True), |
| 741 |
) |
| 742 |
), |
| 743 |
remote_syslog_server=dict( |
| 744 |
required=False, |
| 745 |
type="dict", |
| 746 |
options=dict( |
| 747 |
enabled=dict(type="bool", default=False), |
| 748 |
protocol=dict(type="str", choices=["udp", "tcp", "tls", "relp+tcp", "relp+tls"], default="udp"), |
| 749 |
server_ca_cert=dict(type="str"), |
| 750 |
insecure_TLS=dict(type="bool", default=False), |
| 751 |
client_cert=dict(type="str"), |
| 752 |
client_key=dict(type="str", no_log=True), |
| 753 |
client_key_passphrase=dict(type="str", no_log=True), |
| 754 |
tls_configuration_parameters=dict(type="str"), |
| 755 |
hostname=dict(type="str", required=True), |
| 756 |
port=dict(type="int", default=514), |
| 757 |
auth_events_send=dict(type="bool", default=True), |
| 758 |
auth_events_facility=dict(type="int", default=-1), |
| 759 |
auth_events_severity=dict(type="int", default=-1), |
| 760 |
audit_logs_send=dict(type="bool", default=True), |
| 761 |
audit_logs_facility=dict(type="int", default=23), |
| 762 |
audit_logs_severity=dict(type="int", default=6), |
| 763 |
application_logs_send=dict(type="bool", default=True), |
| 764 |
application_logs_facility=dict(type="int", default=-1), |
| 765 |
application_logs_severity=dict(type="int", default=-1), |
| 766 |
access_logs_send=dict(type="bool", default=True), |
| 767 |
access_logs_facility=dict(type="int", default=-1), |
| 768 |
access_logs_severity=dict(type="int", default=-1), |
| 769 |
), |
| 770 |
), |
| 771 |
remote_syslog_server_test=dict( |
| 772 |
required=False, |
| 773 |
type="dict", |
| 774 |
options=dict( |
| 775 |
enabled=dict(type="bool", default=False), |
| 776 |
protocol=dict(type="str", choices=["udp", "tcp", "tls", "relp+tcp", "relp+tls"], default="udp"), |
| 777 |
server_ca_cert=dict(type="str"), |
| 778 |
insecure_TLS=dict(type="bool", default=False), |
| 779 |
client_cert=dict(type="str"), |
| 780 |
client_key=dict(type="str", no_log=True), |
| 781 |
client_key_passphrase=dict(type="str", no_log=True), |
| 782 |
tls_configuration_parameters=dict(type="str"), |
| 783 |
hostname=dict(type="str", required=True), |
| 784 |
port=dict(type="int", default=514), |
| 785 |
auth_events_send=dict(type="bool", default=True), |
| 786 |
auth_events_facility=dict(type="int", default=-1), |
| 787 |
auth_events_severity=dict(type="int", default=-1), |
| 788 |
audit_logs_send=dict(type="bool", default=True), |
| 789 |
audit_logs_facility=dict(type="int", default=23), |
| 790 |
audit_logs_severity=dict(type="int", default=6), |
| 791 |
application_logs_send=dict(type="bool", default=True), |
| 792 |
application_logs_facility=dict(type="int", default=-1), |
| 793 |
application_logs_severity=dict(type="int", default=-1), |
| 794 |
access_logs_send=dict(type="bool", default=True), |
| 795 |
access_logs_facility=dict(type="int", default=-1), |
| 796 |
access_logs_severity=dict(type="int", default=-1), |
| 797 |
), |
| 798 |
), |
| 799 |
), |
| 800 |
), |
| 801 |
nodes=dict( |
| 802 |
required=False, |
| 803 |
type="list", |
| 804 |
elements="dict", |
| 805 |
options=dict( |
| 806 |
node_id=dict(type="str", required=False), |
| 807 |
admin_nodes=dict( |
| 808 |
required=False, |
| 809 |
type="dict", |
| 810 |
options=dict( |
| 811 |
enabled=dict(type="bool", default=True), |
| 812 |
) |
| 813 |
), |
| 814 |
remote_syslog_server=dict( |
| 815 |
required=False, |
| 816 |
type="dict", |
| 817 |
options=dict( |
| 818 |
enabled=dict(type="bool", default=False), |
| 819 |
protocol=dict(type="str", choices=["udp", "tcp", "tls", "relp+tcp", "relp+tls"], default="udp"), |
| 820 |
server_ca_cert=dict(type="str"), |
| 821 |
insecure_TLS=dict(type="bool", default=False), |
| 822 |
client_cert=dict(type="str"), |
| 823 |
client_key=dict(type="str", no_log=True), |
| 824 |
client_key_passphrase=dict(type="str", no_log=True), |
| 825 |
tls_configuration_parameters=dict(type="str"), |
| 826 |
hostname=dict(type="str", required=True), |
| 827 |
port=dict(type="int", default=514), |
| 828 |
auth_events_send=dict(type="bool", default=True), |
| 829 |
auth_events_facility=dict(type="int", default=-1), |
| 830 |
auth_events_severity=dict(type="int", default=-1), |
| 831 |
audit_logs_send=dict(type="bool", default=True), |
| 832 |
audit_logs_facility=dict(type="int", default=23), |
| 833 |
audit_logs_severity=dict(type="int", default=6), |
| 834 |
application_logs_send=dict(type="bool", default=True), |
| 835 |
application_logs_facility=dict(type="int", default=-1), |
| 836 |
application_logs_severity=dict(type="int", default=-1), |
| 837 |
access_logs_send=dict(type="bool", default=True), |
| 838 |
access_logs_facility=dict(type="int", default=-1), |
| 839 |
access_logs_severity=dict(type="int", default=-1), |
| 840 |
), |
| 841 |
), |
| 842 |
remote_syslog_server_test=dict( |
| 843 |
required=False, |
| 844 |
type="dict", |
| 845 |
options=dict( |
| 846 |
enabled=dict(type="bool", default=False), |
| 847 |
protocol=dict(type="str", choices=["udp", "tcp", "tls", "relp+tcp", "relp+tls"], default="udp"), |
| 848 |
server_ca_cert=dict(type="str"), |
| 849 |
insecure_TLS=dict(type="bool", default=False), |
| 850 |
client_cert=dict(type="str"), |
| 851 |
client_key=dict(type="str", no_log=True), |
| 852 |
client_key_passphrase=dict(type="str", no_log=True), |
| 853 |
tls_configuration_parameters=dict(type="str"), |
| 854 |
hostname=dict(type="str", required=True), |
| 855 |
port=dict(type="int", default=514), |
| 856 |
auth_events_send=dict(type="bool", default=True), |
| 857 |
auth_events_facility=dict(type="int", default=-1), |
| 858 |
auth_events_severity=dict(type="int", default=-1), |
| 859 |
audit_logs_send=dict(type="bool", default=True), |
| 860 |
audit_logs_facility=dict(type="int", default=23), |
| 861 |
audit_logs_severity=dict(type="int", default=6), |
| 862 |
application_logs_send=dict(type="bool", default=True), |
| 863 |
application_logs_facility=dict(type="int", default=-1), |
| 864 |
application_logs_severity=dict(type="int", default=-1), |
| 865 |
access_logs_send=dict(type="bool", default=True), |
| 866 |
access_logs_facility=dict(type="int", default=-1), |
| 867 |
access_logs_severity=dict(type="int", default=-1), |
| 868 |
), |
| 869 |
), |
| 870 |
), |
| 871 |
), |
| 872 |
), |
| 873 |
) |
| 874 |
|
| 875 |
self.module = AnsibleModule( |
| 876 |
argument_spec=self.argument_spec, |
| 877 |
required_one_of=[["defaults", "nodes"]], |
| 878 |
supports_check_mode=True |
| 879 |
) |
| 880 |
self.na_helper = NetAppModule() |
| 881 |
|
| 882 |
# set up state variables |
| 883 |
self.parameters = self.na_helper.set_parameters(self.module.params) |
| 884 |
# Calling generic SG rest_api class |
| 885 |
self.rest_api = SGRestAPI(self.module) |
| 886 |
# Get API version |
| 887 |
self.rest_api.get_sg_product_version() |
| 888 |
self.api_version = self.rest_api.get_api_version() |
| 889 |
|
| 890 |
# Checking for the parameters passed and create new parameters list |
| 891 |
self.data = {} |
| 892 |
|
| 893 |
if self.parameters.get("defaults"): |
| 894 |
self.data["defaults"] = {} |
| 895 |
if self.parameters["defaults"].get("admin_nodes"): |
| 896 |
self.data["defaults"]["adminNodes"] = { |
| 897 |
"enabled": self.parameters["defaults"]["admin_nodes"].get("enabled") |
| 898 |
} |
| 899 |
if self.parameters["defaults"].get("remote_syslog_server"): |
| 900 |
self.data["defaults"]["remoteSyslogServerA"] = self.external_syslog_server_params(self.parameters["defaults"]["remote_syslog_server"]) |
| 901 |
if self.parameters["defaults"].get("remote_syslog_server_test"): |
| 902 |
self.data["defaults"]["remoteSyslogServerATest"] = self.external_syslog_server_params(self.parameters["defaults"]["remote_syslog_server_test"]) |
| 903 |
|
| 904 |
if self.parameters.get("nodes"): |
| 905 |
self.data["nodes"] = {} |
| 906 |
for node in self.parameters["nodes"]: |
| 907 |
node_id = node.get("node_id") |
| 908 |
if node_id: |
| 909 |
self.data["nodes"][node_id] = {} |
| 910 |
if node.get("admin_nodes"): |
| 911 |
self.data["nodes"][node_id]["adminNodes"] = { |
| 912 |
"enabled": node["admin_nodes"].get("enabled") |
| 913 |
} |
| 914 |
if node.get("remote_syslog_server"): |
| 915 |
self.data["nodes"][node_id]["remoteSyslogServerA"] = self.external_syslog_server_params(node["remote_syslog_server"]) |
| 916 |
if node.get("remote_syslog_server_test"): |
| 917 |
self.data["nodes"][node_id]["remoteSyslogServerATest"] = self.external_syslog_server_params(node["remote_syslog_server_test"]) |
| 918 |
|
| 919 |
def external_syslog_server_params(self, params): |
| 920 |
""" Get external syslog server parameters """ |
| 921 |
return { |
| 922 |
"enabled": params.get("enabled", False), |
| 923 |
"protocol": params.get("protocol", "udp"), |
| 924 |
"serverCaCert": params.get("server_ca_cert"), |
| 925 |
"insecureTLS": params.get("insecure_TLS", False), |
| 926 |
"clientCert": params.get("client_cert"), |
| 927 |
"clientKey": params.get("client_key"), |
| 928 |
"clientKeyPassphrase": params.get("client_key_passphrase"), |
| 929 |
"tlsConfigurationParameters": params.get("tls_configuration_parameters"), |
| 930 |
"hostname": params.get("hostname"), |
| 931 |
"port": params.get("port", 514), |
| 932 |
"authEventsSend": params.get("auth_events_send", True), |
| 933 |
"authEventsFacility": params.get("auth_events_facility", -1), |
| 934 |
"authEventsSeverity": params.get("auth_events_severity", -1), |
| 935 |
"auditLogsSend": params.get("audit_logs_send", True), |
| 936 |
"auditLogsFacility": params.get("audit_logs_facility", 23), |
| 937 |
"auditLogsSeverity": params.get("audit_logs_severity", 6), |
| 938 |
"applicationLogsSend": params.get("application_logs_send", True), |
| 939 |
"applicationLogsFacility": params.get("application_logs_facility", -1), |
| 940 |
"applicationLogsSeverity": params.get("application_logs_severity", -1), |
| 941 |
"accessLogsSend": params.get("access_logs_send", True), |
| 942 |
"accessLogsFacility": params.get("access_logs_facility", -1), |
| 943 |
"accessLogsSeverity": params.get("access_logs_severity", -1), |
| 944 |
} |
| 945 |
|
| 946 |
def get_audit_log_destination_config(self): |
| 947 |
""" Get current audit log destination configuration """ |
| 948 |
api = "api/%s/private/audit-destinations" % self.api_version |
| 949 |
response, error = self.rest_api.get(api) |
| 950 |
|
| 951 |
if error: |
| 952 |
self.module.fail_json(msg=error) |
| 953 |
else: |
| 954 |
return response["data"] |
| 955 |
|
| 956 |
def update_audit_log_destination_config(self): |
| 957 |
""" Update audit log destination configuration """ |
| 958 |
api = "api/%s/private/audit-destinations" % self.api_version |
| 959 |
response, error = self.rest_api.put(api, self.data) |
| 960 |
|
| 961 |
if error: |
| 962 |
self.module.fail_json(msg=error) |
| 963 |
else: |
| 964 |
return response["data"] |
| 965 |
|
| 966 |
def apply(self): |
| 967 |
''' Apply audit destination configuration ''' |
| 968 |
|
| 969 |
current_audit_destination = self.get_audit_log_destination_config() |
| 970 |
|
| 971 |
if self.parameters["state"] == "present": |
| 972 |
# let's see if we need to update parameters |
| 973 |
if self.data.get("defaults") and not first_inside_second_dict_or_list(self.data.get("defaults"), current_audit_destination.get("defaults")): |
| 974 |
self.na_helper.changed = True |
| 975 |
if self.data.get("nodes") and not first_inside_second_dict_or_list(self.data.get("nodes"), current_audit_destination.get("nodes")): |
| 976 |
self.na_helper.changed = True |
| 977 |
|
| 978 |
result_message = "" |
| 979 |
resp_data = current_audit_destination |
| 980 |
if self.na_helper.changed: |
| 981 |
if self.module.check_mode: |
| 982 |
pass |
| 983 |
else: |
| 984 |
resp_data = self.update_audit_log_destination_config() |
| 985 |
result_message = "Audit destination configuration updated successfully." |
| 986 |
|
| 987 |
self.module.exit_json(changed=self.na_helper.changed, msg=result_message, resp=resp_data) |
| 988 |
|
| 989 |
|
| 990 |
def main(): |
| 991 |
""" |
| 992 |
Main function |
| 993 |
""" |
| 994 |
na_sg_grid_audit_destination = SgAuditDestination() |
| 995 |
na_sg_grid_audit_destination.apply() |
| 996 |
|
| 997 |
|
| 998 |
if __name__ == "__main__": |
| 999 |
main() |