Skip to content

Commit 61d0ec9

Browse files
authored
Migrate AAA table per-command authorization in db_migrator (#3296)
Migrate AAA table per-command authorization in db_migrator #### Why I did it per-command AAA need enable in warm-upgrade case #### How I did it Add code to migrate per-command aunthorization #### How to verify it Pass all test case. Add new test case. #### Which release branch to backport (provide reason below if selected) N/A #### Description for the changelog Migrate AAA table per-command authorization in db_migrator #### A picture of a cute animal (not mandatory but encouraged)
1 parent 8629b68 commit 61d0ec9

5 files changed

+28
-0
lines changed

scripts/db_migrator.py

+16
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,22 @@ def migrate_aaa(self):
840840
self.configDB.set_entry("AAA", "accounting", accounting_new)
841841
log.log_info('Migrate AAA accounting: {}'.format(accounting_new))
842842

843+
# setup per-command authorization
844+
tacplus_config = self.configDB.get_entry('TACPLUS', 'global')
845+
if 'passkey' in tacplus_config and '' != tacplus_config.get('passkey'):
846+
authorization = self.configDB.get_entry('AAA', 'authorization')
847+
if not authorization:
848+
authorization_new = aaa_new.get("authorization")
849+
self.configDB.set_entry("AAA", "authorization", authorization_new)
850+
log.log_info('Migrate AAA authorization: {}'.format(authorization_new))
851+
else:
852+
# If no passkey, setup per-command authorization will block remote user command
853+
log.log_info('TACACS passkey does not exist, disable per-command authorization.')
854+
authorization_key = "AAA|authorization"
855+
keys = self.configDB.keys(self.configDB.CONFIG_DB, authorization_key)
856+
if keys:
857+
self.configDB.delete(self.configDB.CONFIG_DB, authorization_key)
858+
843859
def version_unknown(self):
844860
"""
845861
version_unknown tracks all SONiC versions that doesn't have a version

tests/db_migrator_input/config_db/per_command_aaa_enable_expected.json

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
"AAA|authentication": {
66
"login": "tacacs+"
77
},
8+
"AAA|authorization": {
9+
"login": "tacacs+"
10+
},
811
"TACPLUS|global": {
912
"auth_type": "login",
1013
"passkey": "testpasskey"

tests/db_migrator_input/config_db/per_command_aaa_no_authentication_expected.json

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
"AAA|authentication": {
66
"login": "tacacs+"
77
},
8+
"AAA|authorization": {
9+
"login": "tacacs+"
10+
},
811
"TACPLUS|global": {
912
"auth_type": "login",
1013
"passkey": "testpasskey"

tests/db_migrator_input/config_db/per_command_aaa_no_passkey.json

+3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
"AAA|authentication": {
33
"login": "tacacs+"
44
},
5+
"AAA|authorization": {
6+
"login": "tacacs+"
7+
},
58
"TACPLUS|global": {
69
"auth_type": "login"
710
}

tests/db_migrator_input/config_db/per_command_aaa_no_tacplus_expected.json

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
"AAA|authentication": {
66
"login": "tacacs+"
77
},
8+
"AAA|authorization": {
9+
"login": "tacacs+"
10+
},
811
"TACPLUS|global": {
912
"auth_type": "login",
1013
"passkey": "testpasskey"

0 commit comments

Comments
 (0)