Allow the user that runs the app to be specified via an env var
See gh-16973
This commit is contained in:
committed by
Andy Wilkinson
parent
ea6d9f3328
commit
b57f35893c
@@ -128,6 +128,26 @@ log_file="$LOG_FOLDER/$LOG_FILENAME"
|
||||
# shellcheck disable=SC2012
|
||||
[[ $(id -u) == "0" ]] && run_user=$(ls -ld "$jarfile" | awk '{print $3}')
|
||||
|
||||
# Force run as informed user (from environment variable)
|
||||
if [[ -n "$RUN_AS_USER" ]]; then
|
||||
# checks performed for all actions except 'status' and 'run'
|
||||
if ! [[ "$action" =~ ^(status|run)$ ]]; then
|
||||
# Issue a error if informed user is not valid
|
||||
id -u "$RUN_AS_USER" || {
|
||||
echoRed "Cannot run as '$RUN_AS_USER': no such user"
|
||||
exit 5
|
||||
}
|
||||
|
||||
# Issue a error if we are not root
|
||||
[[ $(id -u) == 0 ]] || {
|
||||
echoRed "root required to run as '$RUN_AS_USER'"
|
||||
exit 6
|
||||
}
|
||||
fi
|
||||
|
||||
run_user="$RUN_AS_USER"
|
||||
fi
|
||||
|
||||
# Issue a warning if the application will run as root
|
||||
[[ $(id -u ${run_user}) == "0" ]] && { echoYellow "Application is running as root (UID 0). This is considered insecure."; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user