From cafbf44e2fc5c93b2b8d047c50c495f65e6fc5c9 Mon Sep 17 00:00:00 2001 From: Jose Diaz-Gonzalez Date: Sun, 17 Jan 2021 21:53:28 -0500 Subject: [PATCH] fix: drop tmpdir environment variables when not running as dokku user This ensures that tmpdir (and related calls) respect the system defaults for temporary directory access. Critically, changing user via 'sudo' will leave the root temp directory in place, which causes dokku to have undefined behavior when writing to temporary files under libpam-tmpdir. This may break cases where users have redefined tmpdir or related variables, but those cases can be remedied by specifying a value for TMPDIR (and related variables) in /etc/default/dokku. Closes #3149 --- dokku | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/dokku b/dokku index 32683ce30..18ab80921 100755 --- a/dokku +++ b/dokku @@ -88,10 +88,13 @@ if [[ "${args[0]}" =~ ^--.* ]]; then fi ! has_tty && DOKKU_QUIET_OUTPUT=1 -if [[ $(id -un) != "dokku" ]] && [[ ! $1 =~ plugin:* ]] && [[ $1 != "ssh-keys:add" ]] && [[ $1 != "ssh-keys:remove" ]]; then - export SSH_USER=$(id -un) - sudo -u dokku -E -H "$0" "$@" - exit $? +if [[ $(id -un) != "dokku" ]]; then + unset TMP TMPDIR TEMP TEMPDIR + if [[ ! $1 =~ plugin:* ]] && [[ $1 != "ssh-keys:add" ]] && [[ $1 != "ssh-keys:remove" ]]; then + export SSH_USER=$(id -un) + sudo -u dokku -E -H "$0" "$@" + exit $? + fi fi if [[ $1 =~ ^plugin:.* && $1 != "plugin:help" && $1 != "plugin:list" ]] || [[ $1 == "ssh-keys:add" ]] || [[ $1 == "ssh-keys:remove" ]]; then