Repository: zeppelin
Updated Branches:
  refs/heads/master c7dede3d3 -> d1fc86b7b


ZEPPELIN-1701: User impersonation not work with SPARK_HOME set.

### What is this PR for?
User impersonation of front end user does not work with SPARK_HOME set.

### What type of PR is it?
[Bug Fix | Hot Fix]

### Todos
* [x] - Fix log file permission issue

### What is the Jira issue?
* [ZEPPELIN-1701](https://issues.apache.org/jira/browse/ZEPPELIN-1701)

### How should this be tested?
set SPARK_HOME zeppelin-env.sh and then try to run

```
%spark
System.getProperty("user.name")
```

### Screenshots (if appropriate)

### Questions:
* Does the licenses files need update? N/A
* Is there breaking changes for older versions? N/A
* Does this needs documentation? Yes

Author: Prabhjyot Singh <prabhjyotsi...@gmail.org>

Closes #1672 from prabhjyotsingh/ZEPPELIN-1701 and squashes the following 
commits:

4508ae8 [Prabhjyot Singh] add space between `'` and `source`
906bf15 [Prabhjyot Singh] Merge remote-tracking branch 'origin/master' into 
ZEPPELIN-1701
d49a106 [Prabhjyot Singh] add doc for running impersonate command as sudo
002950b [Prabhjyot Singh] adding missing import
9052f2d [Prabhjyot Singh] Merge remote-tracking branch 'origin/master' into 
ZEPPELIN-1701
aa5de22 [Prabhjyot Singh] use different log file for different user (in case of 
user impersonation)
d3d020c [Prabhjyot Singh] execute env variables in zeppelin-env.sh
62d4eb8 [Prabhjyot Singh] ZEPPELIN-1701: User impersonation of front end user 
does not work with SPARK_HOME set.


Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/d1fc86b7
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/d1fc86b7
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/d1fc86b7

Branch: refs/heads/master
Commit: d1fc86b7b2d2012c0323345166c98cc02886e9f1
Parents: c7dede3
Author: Prabhjyot Singh <prabhjyotsi...@gmail.org>
Authored: Wed Nov 30 12:35:33 2016 +0530
Committer: Prabhjyot Singh <prabhjyotsi...@gmail.org>
Committed: Fri Dec 2 11:36:02 2016 +0530

----------------------------------------------------------------------
 bin/interpreter.sh                              | 23 +++++++++++++++++---
 conf/zeppelin-env.sh.template                   |  2 +-
 docs/manual/userimpersonation.md                |  7 ++++++
 .../main/resources/python/zeppelin_pyspark.py   |  1 +
 4 files changed, 29 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/d1fc86b7/bin/interpreter.sh
----------------------------------------------------------------------
diff --git a/bin/interpreter.sh b/bin/interpreter.sh
index b1e1a15..9c13c99 100755
--- a/bin/interpreter.sh
+++ b/bin/interpreter.sh
@@ -88,7 +88,11 @@ 
ZEPPELIN_SERVER=org.apache.zeppelin.interpreter.remote.RemoteInterpreterServer
 
 INTERPRETER_ID=$(basename "${INTERPRETER_DIR}")
 
ZEPPELIN_PID="${ZEPPELIN_PID_DIR}/zeppelin-interpreter-${INTERPRETER_ID}-${ZEPPELIN_IDENT_STRING}-${HOSTNAME}.pid"
-ZEPPELIN_LOGFILE="${ZEPPELIN_LOG_DIR}/zeppelin-interpreter-${INTERPRETER_ID}-${ZEPPELIN_IDENT_STRING}-${HOSTNAME}.log"
+ZEPPELIN_LOGFILE="${ZEPPELIN_LOG_DIR}/zeppelin-interpreter-"
+if [[ ! -z "$ZEPPELIN_IMPERSONATE_USER" ]]; then
+    ZEPPELIN_LOGFILE+="${ZEPPELIN_IMPERSONATE_USER}-"
+fi
+ZEPPELIN_LOGFILE+="${INTERPRETER_ID}-${ZEPPELIN_IDENT_STRING}-${HOSTNAME}.log"
 JAVA_INTP_OPTS+=" -Dzeppelin.log.file=${ZEPPELIN_LOGFILE}"
 
 if [[ ! -d "${ZEPPELIN_LOG_DIR}" ]]; then
@@ -185,12 +189,25 @@ addJarInDirForIntp "${LOCAL_INTERPRETER_REPO}"
 
 CLASSPATH+=":${ZEPPELIN_INTP_CLASSPATH}"
 
+if [[ ! -z "$ZEPPELIN_IMPERSONATE_USER" ]]; then
+    INTERPRETER_RUN_COMMAND=${ZEPPELIN_IMPERSONATE_RUN_CMD}" '"
+    if [[ -f "${ZEPPELIN_CONF_DIR}/zeppelin-env.sh" ]]; then
+        INTERPRETER_RUN_COMMAND+=" source 
"${ZEPPELIN_CONF_DIR}'/zeppelin-env.sh;'
+    fi
+fi
+
 if [[ -n "${SPARK_SUBMIT}" ]]; then
-    ${ZEPPELIN_IMPERSONATE_RUN_CMD} `${SPARK_SUBMIT} --class 
${ZEPPELIN_SERVER} --driver-class-path 
"${ZEPPELIN_INTP_CLASSPATH_OVERRIDES}:${CLASSPATH}" --driver-java-options 
"${JAVA_INTP_OPTS}" ${SPARK_SUBMIT_OPTIONS} ${SPARK_APP_JAR} ${PORT} &`
+    INTERPRETER_RUN_COMMAND+=' '` echo ${SPARK_SUBMIT} --class 
${ZEPPELIN_SERVER} --driver-class-path 
\"${ZEPPELIN_INTP_CLASSPATH_OVERRIDES}:${CLASSPATH}\" --driver-java-options 
\"${JAVA_INTP_OPTS}\" ${SPARK_SUBMIT_OPTIONS} ${SPARK_APP_JAR} ${PORT}`
 else
-    ${ZEPPELIN_IMPERSONATE_RUN_CMD} ${ZEPPELIN_RUNNER} ${JAVA_INTP_OPTS} 
${ZEPPELIN_INTP_MEM} -cp ${ZEPPELIN_INTP_CLASSPATH_OVERRIDES}:${CLASSPATH} 
${ZEPPELIN_SERVER} ${PORT} &
+    INTERPRETER_RUN_COMMAND+=' '` echo ${ZEPPELIN_RUNNER} ${JAVA_INTP_OPTS} 
${ZEPPELIN_INTP_MEM} -cp ${ZEPPELIN_INTP_CLASSPATH_OVERRIDES}:${CLASSPATH} 
${ZEPPELIN_SERVER} ${PORT} `
 fi
 
+if [[ ! -z "$ZEPPELIN_IMPERSONATE_USER" ]]; then
+    INTERPRETER_RUN_COMMAND+="'"
+fi
+
+eval $INTERPRETER_RUN_COMMAND &
+
 pid=$!
 if [[ -z "${pid}" ]]; then
   return 1;

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/d1fc86b7/conf/zeppelin-env.sh.template
----------------------------------------------------------------------
diff --git a/conf/zeppelin-env.sh.template b/conf/zeppelin-env.sh.template
index 50af004..cc0a83e 100644
--- a/conf/zeppelin-env.sh.template
+++ b/conf/zeppelin-env.sh.template
@@ -80,4 +80,4 @@
 # export ZEPPELINHUB_API_ADDRESS               # Refers to the address of the 
ZeppelinHub service in use
 # export ZEPPELINHUB_API_TOKEN                 # Refers to the Zeppelin 
instance token of the user
 # export ZEPPELINHUB_USER_KEY                  # Optional, when using Zeppelin 
with authentication.
-# export ZEPPELIN_IMPERSONATE_CMD       # Optional, when user want to run 
interpreter as end web user. eg) 'sudo -u ${ZEPPELIN_IMPERSONATE_USER}'
+# export ZEPPELIN_IMPERSONATE_CMD       # Optional, when user want to run 
interpreter as end web user. eg) 'sudo -H -u ${ZEPPELIN_IMPERSONATE_USER} bash 
-c '

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/d1fc86b7/docs/manual/userimpersonation.md
----------------------------------------------------------------------
diff --git a/docs/manual/userimpersonation.md b/docs/manual/userimpersonation.md
index 363c62d..f0f01b4 100644
--- a/docs/manual/userimpersonation.md
+++ b/docs/manual/userimpersonation.md
@@ -38,6 +38,13 @@ ssh user1@localhost mkdir -p .ssh
 cat ~/.ssh/id_rsa.pub | ssh user1@localhost 'cat >> .ssh/authorized_keys'
 ```
 
+* Alternatively instead of password-less, user can override 
ZEPPELIN_IMPERSONATE_CMD in zeppelin-env.sh
+
+```
+export ZEPPELIN_IMPERSONATE_CMD='sudo -H -u ${ZEPPELIN_IMPERSONATE_USER} bash 
-c '
+```
+  
+
  * Start zeppelin server.
  
 <hr>

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/d1fc86b7/spark/src/main/resources/python/zeppelin_pyspark.py
----------------------------------------------------------------------
diff --git a/spark/src/main/resources/python/zeppelin_pyspark.py 
b/spark/src/main/resources/python/zeppelin_pyspark.py
index de692ce..dbc7305 100644
--- a/spark/src/main/resources/python/zeppelin_pyspark.py
+++ b/spark/src/main/resources/python/zeppelin_pyspark.py
@@ -27,6 +27,7 @@ from pyspark.storagelevel import StorageLevel
 from pyspark.accumulators import Accumulator, AccumulatorParam
 from pyspark.broadcast import Broadcast
 from pyspark.serializers import MarshalSerializer, PickleSerializer
+import warnings
 import ast
 import traceback
 import warnings

Reply via email to