Allow the user that runs the app to be specified via an env var

See gh-16973
This commit is contained in:
Wagner Macedo
2019-05-26 17:06:43 -03:00
committed by Andy Wilkinson
parent ea6d9f3328
commit b57f35893c
7 changed files with 94 additions and 0 deletions

View File

@@ -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."; }