Skip to content

Commit

Permalink
Migrate AAA table per-command authorization in db_migrator (#3296)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
liuh-80 authored May 15, 2024
1 parent 8629b68 commit 61d0ec9
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 0 deletions.
16 changes: 16 additions & 0 deletions scripts/db_migrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,22 @@ def migrate_aaa(self):
self.configDB.set_entry("AAA", "accounting", accounting_new)
log.log_info('Migrate AAA accounting: {}'.format(accounting_new))

# setup per-command authorization
tacplus_config = self.configDB.get_entry('TACPLUS', 'global')
if 'passkey' in tacplus_config and '' != tacplus_config.get('passkey'):
authorization = self.configDB.get_entry('AAA', 'authorization')
if not authorization:
authorization_new = aaa_new.get("authorization")
self.configDB.set_entry("AAA", "authorization", authorization_new)
log.log_info('Migrate AAA authorization: {}'.format(authorization_new))
else:
# If no passkey, setup per-command authorization will block remote user command
log.log_info('TACACS passkey does not exist, disable per-command authorization.')
authorization_key = "AAA|authorization"
keys = self.configDB.keys(self.configDB.CONFIG_DB, authorization_key)
if keys:
self.configDB.delete(self.configDB.CONFIG_DB, authorization_key)

def version_unknown(self):
"""
version_unknown tracks all SONiC versions that doesn't have a version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"AAA|authentication": {
"login": "tacacs+"
},
"AAA|authorization": {
"login": "tacacs+"
},
"TACPLUS|global": {
"auth_type": "login",
"passkey": "testpasskey"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"AAA|authentication": {
"login": "tacacs+"
},
"AAA|authorization": {
"login": "tacacs+"
},
"TACPLUS|global": {
"auth_type": "login",
"passkey": "testpasskey"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
"AAA|authentication": {
"login": "tacacs+"
},
"AAA|authorization": {
"login": "tacacs+"
},
"TACPLUS|global": {
"auth_type": "login"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
"AAA|authentication": {
"login": "tacacs+"
},
"AAA|authorization": {
"login": "tacacs+"
},
"TACPLUS|global": {
"auth_type": "login",
"passkey": "testpasskey"
Expand Down

0 comments on commit 61d0ec9

Please sign in to comment.