Skip to content

Commit 34f01f9

Browse files
liuh-80mssonicbld
authored andcommitted
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 3e1ae91 commit 34f01f9

File tree

5 files changed

+28
-0
lines changed

5 files changed

+28
-0
lines changed

scripts/db_migrator.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,22 @@ def migrate_aaa(self):
841841
self.configDB.set_entry("AAA", "accounting", accounting_new)
842842
log.log_info('Migrate AAA accounting: {}'.format(accounting_new))
843843

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

tests/db_migrator_input/config_db/per_command_aaa_enable_expected.json

Lines changed: 3 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 3 additions & 0 deletions
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)