forked from sonic-net/sonic-buildimage
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support readonly vtysh for sudoers (sonic-net#7383)
Why I did it Support readonly version of the command vtysh How I did it Check if the command starting with "show", and verify only contains single command in script.
- Loading branch information
Showing
5 changed files
with
26 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#!/bin/bash | ||
|
||
# The command rvtysh can be run as root priviledge by any user without password, only allow to execute readonly commands. | ||
|
||
# The options in the show command cannot contains any charactors to run multiple sub-commands potentially, such as "\n", "\r", "|", "&", "$" and ";". | ||
if printf -- "$*" | grep -qPz '[\n\r|&$;]'; then | ||
echo "Not allow to run the command, please use the comand 'sudo vtysh' instead." 1>&2 | ||
exit 1 | ||
fi | ||
|
||
# The sub commands must start with "show" | ||
LAST_PARA= | ||
for para in "$@" | ||
do | ||
if [ "$LAST_PARA" == "-c" ] && [[ "$para" != show* ]]; then | ||
echo "Not allow to run the command '$para', please use the comand 'sudo vtysh' instead." 1>&2 | ||
exit 1 | ||
fi | ||
LAST_PARA=$para | ||
done | ||
|
||
vtysh "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../docker-fpm-frr/base_image_files/rvtysh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters