jupyterhub / jupyter-rsession-proxy

Jupyter extensions for running an RStudio rsession proxy
BSD 3-Clause "New" or "Revised" License
118 stars 87 forks source link

"No user specified" error with Rstudio 1.2.1335 #65

Open anton-khodak opened 5 years ago

anton-khodak commented 5 years ago

Hi,

I'm using jupyter-rsession-proxy inside zero-to-jupyterhub Kubernetes deployment. For Rstudio version == 1.2.1335 R code is executed in console, but launching any R code from the editor ends with an error:

[rsession-] ERROR system error 13 (Permission denied) [description=No user specified]; OCCURRED AT: rstudio::core::Error rstudio::server_core::sessions::signRequest(const string&, rstudio::core::http::Request&, bool) /var/lib/jenkins/workspace/IDE_open-source-pipeline_v1.2/src/cpp/server_core/sessions/SessionSignature.cpp:42; LOGGED FROM: void rstudio::session::modules::rmarkdown::notebook::{anonymous}::NotebookQueue::consoleThreadMain() /var/lib/jenkins/workspace/IDE_open-source-pipeline_v1.2/src/cpp/session/modules/rmarkdown/NotebookQueue.cpp:498

It works as expected with RStudio == 1.1.456. I suspect it has something to deal with how rsession-proxy specifies a user when starting Rstudio.

zeehio commented 5 years ago

RStudio 1.2.1335 requires a header "X-RStudioUserIdentity" with the username, according to https://github.com/rstudio/rstudio/blame/8af730409bb6d651cc8f6816d136bea91441e7a4/src/cpp/server_core/sessions/SessionSignature.cpp#L30-L43

(I wish I knew how to pass this header from the jupyterhub rsession proxy)

ryanlovett commented 5 years ago

I believe overriding proxy_request_headers will work here. If nobody gets to this before me I'll try to work on it next week.

A better solution would be to make this independent of the http client we happen to be using now.

ryanlovett commented 5 years ago

I've prepared a fix for this which involves letting jupyter-server-proxy users specify additional headers. However I then tried to reproduce this issue without the fix and was unable to do so. I was able to execute commands from Console and by hitting Run from within an editor. Do you have some tips on how to reproduce?

Here is the container I was testing from which uses jupyter-server-proxy master and jupyter-rsession-proxy master:

FROM jupyter/minimal-notebook

USER root

RUN apt-get update
RUN apt-get install -y --no-install-recommends r-base gdebi-core

# ENV RSTUDIO_VERSION 1.1.456
ENV RSTUDIO_VERSION 1.2.1335

# RUN wget --quiet https://download2.rstudio.org/rstudio-server-${RSTUDIO_VERSION}-amd64.deb
RUN wget --quiet https://download2.rstudio.org/server/bionic/amd64/rstudio-server-${RSTUDIO_VERSION}-amd64.deb
RUN gdebi -n rstudio-server-${RSTUDIO_VERSION}-amd64.deb
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

USER $NB_USER

RUN pip install git+https://github.com/jupyterhub/jupyter-server-proxy
# RUN pip install git+https://github.com/ryanlovett/jupyter-server-proxy@configurable_headers
RUN pip install git+https://github.com/jupyterhub/jupyter-rsession-proxy

USER jovyan
ENV PATH="${PATH}:/usr/lib/rstudio-server/bin"

Iirc there's another server extension which wants the additional headers feature so I'll work on it regardless.

zeehio commented 5 years ago

Thanks! I'll test as soon as I can, hopefully this week or the next one. I will try to provide a small reproducible environment as well.

With respect to the reproducible environment, it is a bit confusing to me that the latest jupyter-rsesion-proxy version on pypi is (apparently?) not merged https://github.com/jupyterhub/jupyter-rsession-proxy/pull/57 ... Do you know why?

ryanlovett commented 5 years ago

Not sure why that PR hasn't merged yet. Maybe its worthwhile to post a message on that issue?

