Debian Codegraph @

ansible_collections/dellemc/enterprise_sonic/plugins/modules/sonic_aaa.py

raw symbols SCIP
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3 # Copyright 2025 Dell Inc. or its subsidiaries. All Rights Reserved.
4 # GNU General Public License v3.0+
5 # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 """
8 The module file for sonic_aaa
9 """
10
11 from __future__ import absolute_import, division, print_function
12 __metaclass__ = type
13
14
15 DOCUMENTATION = """
16 ---
17 module: sonic_aaa
18 version_added: 1.1.0
19 notes:
20 - Tested against Enterprise SONiC Distribution by Dell Technologies
21 - Supports C(check_mode)
22 author: S. Talabi (@stalabi1)
23 short_description: Manage AAA configuration on SONiC
24 description:
25 - This module provides configuration management of AAA for devices running SONiC.
26 options:
27 config:
28 description:
29 - AAA configuration
30 - For all lists in the module, the list items should be specified in order of desired priority.
31 - List items specified first have the highest priority.
32 type: dict
33 suboptions:
34 authentication:
35 description:
36 - AAA authentication configuration
37 type: dict
38 version_added: 3.0.0
39 suboptions:
40 auth_method:
41 description:
42 - Specifies the order of the methods in which to authenticate login
43 - Any 1 choice may be specified or 2 choices consisting of local and another group may be specified
44 - C(cac-piv) option is only available in devices running sonic 4.5.0 and above.
45 - MFA is not applicable when C(cac-piv) is configured as first factor for authentication.
46 type: list
47 elements: str
48 choices: ['ldap', 'local', 'radius', 'tacacs+', 'cac-piv']
49 console_auth_local :
50 description:
51 Enable/disable local authentication on console
52 type: bool
53 failthrough:
54 description:
55 - Enable/disable failthrough
56 type: bool
57 mfa_auth_method:
58 version_added: 3.1.0
59 description:
60 - Specifies RSA SecurID as multi-factor authentication method.
61 type: str
62 choices: ['rsa-securid']
63 login_mfa_console:
64 version_added: 3.1.0
65 description:
66 - Enable/disable MFA method for console access.
67 type: bool
68 authorization:
69 description:
70 - AAA authorization configuration
71 type: dict
72 version_added: 3.0.0
73 suboptions:
74 commands_auth_method:
75 description:
76 - Specifies the order of the methods in which to authorize commands
77 type: list
78 elements: str
79 choices: ['local', 'tacacs+']
80 login_auth_method:
81 description:
82 - Specifies the order of the methods in which to authorize login
83 type: list
84 elements: str
85 choices: ['ldap', 'local']
86 accounting:
87 description:
88 - AAA accounting configuration.
89 type: dict
90 version_added: 4.0.0
91 suboptions:
92 commands_accounting:
93 description:
94 - AAA commands accounting configuration.
95 type: dict
96 suboptions:
97 accounting_method:
98 description:
99 - Specifies the methods in which to perform accounting.
100 type: list
101 elements: str
102 choices: ['tacacs+', 'logging']
103 accounting_record_type:
104 description:
105 - Specifies the type of record to be sent to the accounting server.
106 type: str
107 choices:
108 - start-stop
109 - stop-only
110 accounting_console_exempt:
111 description:
112 - Exempt accounting of events from console.
113 type: bool
114 session_accounting:
115 description:
116 - AAA session accounting configuration.
117 type: dict
118 suboptions:
119 accounting_method:
120 description:
121 - Specifies the methods in which to perform accounting.
122 type: list
123 elements: str
124 choices: ['tacacs+', 'logging']
125 accounting_record_type:
126 description:
127 - Specifies the type of record to be sent to the accounting server.
128 type: str
129 choices:
130 - start-stop
131 - stop-only
132 accounting_console_exempt:
133 description:
134 - Exempt accounting of events from console.
135 type: bool
136 name_service:
137 description:
138 - AAA name-service configuration
139 type: dict
140 version_added: 3.0.0
141 suboptions:
142 group:
143 description:
144 - Name-service source for group method
145 type: list
146 elements: str
147 choices: ['ldap', 'local', 'login']
148 netgroup:
149 description:
150 - Name-service source for netgroup method
151 type: list
152 elements: str
153 choices: ['ldap', 'local']
154 passwd:
155 description:
156 - Name-service source for passwd method
157 type: list
158 elements: str
159 choices: ['ldap', 'local', 'login']
160 shadow:
161 description:
162 - Name-service source for shadow method
163 type: list
164 elements: str
165 choices: ['ldap', 'local', 'login']
166 sudoers:
167 description:
168 - Name-service source for sudoers method
169 type: list
170 elements: str
171 choices: ['ldap', 'local']
172 state:
173 description:
174 - The state of the configuration after module completion
175 choices: ['merged', 'deleted', 'overridden', 'replaced']
176 default: merged
177 type: str
178 """
179
180 EXAMPLES = """
181 # Using "merged" state
182 #
183 # Before state:
184 # -------------
185 #
186 # sonic# show aaa
187 # (No AAA configuration present)
188 #
189 # sonic# show mfa
190 # ---------------------------------------------------------
191 # Multi-factor Authentication Information
192 # ---------------------------------------------------------
193 # MFA Authentication : None
194 # Console Exempted : None
195 # MFA Service Security Profile : None
196 # RSA SecurID Security Profile : None
197
198 - name: Merge AAA configuration
199 dellemc.enterprise_sonic.sonic_aaa:
200 config:
201 authentication:
202 auth_method:
203 - local
204 - ldap
205 console_auth_local: true
206 failthrough: true
207 mfa_auth_method: 'rsa-securid'
208 login_mfa_console: true
209 authorization:
210 commands_auth_method:
211 - local
212 - tacacs+
213 login_auth_method:
214 - local
215 - ldap
216 accounting:
217 commands_accounting:
218 accounting_method:
219 - tacacs+
220 - logging
221 accounting_record_type: 'start-stop'
222 accounting_console_exempt: true
223 session_accounting:
224 accounting_method:
225 - logging
226 accounting_record_type: 'stop-only'
227 accounting_console_exempt: true
228 name_service:
229 group:
230 - ldap
231 netgroup:
232 - local
233 passwd:
234 - login
235 shadow:
236 - ldap
237 sudoers:
238 - local
239 state: merged
240
241 # After state:
242 # ------------
243 #
244 # sonic# show aaa
245 # ---------------------------------------------------------
246 # AAA Authentication Information
247 # ---------------------------------------------------------
248 # failthrough : True
249 # login-method : local, ldap
250 # login-mfa : rsa-securid
251 # console authentication : local
252 # ---------------------------------------------------------
253 # AAA Authorization Information
254 # ---------------------------------------------------------
255 # login : local, ldap
256 # commands : local, tacacs+
257 # ---------------------------------------------------------
258 # AAA Accounting Information
259 # ---------------------------------------------------------
260 # commands : tacacs+, logging (start-stop, console-disabled)
261 # session : logging (stop-only, console-disabled)
262 # ---------------------------------------------------------
263 # AAA Name-Service Information
264 # ---------------------------------------------------------
265 # group-method : ldap
266 # netgroup-method : local
267 # passwd-method : login
268 # shadow-method : ldap
269 # sudoers-method : local
270 #
271 # sonic# show mfa
272 # ---------------------------------------------------------
273 # Multi-factor Authentication Information
274 # ---------------------------------------------------------
275 # MFA Authentication : rsa-securid
276 # Console Exempted : No
277 # MFA Service Security Profile : None
278 # RSA SecurID Security Profile : None
279
280
281 # Using "replaced" state
282 #
283 # Before state:
284 # -------------
285 #
286 # sonic# show aaa
287 # ---------------------------------------------------------
288 # AAA Authentication Information
289 # ---------------------------------------------------------
290 # failthrough : True
291 # login-method : local, ldap
292 # login-mfa : rsa-securid
293 # console authentication : local
294 # ---------------------------------------------------------
295 # AAA Authorization Information
296 # ---------------------------------------------------------
297 # login : local, ldap
298 # commands : local, tacacs+
299 # ---------------------------------------------------------
300 # AAA Accounting Information
301 # ---------------------------------------------------------
302 # commands : tacacs+, logging (start-stop, console-disabled)
303 # session : logging (stop-only, console-disabled)
304 # ---------------------------------------------------------
305 # AAA Name-Service Information
306 # ---------------------------------------------------------
307 # group-method : ldap
308 # netgroup-method : local
309 # passwd-method : login
310 # shadow-method : ldap
311 # sudoers-method : local
312 #
313 # sonic# show mfa
314 # ---------------------------------------------------------
315 # Multi-factor Authentication Information
316 # ---------------------------------------------------------
317 # MFA Authentication : rsa-securid
318 # Console Exempted : No
319 # MFA Service Security Profile : None
320 # RSA SecurID Security Profile : None
321
322 - name: Replace AAA configuration
323 dellemc.enterprise_sonic.sonic_aaa:
324 config:
325 authentication:
326 auth_method:
327 - cac-piv
328 - local
329 console_auth_local: true
330 failthrough: false
331 authorization:
332 commands_auth_method:
333 - local
334 accounting:
335 commands_accounting:
336 accounting_method:
337 - tacacs+
338 session_accounting:
339 accounting_record_type: 'start-stop'
340 name_service:
341 group:
342 - ldap
343 state: replaced
344
345 # After state:
346 # ------------
347 #
348 # sonic# show aaa
349 # ---------------------------------------------------------
350 # AAA Authentication Information
351 # ---------------------------------------------------------
352 # failthrough : False
353 # login-method : cac-piv, local
354 # login-mfa : None
355 # console authentication : local
356 # ---------------------------------------------------------
357 # AAA Authorization Information
358 # ---------------------------------------------------------
359 # login : local
360 # ---------------------------------------------------------
361 # AAA Accounting Information
362 # ---------------------------------------------------------
363 # commands : tacacs+ (start-stop, console-disabled)
364 # session : logging (start-stop, console-disabled)
365 # ---------------------------------------------------------
366 # AAA Name-Service Information
367 # ---------------------------------------------------------
368 # group-method : ldap
369 #
370 # sonic# show mfa
371 # ---------------------------------------------------------
372 # Multi-factor Authentication Information
373 # ---------------------------------------------------------
374 # MFA Authentication : None
375 # Console Exempted : None
376 # MFA Service Security Profile : None
377 # RSA SecurID Security Profile : None
378
379
380 # Using "overridden" state
381 #
382 # Before state:
383 # -------------
384 #
385 # sonic# show aaa
386 # ---------------------------------------------------------
387 # AAA Authentication Information
388 # ---------------------------------------------------------
389 # failthrough : True
390 # login-method : local, ldap
391 # login-mfa : rsa-securid
392 # console authentication : local
393 # ---------------------------------------------------------
394 # AAA Authorization Information
395 # ---------------------------------------------------------
396 # login : local, ldap
397 # commands : local, tacacs+
398 # ---------------------------------------------------------
399 # AAA Accounting Information
400 # ---------------------------------------------------------
401 # commands : tacacs+ (start-stop, console-disabled)
402 # session : logging (start-stop, console-disabled)
403 # ---------------------------------------------------------
404 # AAA Name-Service Information
405 # ---------------------------------------------------------
406 # group-method : ldap
407 # netgroup-method : local
408 # passwd-method : login
409 # shadow-method : ldap
410 # sudoers-method : local
411 #
412 # sonic# show mfa
413 # ---------------------------------------------------------
414 # Multi-factor Authentication Information
415 # ---------------------------------------------------------
416 # MFA Authentication : rsa-securid
417 # Console Exempted : Yes
418 # MFA Service Security Profile : None
419 # RSA SecurID Security Profile : None
420
421 - name: Override AAA configuration
422 dellemc.enterprise_sonic.sonic_aaa:
423 config:
424 authentication:
425 auth_method:
426 - tacacs+
427 console_auth_local: true
428 failthrough: true
429 mfa_auth_method: 'rsa-securid'
430 login_mfa_console: true
431 accounting:
432 commands_accounting:
433 accounting_method:
434 - tacacs+
435 - logging
436 accounting_record_type: 'stop-only'
437 accounting_console_exempt: true
438 session_accounting:
439 accounting_method:
440 - logging
441 accounting_record_type: 'stop-only'
442 accounting_console_exempt: true
443 state: overridden
444
445 # After state:
446 # ------------
447 #
448 # sonic# show aaa
449 # ---------------------------------------------------------
450 # AAA Authentication Information
451 # ---------------------------------------------------------
452 # failthrough : True
453 # login-method : tacacs+
454 # login-mfa : rsa-securid
455 # console authentication : local
456 #
457 # sonic# show mfa
458 # ---------------------------------------------------------
459 # Multi-factor Authentication Information
460 # ---------------------------------------------------------
461 # MFA Authentication : rsa-securid
462 # Console Exempted : No
463 # MFA Service Security Profile : None
464 # RSA SecurID Security Profile : None
465 # ---------------------------------------------------------
466 # AAA Accounting Information
467 # ---------------------------------------------------------
468 # commands : tacacs+, logging (stop-only, console-disabled)
469 # session : logging (stop-only, console-disabled)
470
471 # Using "deleted" state
472 #
473 # Before state:
474 # -------------
475 #
476 # sonic# show aaa
477 # ---------------------------------------------------------
478 # AAA Authentication Information
479 # ---------------------------------------------------------
480 # failthrough : True
481 # login-method : local, ldap
482 # login-mfa : rsa-securid
483 # console authentication : local
484 # ---------------------------------------------------------
485 # AAA Authorization Information
486 # ---------------------------------------------------------
487 # login : local, ldap
488 # commands : local, tacacs+
489 # ---------------------------------------------------------
490 # AAA Accounting Information
491 # ---------------------------------------------------------
492 # commands : tacacs+, logging (stop-only, console-disabled)
493 # session : logging (stop-only, console-disabled)
494 # ---------------------------------------------------------
495 # AAA Name-Service Information
496 # ---------------------------------------------------------
497 # group-method : ldap
498 # netgroup-method : local
499 # passwd-method : login
500 # shadow-method : ldap
501 # sudoers-method : local
502 #
503 # sonic# show mfa
504 # ---------------------------------------------------------
505 # Multi-factor Authentication Information
506 # ---------------------------------------------------------
507 # MFA Authentication : rsa-securid
508 # Console Exempted : No
509 # MFA Service Security Profile : None
510 # RSA SecurID Security Profile : None
511
512 - name: Delete AAA individual attributes
513 dellemc.enterprise_sonic.sonic_aaa:
514 config:
515 authentication:
516 auth_method:
517 - local
518 - ldap
519 console_auth_local: true
520 failthrough: true
521 mfa_auth_method: 'rsa-securid'
522 login_mfa_console: true
523 authorization:
524 commands_auth_method:
525 - local
526 - tacacs+
527 login_auth_method:
528 - local
529 - ldap
530 accounting:
531 commands_accounting:
532 accounting_method:
533 - tacacs+
534 - logging
535 accounting_record_type: 'stop-only'
536 accounting_console_exempt: true
537 session_accounting:
538 accounting_method:
539 - logging
540 accounting_record_type: 'stop-only'
541 accounting_console_exempt: true
542 name_service:
543 group:
544 - ldap
545 netgroup:
546 - local
547 passwd:
548 - login
549 shadow:
550 - ldap
551 sudoers:
552 - local
553 state: deleted
554
555 # After state:
556 # ------------
557 #
558 # sonic# show aaa
559 # (No AAA configuration present)
560 #
561 # sonic# show mfa
562 # ---------------------------------------------------------
563 # Multi-factor Authentication Information
564 # ---------------------------------------------------------
565 # MFA Authentication : None
566 # Console Exempted : None
567 # MFA Service Security Profile : None
568 # RSA SecurID Security Profile : None
569
570
571 # Using "deleted" state
572 #
573 # Before state:
574 # -------------
575 #
576 # sonic# show aaa
577 # ---------------------------------------------------------
578 # AAA Authentication Information
579 # ---------------------------------------------------------
580 # failthrough : True
581 # login-method : local, ldap
582 # login-mfa : rsa-securid
583 # console authentication : local
584 # ---------------------------------------------------------
585 # AAA Authorization Information
586 # ---------------------------------------------------------
587 # login : local, ldap
588 # commands : local, tacacs+
589 # ---------------------------------------------------------
590 # AAA Accounting Information
591 # ---------------------------------------------------------
592 # commands : tacacs+, logging (stop-only, console-disabled)
593 # session : logging (stop-only, console-disabled)
594 # ---------------------------------------------------------
595 # AAA Name-Service Information
596 # ---------------------------------------------------------
597 # group-method : ldap
598 # netgroup-method : local
599 # passwd-method : login
600 # shadow-method : ldap
601 # sudoers-method : local
602 #
603 # sonic# show mfa
604 # ---------------------------------------------------------
605 # Multi-factor Authentication Information
606 # ---------------------------------------------------------
607 # MFA Authentication : rsa-securid
608 # Console Exempted : Yes
609 # MFA Service Security Profile : None
610 # RSA SecurID Security Profile : None
611
612 - name: Delete all AAA configuration
613 dellemc.enterprise_sonic.sonic_aaa:
614 config: {}
615 state: deleted
616
617 # After state:
618 # ------------
619 #
620 # sonic# show aaa
621 # (No AAA configuration present)
622 #
623 # sonic# show mfa
624 # ---------------------------------------------------------
625 # Multi-factor Authentication Information
626 # ---------------------------------------------------------
627 # MFA Authentication : None
628 # Console Exempted : None
629 # MFA Service Security Profile : None
630 # RSA SecurID Security Profile : None
631 """
632
633 RETURN = """
634 before:
635 description: The configuration prior to the module invocation.
636 returned: always
637 type: dict
638 after:
639 description: The resulting configuration module invocation.
640 returned: when changed
641 type: dict
642 after_generated:
643 description: The generated configuration module invocation.
644 returned: when C(check_mode)
645 type: dict
646 commands:
647 description: The set of commands pushed to the remote device.
648 returned: always
649 type: list
650 sample: ['command 1', 'command 2', 'command 3']
651 """
652
653
654 from ansible.module_utils.basic import AnsibleModule
655 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.argspec.aaa.aaa import AaaArgs
656 from ansible_collections.dellemc.enterprise_sonic.plugins.module_utils.network.sonic.config.aaa.aaa import Aaa
657
658
659 def main():
660 """
661 Main entry point for module execution
662
663 :returns: the result form module invocation
664 """
665 module = AnsibleModule(argument_spec=AaaArgs.argument_spec,
666 supports_check_mode=True)
667
668 result = Aaa(module).execute_module()
669 module.exit_json(**result)
670
671
672 if __name__ == '__main__':
673 main()