Skip to content

Commit 089b7c1

Browse files
authored
Merge pull request #166 from jrdnbradford/rsession-socket
Make unix socket default
2 parents aa2ba60 + 06ffb4f commit 089b7c1

File tree

2 files changed

+15
-18
lines changed

2 files changed

+15
-18
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ conda install -c conda-forge jupyter-rsession-proxy
3939

4040
### Multiuser Considerations
4141

42-
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.
42+
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.
4343

4444
## Configuration with Environment Variables
45-
The following behavior can be configured with environment variables
45+
The following behavior can be configured with environment variables:
4646

4747
| Environment Variable | Effect | Default Value | Notes |
4848
|-------------------------------------------|-----------------------------------------------------------------------|---------------------|---------------------------------------------------------------------------|
49-
| `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 |
49+
| `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 |
5050
| `JUPYTER_RSESSION_PROXY_WWW_FRAME_ORIGIN` | The value of the `www-frame-origin` flag to rserver | `same` | |
5151
| `RSERVER_TIMEOUT` | Idle timeout flag to rserver in minutes | `15` | Must be numeric and positive |
5252
| `RSESSION_TIMEOUT` | Idle timeout flag to rsession in minutes | `15` | Must be numeric and positive |

jupyter_rsession_proxy/__init__.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import getpass
22
import os
3-
import pathlib
43
import shutil
54
import subprocess
65
import tempfile
@@ -42,7 +41,7 @@ def rewrite_netloc(response, request):
4241
u = urlparse(v)
4342
redirect_path = u.path
4443
if u.path.startswith("../"):
45-
# R Help server sometimes responds with relative locations which
44+
# R Help server sometimes responds with relative locations which
4645
# need to be handled if changing the host part of the header.
4746
redirect_path = urljoin(request.path, u.path)
4847
if u.netloc != request.host:
@@ -132,11 +131,8 @@ def _get_cmd(port, unix_socket):
132131
print("Invalid value for JUPYTER_RSESSION_PROXY_THREAD_POOL_SIZE. Must be an integer.")
133132
pass
134133

135-
if unix_socket != "":
136-
if supported_args['www-socket']:
137-
cmd.append('--www-socket={unix_socket}')
138-
else:
139-
raise NotImplementedError(f'rstudio-server does not support requested socket connection')
134+
if unix_socket and supported_args['www-socket']:
135+
cmd.append('--www-socket={unix_socket}')
140136
else:
141137
cmd.append('--www-port={port}')
142138

@@ -159,14 +155,15 @@ def _get_timeout(default=15):
159155
}
160156
}
161157

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

171168
return server_process
172169

0 commit comments

Comments
 (0)