Skip to content

Commit

Permalink
[bgp]: Add sudo check for TSA/B/C command execution (sonic-net#15288)
Browse files Browse the repository at this point in the history
TSA/B/C scripts invoke commands that require root permissions. If the user does not have sudo permissions, the scripts today execute until the command and throw a backtrace with error at the specific command. Added a check to ensure the operations check for root permissions upfront.
  • Loading branch information
tjchadaga authored and root committed Jul 13, 2023
1 parent afa2423 commit 5a1abf2
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
8 changes: 7 additions & 1 deletion dockers/docker-fpm-frr/base_image_files/TSA
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
#!/bin/bash

# Restrict command to sudo users
if [ "$EUID" -ne 0 ] ; then
echo "Root priveleges are needed for this operation"
exit 1
fi

if [ -f /etc/sonic/chassisdb.conf ]; then
rexec all -c "TSA chassis"
rexec all -c "sudo TSA chassis"
echo "Please execute \"rexec all -c 'sudo config save -y'\" to preserve System mode in Maintenance after reboot\
or config reload on all linecards"
exit 0
Expand Down
8 changes: 7 additions & 1 deletion dockers/docker-fpm-frr/base_image_files/TSB
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
#!/bin/bash

# Restrict command to sudo users
if [ "$EUID" -ne 0 ] ; then
echo "Root priveleges are needed for this operation"
exit 1
fi

# If run on supervisor of chassis, trigger remote execution of TSB on all linecards
if [ -f /etc/sonic/chassisdb.conf ]; then
rexec all -c "TSB chassis"
rexec all -c "sudo TSB chassis"
echo "Please execute \"rexec all -c 'sudo config save -y'\" to preserve System mode in Normal state after reboot\
or config reload on all linecards"
exit 0
Expand Down
10 changes: 8 additions & 2 deletions dockers/docker-fpm-frr/base_image_files/TSC
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
#!/bin/bash

# Restrict command to sudo users
if [ "$EUID" -ne 0 ] ; then
echo "Root priveleges are needed for this operation"
exit 1
fi

if [ -f /etc/sonic/chassisdb.conf ]; then
if [[ $1 == "no-stats" ]]; then
rexec all -c "TSC no-stats"
rexec all -c "sudo TSC no-stats"
else
rexec all -c "TSC"
rexec all -c "sudo TSC"
fi
exit 0
fi
Expand Down

0 comments on commit 5a1abf2

Please sign in to comment.