Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,14 @@ conda install -c conda-forge jupyter-rsession-proxy

### Multiuser Considerations

This extension launches an rstudio server process from the jupyter notebook server. This is fine in JupyterHub deployments where user servers are containerized since other users cannot connect to the rstudio server port. In non-containerized JupyterHub deployments, for example on multiuser systems running LocalSpawner or BatchSpawner, this not secure. Any user may connect to rstudio server and run arbitrary code.
This extension launches an RStudio server process from the Jupyter notebook server. This is fine in JupyterHub deployments where user servers are containerized since other users cannot connect to the RStudio server port. In non-containerized JupyterHub deployments, for example on multiuser systems running LocalSpawner or BatchSpawner, this not secure. Any user may connect to Rstudio server and run arbitrary code.

## Configuration with Environment Variables
The following behavior can be configured with environment variables
The following behavior can be configured with environment variables:

| Environment Variable | Effect | Default Value | Notes |
|-------------------------------------------|-----------------------------------------------------------------------|---------------------|---------------------------------------------------------------------------|
| `JUPYTER_RSESSION_PROXY_USE_SOCKET` | Use unix sockets instead of TCP sockets | `no` | Anything other than case insensitive `no` or `false` will use unix socket |
| `JUPYTER_RSESSION_PROXY_USE_SOCKET` | Whether to use unix socket | `true` | By default a unix socket is used. If set to case-insensitive `no` or `false` it will switch to using a TCP socket |
| `JUPYTER_RSESSION_PROXY_WWW_FRAME_ORIGIN` | The value of the `www-frame-origin` flag to rserver | `same` | |
| `RSERVER_TIMEOUT` | Idle timeout flag to rserver in minutes | `15` | Must be numeric and positive |
| `RSESSION_TIMEOUT` | Idle timeout flag to rsession in minutes | `15` | Must be numeric and positive |
Expand Down
27 changes: 12 additions & 15 deletions jupyter_rsession_proxy/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import getpass
import os
import pathlib
import shutil
import subprocess
import tempfile
Expand Down Expand Up @@ -42,7 +41,7 @@ def rewrite_netloc(response, request):
u = urlparse(v)
redirect_path = u.path
if u.path.startswith("../"):
# R Help server sometimes responds with relative locations which
# R Help server sometimes responds with relative locations which
# need to be handled if changing the host part of the header.
redirect_path = urljoin(request.path, u.path)
if u.netloc != request.host:
Expand Down Expand Up @@ -132,11 +131,8 @@ def _get_cmd(port, unix_socket):
print("Invalid value for JUPYTER_RSESSION_PROXY_THREAD_POOL_SIZE. Must be an integer.")
pass

if unix_socket != "":
if supported_args['www-socket']:
cmd.append('--www-socket={unix_socket}')
else:
raise NotImplementedError(f'rstudio-server does not support requested socket connection')
if unix_socket and supported_args['www-socket']:
cmd.append('--www-socket={unix_socket}')
else:
cmd.append('--www-port={port}')

Expand All @@ -159,14 +155,15 @@ def _get_timeout(default=15):
}
}

use_socket = os.getenv('JUPYTER_RSESSION_PROXY_USE_SOCKET')
if use_socket is not None:
# If this env var is anything other than case insensitive 'no' or 'false',
# use unix sockets instead of tcp sockets. This allows us to default to
# using unix sockets by default in the future once this feature is better
# tested, and allow people to turn it off if needed.
if use_socket.casefold() not in ('no', 'false'):
server_process['unix_socket'] = True
# The environment variable serves to explicitly disable Unix sockets, which are the default
use_unix_socket = True
disable_socket = os.getenv('JUPYTER_RSESSION_PROXY_USE_SOCKET')
if disable_socket is not None:
if disable_socket.casefold() in ('no', 'false'):
use_unix_socket = False

if use_unix_socket:
server_process['unix_socket'] = True

return server_process

Expand Down