From 0ba6267b9f6a78a5df49c83d86d8d928721a7d89 Mon Sep 17 00:00:00 2001 From: "FAREAST\\chezhang" Date: Fri, 7 Dec 2018 22:00:33 +0800 Subject: [PATCH] enable switching user and running task command by using environment variable CCP_SWITCH_USER, which is to fix a bug that command, like "ulimit -l" on Ubuntu, is executed as root even if the runas user is specified as other user --- nodemanager/scripts/StartTask.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/nodemanager/scripts/StartTask.sh b/nodemanager/scripts/StartTask.sh index 8463326..9b5402e 100644 --- a/nodemanager/scripts/StartTask.sh +++ b/nodemanager/scripts/StartTask.sh @@ -34,9 +34,11 @@ fi if $CGInstalled; then groupName=$(GetCGroupName "$taskId") group=$CGroupSubSys:$groupName - cgexec -g "$group" /bin/bash $taskFolder/TestMutualTrust.sh "$taskId" "$taskFolder" "$userName" &&\ - cgexec -g "$group" sudo -H -E -u $userName env "PATH=$PATH" /bin/bash $runPath + cgexec -g "$group" /bin/bash $taskFolder/TestMutualTrust.sh "$taskId" "$taskFolder" "$userName" && (\ + [ "$CCP_SWITCH_USER" == "1" ] && (cgexec -g "$group" su - $userName -m -c "/bin/bash $runPath" || exit) ||\ + cgexec -g "$group" sudo -H -E -u $userName env "PATH=$PATH" /bin/bash $runPath) else - /bin/bash $taskFolder/TestMutualTrust.sh "$taskId" "$taskFolder" "$userName" &&\ - sudo -H -E -u $userName env "PATH=$PATH" /bin/bash $runPath + /bin/bash $taskFolder/TestMutualTrust.sh "$taskId" "$taskFolder" "$userName" && (\ + [ "$CCP_SWITCH_USER" == "1" ] && (su - $userName -m -c "/bin/bash $runPath" || exit) ||\ + sudo -H -E -u $userName env "PATH=$PATH" /bin/bash $runPath) fi