Fwiw, I tried using the desktop version of rstudio rather than rstudio-server in the same Dockerfile as above and it also ran fine.

zeehio commented 5 years ago

I am puzzled since I can't reproduce the error anymore. Maybe @anton-khodak can?

On the other hand, I realized I was getting all sorts of errors from RStudio due to a) Wrong permissions on the /home/$user/.rstudio directory b) Multiple RStudio servers using simultaneously the same /home/$user/.rstudio directory

So maybe the "No user specified" error was actually related to that and I fixed it. RStudio is working fine now for me as well with the current pypi versions.

In case Anton can reproduce the issue, maybe he can also check if it is solved by setting proper permissions in his rstudio directory.

To address a), I created this script:

#!/bin/sh
# Name it fix-rstudio.sh and place it with your notebook Dockerfile

chown -R ${NB_UID}:${NB_GID} /home/${NB_USER}/.rstudio

And add it to the before-notebook.d hooks in the notebook Dockerfile:

COPY fix-rstudio.sh /usr/local/bin/before-notebook.d/fix-rstudio.sh

To address b), I made sure the /home/${NB_USER}/.rstudio was not shared among multiple rstudio instances.

anton-khodak commented 5 years ago

Sorry for taking so long to answer. A reproducible example would be to use @ryanlovett 's Dockerfile and to try running a chunk in a file with a name "test.Rmd" and content

    ```{r}
    library(Seurat)

The error message in the console is:

27 Jun 2019 15:50:44 [rsession-] ERROR system error 13 (Permission denied) [description=No user specified]; OCCURRED AT: rstudio::core::Error rstudio::server_core::sessions::signRequest(const string&, rstudio::core::http::Request&, bool) /var/lib/jenkins/workspace/IDE_open-source-pipeline_v1.2/src/cpp/server_core/sessions/SessionSignature.cpp:42; LOGGED FROM: void rstudio::session::modules::rmarkdown::notebook::{anonymous}::NotebookQueue::consoleThreadMain() /var/lib/jenkins/workspace/IDE_open-source-pipeline_v1.2/src/cpp/session/modules/rmarkdown/NotebookQueue.cpp:498 rsession-[30]: ERROR system error 13 (Permission denied) [description=No user specified]; OCCURRED AT: rstudio::core::Error rstudio::server_core::sessions::signRequest(const string&, rstudio::core::http::Request&, bool) /var/lib/jenkins/workspace/IDE_open-source-pipeline_v1.2/src/cpp/server_core/sessions/SessionSignature.cpp:42; LOGGED FROM: void rstudio::session::modules::rmarkdown::notebook::{anonymous}::NotebookQueue::consoleThreadMain() /var/lib/jenkins/workspace/IDE_open-source-pipeline_v1.2/src/cpp/session/modules/rmarkdown/NotebookQueue.cpp:498

ryanlovett commented 5 years ago

I was able to reproduce the error. I had to add a lot more packages to get Seurat to install (new Dockerfile below) -- I didn't experiment with others. I'll see if the configurable_headers stuff I worked on earlier fixes it.

FROM jupyter/minimal-notebook

USER root

RUN apt-get update -qq
RUN apt-get install -y --no-install-recommends \
    software-properties-common \
    gdebi-core \
    dirmngr \
    gpg-agent

RUN apt-key adv --keyserver keyserver.ubuntu.com --recv-keys E298A3A825C0D65DFD57CBB651716619E084DAB9
RUN add-apt-repository -y 'deb https://cloud.r-project.org/bin/linux/ubuntu bionic-cran35/'
RUN apt update -qq -y

RUN add-apt-repository -y ppa:marutter/c2d4u3.5
RUN apt-get update -qq -y

RUN apt install -y r-base r-base-core r-recommended

# ENV RSTUDIO_VERSION 1.1.456
ENV RSTUDIO_VERSION 1.2.1335

RUN wget --quiet https://download2.rstudio.org/server/bionic/amd64/rstudio-server-${RSTUDIO_VERSION}-amd64.deb
RUN gdebi -n rstudio-server-${RSTUDIO_VERSION}-amd64.deb

RUN apt-get install -y r-cran-ape r-cran-assertthat r-cran-backports r-cran-base64enc r-cran-bibtex r-cran-bitops r-cran-catools r-cran-cli r-cran-colorspace r-cran-cowplot r-cran-crayon r-cran-crosstalk r-cran-curl r-cran-data.table r-cran-digest r-cran-dplyr r-cran-fitdistrplus r-cran-future r-cran-future.apply r-cran-gbrd r-cran-gdata r-cran-ggplot2 r-cran-ggrepel r-cran-ggridges r-cran-globals r-cran-glue r-cran-gplots r-cran-gridextra r-cran-gtable r-cran-gtools r-cran-hexbin r-cran-htmltools r-cran-htmlwidgets r-cran-httpuv r-cran-httr r-cran-ica r-cran-igraph r-cran-irlba r-cran-jsonlite r-cran-labeling r-cran-lazyeval r-cran-listenv r-cran-lmtest r-cran-lsei r-cran-magrittr r-cran-matrix r-cran-metap r-cran-mime r-cran-munsell r-cran-npsurv r-cran-openssl r-cran-pbapply r-cran-pillar r-cran-pkgconfig r-cran-plogr r-cran-plotly r-cran-plyr r-cran-png r-cran-purrr r-cran-r6 r-cran-rann r-cran-rcolorbrewer r-cran-rcpp r-cran-rcppeigen r-cran-rcppprogress r-cran-rmarkdown r-cran-rdpack r-cran-reshape2 r-cran-reticulate r-cran-rlang r-cran-r.methodss3 r-cran-rocr r-cran-r.oo r-cran-r.utils r-cran-scales r-cran-sdmtools r-cran-shiny r-cran-sourcetools r-cran-stringi r-cran-stringr r-cran-tibble r-cran-tidyr r-cran-tidyselect r-cran-utf8 r-cran-viridislite r-cran-withr r-cran-xtable r-cran-yaml r-cran-zoo

# r-cran-rsvd r-cran-rtsne r-cran-sctransform r-cran-tsne

RUN apt-get clean && rm -rf /var/lib/apt/lists/*

RUN Rscript -e "install.packages('Seurat')"

USER $NB_USER

RUN pip install git+https://github.com/jupyterhub/jupyter-server-proxy
# RUN pip install git+https://github.com/ryanlovett/jupyter-server-proxy@configurable_headers
RUN pip install git+https://github.com/jupyterhub/jupyter-rsession-proxy

USER jovyan
ENV PATH="${PATH}:/usr/lib/rstudio-server/bin"

CMD jupyter notebook --ip=0.0.0.0 --port=8888 --NotebookApp.token=
scivm commented 4 years ago

Hi. I am seeing this same issue also using 1.2.5033. Easiest test case to reproduce is:

@ryanlovett Can I test your fix for this one?

simplest.Rmd:

simplest operation
```{r}
temp = 1 + 1
scivm commented 4 years ago

I tried to hardcode the header in _build_proxy_request handlers.py of jupyter server proxy but not working....

    headers = self.proxy_request_headers()
    headers['X-RStudioUserIdentity'] = "jovyan"
scivm commented 4 years ago

Not sure what is going on here. Updated the nginx ingress to always send the X-RStudioUserIdentity header with value of jovyan but it did not help. I can see that it is set from the logs of the user image but I still get the ERROR system error 13 (Permission denied) [description=No user specified]

ryanlovett commented 4 years ago

@scivm My changes were in branches of both jupyter-rsession-proxy and jupyter-server-proxy:

https://github.com/jupyterhub/jupyter-rsession-proxy/compare/master...ryanlovett:proxy_headers

https://github.com/jupyterhub/jupyter-server-proxy/compare/master...ryanlovett:configurable_headers