Skip to content

[TACACS] Fix TACACS config revert to old config when device reboot issue.#22342

Merged
qiluo-msft merged 2 commits intosonic-net:masterfrom
liuh-80:dev/liuh/fix_tacacs_config_revert
Apr 30, 2025
Merged

[TACACS] Fix TACACS config revert to old config when device reboot issue.#22342
qiluo-msft merged 2 commits intosonic-net:masterfrom
liuh-80:dev/liuh/fix_tacacs_config_revert

Conversation

@liuh-80
Copy link
Contributor

@liuh-80 liuh-80 commented Apr 16, 2025

Fix TACACS config revert to old config when device reboot issue.

Why I did it

Fix following bug:

  1. When SONiC OS upgrade, old TACACS config will save to /etc/sonic/old_config/tacacs.json
  2. After device reboot, TACACS config service (https://github.com/sonic-net/sonic-buildimage/blob/master/files/build_templates/tacacs-config.service) will restore TACACS config from /etc/sonic/old_config/tacacs.json, but this file will keep no change after restore TACACS config.
  3. If TACACS service changed by user, because of Update README.md #2, if device reboot again, the TACACS config been reverted back to old config in /etc/sonic/old_config/tacacs.json

Note: the TACACS config does not revert immediately after reboot, it will delay 5min 30sec:
https://github.com/sonic-net/sonic-buildimage/blob/master/files/build_templates/tacacs-config.timer

Work item tracking
  • Microsoft ADO (number only):32338799

How I did it

Move /etc/sonic/old_config/tacacs.json to /etc/sonic/old_config/tacacs.json_backup

How to verify it

Pass all test case.
Manually verify with following steps:

admin@vlab-01:~$ show tacacs
TACPLUS global auth_type login
TACPLUS global timeout 5 (default)
TACPLUS global passkey testing123

TACPLUS_SERVER address 10.250.0.102
priority 1
tcp_port 49

admin@vlab-01:~$ echo '

{
"TACPLUS": {"global": { "auth_type": "login", "passkey": "12345" } }
}' > /etc/sonic/old_config/tacacs.json
admin@vlab-01:~$ cat /etc/sonic/old_config/tacacs.json

{
"TACPLUS": {"global": { "auth_type": "login", "passkey": "12345" } }
}

// then reboot device and wait for 6 minutes, because the TACACS config service will delay 5min 30sec after reboot:
https://github.com/sonic-net/sonic-buildimage/blob/master/files/build_templates/tacacs-config.timer

admin@vlab-01:$ ls /etc/sonic/old_config/tacacs.json
ls: cannot access '/etc/sonic/old_config/tacacs.json': No such file or directory
admin@vlab-01:
$ show tacacs
TACPLUS global auth_type login
TACPLUS global timeout 5 (default)
TACPLUS global passkey 12345

TACPLUS_SERVER address 10.250.0.102
priority 1
tcp_port 49

Which release branch to backport (provide reason below if selected)

  • 201811
  • 201911
  • 202006
  • 202012
  • 202106
  • 202111
  • 202205
  • 202211
  • 202305

Tested branch (Please provide the tested image version)

Description for the changelog

Fix TACACS config revert to old config when device reboot issue.

Link to config_db schema for YANG module changes

A picture of a cute animal (not mandatory but encouraged)

@mssonicbld
Copy link
Collaborator

/azp run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@liuh-80
Copy link
Contributor Author

liuh-80 commented Apr 22, 2025

/azpw run Azure.sonic-buildimage

@mssonicbld
Copy link
Collaborator

/AzurePipelines run Azure.sonic-buildimage

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@liuh-80 liuh-80 marked this pull request as ready for review April 23, 2025 05:43
@liuh-80 liuh-80 requested a review from lguohan as a code owner April 23, 2025 05:43
@liuh-80 liuh-80 requested a review from qiluo-msft April 23, 2025 05:43
echo "Applied tacacs json to restore tacacs credentials"
config save -y

# Change tacacs config file name, so tacacs config will not be revert when device reboot.
Copy link
Collaborator

@qiluo-msft qiluo-msft Apr 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change tacacs config file name, so tacacs config will not be revert when device reboot

Should we just remove tacacs-config.service completely and simplified tacacs just as simple as part of the config_db.json? #Closed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Complete remove the service is danger, because remove this service may cause SONiC missing TACACS config.
The OS upgrade scenario does not cover by sonic-mgmt test.

@qiluo-msft qiluo-msft merged commit 3cb1ce0 into sonic-net:master Apr 30, 2025
17 checks passed
@qiluo-msft
Copy link
Collaborator

apply_tacacs()

Actually we should check running config first, if running config already has TACACS key, no need to read old_config file at all.


Refers to: files/image_config/config-setup/config-setup:136 in 5407540. [](commit_id = 5407540, deletion_comment = False)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants