# Connect to ondemand-launched jupyter server from vscode

**URL:** <https://discourse.openondemand.org/t/connect-to-ondemand-launched-jupyter-server-from-vscode/2644>\
**Category:** Get Help\
**Tags:** question\
**Created:** [April 19, 2023, 8:36am UTC](https://discourse.openondemand.org/t/connect-to-ondemand-launched-jupyter-server-from-vscode/2644 "2023-04-19T08:36:01Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![jose-d](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jose-d/32/703_2.png) [@jose-d](https://discourse.openondemand.org/u/jose-d)\
**Post date:** [April 19, 2023, 8:36am UTC](https://discourse.openondemand.org/t/connect-to-ondemand-launched-jupyter-server-from-vscode/2644/1 "2023-04-19T08:36:01Z")

</div>

anybody tried to connect from Visual Studio Code to jupyter server started by ondemand?

Visual Studio Code offers possibility to connect to URL of already running Jupyter server, but it’s not able (that’s my current understanding) to go over the dex authentization phase.

Isn’t anybody here who tried to investigate this already?

---

<div class="post-metadata">

**Author:** ![jeff.ohrstrom](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jeff.ohrstrom/32/136_2.png) [@jeff.ohrstrom](https://discourse.openondemand.org/u/jeff.ohrstrom)\
**Post date:** [April 19, 2023, 1:56pm UTC](https://discourse.openondemand.org/t/connect-to-ondemand-launched-jupyter-server-from-vscode/2644/2 "2023-04-19T13:56:27Z")

</div>

I haven’t, no, sorry! If there’s enough need at your site, it could be beneficial to create it’s own app like `code server + Jupyter`. That way it all happens in the app for the user by itself.

---

<div class="post-metadata">

**Author:** ![jose-d](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jose-d/32/703_2.png) [@jose-d](https://discourse.openondemand.org/u/jose-d)\
**Post date:** [April 20, 2023, 9:36am UTC](https://discourse.openondemand.org/t/connect-to-ondemand-launched-jupyter-server-from-vscode/2644/3 "2023-04-20T09:36:54Z")

</div>

yup, I saw the example code-server [app at OSC github.](https://github.com/OSC/bc_osc_codeserver) - I discussed this already with some key users, and the _known bug_ “In-app installation of extensions does not work” is quite showstopper - we all like syntax highlight, linters, etc…

Also the feeling of “native” app vscode is a factor…

After some research, I can tell that:

- VS code can connect to remote jupyter server
- I am able to extract connection information from logs and connection.yaml and connect to it from vscode

So the remaining task is to show this information somehow here - would you advice me, please, where in the codebase is this box drawn?

(and solve the network visibility between client and compute node indeed)

 ![Screenshot 2023-04-20 at 11-33-22 My Interactive Sessions - Open OnDemand](https://us1.discourse-cdn.com/flex015/uploads/osc/original/2X/4/42db219b925d08e6880814ef381bd350b7021428.png)

---

<div class="post-metadata">

**Author:** ![davide-q](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/davide-q/32/1510_2.png) [@davide-q](https://discourse.openondemand.org/u/davide-q)\
**Post date:** [June 7, 2023, 12:44pm UTC](https://discourse.openondemand.org/t/connect-to-ondemand-launched-jupyter-server-from-vscode/2644/4 "2023-06-07T12:44:54Z")

</div>

We are very interested to this too. @jose-d can you please elaborate on how you have been able to have VSCode connect to OOD-launched jupyter? I see two problems:

- getting the appropriate token
- reaching the compute nodes

At the moment I have a JupyterHub server (running on the head node, and submitting jobs to the compute node) and I would like to retire that. However users like the ability to just launch that, get the token (from the hub control panel) and connect via VSCode. On the other hand, network administrators like that they can keep the compute node behind the firewall.

@jeff.ohrstrom can you please elaborate a bit on the code server + Jupyter option and especially on the two issues? I’m not familiar with code server, so excuse me if the questions are too naive

- in-app installation: is this something that I could workaround by doing global install as root? My user base is relatively small and relatively homogeneous, so that’s something I could live with, but I will need to install syntax highlighter and other extensions.

- auth unencrypted: I don’t get this! If we are talking about a OOD app, how does it have its own authentication? Doesn’t it use just the OOD infrastructure including authentication?

Thanks to both!

---

<div class="post-metadata">

**Author:** ![jose-d](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jose-d/32/703_2.png) [@jose-d](https://discourse.openondemand.org/u/jose-d)\
**Post date:** [June 7, 2023, 3:37pm UTC](https://discourse.openondemand.org/t/connect-to-ondemand-launched-jupyter-server-from-vscode/2644/5 "2023-06-07T15:37:52Z")

</div>

> [@davide-q](#):
>
> @jose-d can you please elaborate on how you have been able to have VSCode connect to OOD-launched jupyter?

sure. I must say it was regular slurm-started jupyter, it would need few tweaks to to the same in the jupyter OOD app, but principally _doable_:

at cluster (front-end node):

```auto
srun -N 1 --partition=gpu_int --gres=gpu:a100:1 --cpus-per-task=8 --mem=64000 --time=1-00:00:00 --pty bash -i
# command above will create interactive shell job with properly booked GPU, we're now in it..
# .. load any modules we like:
module load JupyterLab/3.5.0-GCCcore-11.3.0
module load CUDA/11.7.0
# run jupyter
jupyter-server --ip=0.0.0.0

```

this will get you lot of output including this:

```auto
To access the server, open this file in a browser:
        file:///home/jose/.local/share/jupyter/runtime/.....html
    Or copy and paste one of these URLs:
        http://gpu1......:8888/?token=redacted
     or http://127.0.0.1:8888/?token=redacted

```

well and then, at my local laptop _(edit: changed wording a bit)_, I started vscode, and created _remote development session_ at login/front-end server (acting as a ssh jumpserver), then:

- press F1
- type in “Notebook select Notebook Kernel”
- select “Another kernel”
- select “existing jupyter server”
- enter the URL of the running Jupyter server (- and there paste the URL from above)

…and that’s it.

It would be helpful, if using job templates or other OOD feature I’d be able to automatize the job launch, extract jupyter server URL, and display that in some user-friendly way.

Inbetween I realized that there is “tunnels” feature in vscode. Perhaps it could be more meaningful for our case.

---

<div class="post-metadata">

**Author:** ![jeff.ohrstrom](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jeff.ohrstrom/32/136_2.png) [@jeff.ohrstrom](https://discourse.openondemand.org/u/jeff.ohrstrom)\
**Post date:** [June 7, 2023, 3:49pm UTC](https://discourse.openondemand.org/t/connect-to-ondemand-launched-jupyter-server-from-vscode/2644/6 "2023-06-07T15:49:45Z")

</div>

I’m not entirely sure how to do this, but I would say that with a seperate app you can boot both applications, vscode & jupyter and connect them directly in the `script.sh.erb`.

Here’s an example where we boot Spark along with Jupyter. It’s a seperate application from the regular Jupyter application and does all the work of booting up Spark alongside Jupyter and connecting the two.

> **[GitHub - OSC/bc\_osc\_jupyter\_spark: Batch Connect - OSC Jupyter Notebook Server...](https://github.com/OSC/bc_osc_jupyter_spark)**
>
> Batch Connect - OSC Jupyter Notebook Server + Spark - GitHub - OSC/bc\_osc\_jupyter\_spark: Batch Connect - OSC Jupyter Notebook Server + Spark

---

<div class="post-metadata">

**Author:** ![jose-d](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jose-d/32/703_2.png) [@jose-d](https://discourse.openondemand.org/u/jose-d)\
**Post date:** [June 7, 2023, 4:13pm UTC](https://discourse.openondemand.org/t/connect-to-ondemand-launched-jupyter-server-from-vscode/2644/7 "2023-06-07T16:13:59Z")

</div>

@jeff.ohrstrom isn’t there any template/example to display (part of) content of job output at OOD portal?

(like the _unofficial_ desktop feature showing VNC client connection instructions for various OS, parsed from log output of vncserver…)

---

<div class="post-metadata">

**Author:** ![jeff.ohrstrom](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jeff.ohrstrom/32/136_2.png) [@jeff.ohrstrom](https://discourse.openondemand.org/u/jeff.ohrstrom)\
**Post date:** [June 7, 2023, 7:11pm UTC](https://discourse.openondemand.org/t/connect-to-ondemand-launched-jupyter-server-from-vscode/2644/8 "2023-06-07T19:11:44Z")

</div>

You can use `conn_params` for variables that are generated at runtime (the job’s runtime) that need to be passed back to the `view.html.erb`

[https://osc.github.io/ood-documentation/latest/how-tos/app-development/interactive/conn-params.html](https://osc.github.io/ood-documentation/latest/how-tos/app-development/interactive/conn-params.html)

---

<div class="post-metadata">

**Author:** ![davide-q](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/davide-q/32/1510_2.png) [@davide-q](https://discourse.openondemand.org/u/davide-q)\
**Post date:** [July 6, 2023, 11:35pm UTC](https://discourse.openondemand.org/t/connect-to-ondemand-launched-jupyter-server-from-vscode/2644/9 "2023-07-06T23:35:38Z")

</div>

After some offline discussion, it has been recommended to me to inspect the HTML of the “Connect to Jupyter” button to see if I could find a way to connect to jupyter via an URL-only method which should work in VSCode, but that does not appear to work.

For example, in one instance I get

```auto
<div class="ood-appkit markdown"><form action="/node/node0202/53086/login" method="post" target="_blank">
  <input type="hidden" name="password" value="some_password_value">
  <button class="btn btn-primary" type="submit">
    <i class="fa fa-eye"></i> Connect to Jupyter
  </button>
</form>
</div>

```

However navigating (in another browser) to [https://actcluster.honeywell.lab:5554/node/node0202/53086/login?password=some\_password\_value](https://actcluster.honeywell.lab:5554/node/node0202/53086/login?password=some_password_value) returns a 404. Copy-pasting the actual URL which the “Connect to Jupyter” button opens require a login, whether or not I append the ?password=some\_password\_value at the end.

Any ideas?

---

<div class="post-metadata">

**Author:** ![jeff.ohrstrom](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jeff.ohrstrom/32/136_2.png) [@jeff.ohrstrom](https://discourse.openondemand.org/u/jeff.ohrstrom)\
**Post date:** [July 7, 2023, 2:10pm UTC](https://discourse.openondemand.org/t/connect-to-ondemand-launched-jupyter-server-from-vscode/2644/10 "2023-07-07T14:10:16Z")

</div>

Buttons are a POST request - you can see the `method="post"` there in the `form` tag. Web browsers issue GET requests.

I’m trying to find the documentation for the same, but it seems to indicate that if you switch to token based authentication it may work.

Instead of setting a password in `before.sh.erb` you can use the `uuid` command and set the setting:

```auto
c.NotebookApp.token = ''

```

---

<div class="post-metadata">

**Author:** ![davide-q](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/davide-q/32/1510_2.png) [@davide-q](https://discourse.openondemand.org/u/davide-q)\
**Post date:** [July 10, 2023, 6:02pm UTC](https://discourse.openondemand.org/t/connect-to-ondemand-launched-jupyter-server-from-vscode/2644/11 "2023-07-10T18:02:03Z")

</div>

Thanks.  
I think the problem is that OOD still tries to authenticate me via DEX. So if I set a token authentication in jupyter (perhaps with an actual token, rather than a empty one 😉 I would like to go to an URL like

[https://cluster-url:8443/node/node-name.cluster/12882/lab/?token=1234](https://cluster-url:8443/node/node-name.cluster/12882/lab/?token=1234)

and bypass the DEX authentication getting only the jupyter one.

That’s how it is handled by JupyterHub, as mentioned at here

> **[JupyterHub URL scheme](https://jupyterhub.readthedocs.io/en/stable/reference/urls.html#user-username-servername)**
>
> This document describes how JupyterHub routes requests. This does not include the REST API URLs. In general, all URLs can be prefixed with c.JupyterHub.base\_url to run the whole JupyterHub applicat...

In fact if I go to any JH URL it asks me to authenticate to the JH server, however something like

[https://cluster-url](https://cluster-url):port/user/username/lab/?token=1234

gets authenticated by jupyter notebook and bypasses the jupyterhub authentication.

My guess is that OOD does not support this sort of pass-through? Does it sound like something easy to configure or implement in a future version?

---

<div class="post-metadata">

**Author:** ![jeff.ohrstrom](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jeff.ohrstrom/32/136_2.png) [@jeff.ohrstrom](https://discourse.openondemand.org/u/jeff.ohrstrom)\
**Post date:** [July 10, 2023, 6:12pm UTC](https://discourse.openondemand.org/t/connect-to-ondemand-launched-jupyter-server-from-vscode/2644/12 "2023-07-10T18:12:28Z")

</div>

> [@davide-q](#):
>
> I think the problem is that OOD still tries to authenticate me via DEX. So if I set a token authentication in jupyter (perhaps with an actual token, rather than a empty one 😉 I would like to go to an URL like
> 
> [https://cluster-url:8443/node/node-name.cluster/12882/lab/?token=1234](https://cluster-url:8443/node/node-name.cluster/12882/lab/?token=1234)
> 
> and bypass the DEX authentication getting only the jupyter one.

You cannot bypass DEX. I thought the flow is something like

- you are logged into OnDemand
- you submit a job request and read the card for that jupyter URL
- in a new tab, but the same browser, you input that URL from the job.

The last step is the important bit. You have to use a new tab in the same browser that you’re logged into OnDemand with. Otherwise, yes, you’ll have to authenticate with DEX.

---

<div class="post-metadata">

**Author:** ![davide-q](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/davide-q/32/1510_2.png) [@davide-q](https://discourse.openondemand.org/u/davide-q)\
**Post date:** [July 10, 2023, 7:01pm UTC](https://discourse.openondemand.org/t/connect-to-ondemand-launched-jupyter-server-from-vscode/2644/13 "2023-07-10T19:01:27Z")

</div>

I see. This makes sense for the browser, but sadly not for the pretend-browser that VSCode acts like.

So we need to keep JH running for that reason 😭

Is there any way that in the future this bypass-DEX-for-certain-URLs feature be implemented?

Thanks!

---

<div class="post-metadata">

**Author:** ![jeff.ohrstrom](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/jeff.ohrstrom/32/136_2.png) [@jeff.ohrstrom](https://discourse.openondemand.org/u/jeff.ohrstrom)\
**Post date:** [July 10, 2023, 8:10pm UTC](https://discourse.openondemand.org/t/connect-to-ondemand-launched-jupyter-server-from-vscode/2644/14 "2023-07-10T20:10:00Z")

</div>

> [@davide-q](#):
>
> Is there any way that in the future this bypass-DEX-for-certain-URLs feature be implemented?

I don’t think so. It seems very dangerous to me to leave these URLs open to anyone.

---

<div class="post-metadata">

**Author:** ![davide-q](https://sea1.discourse-cdn.com/flex015/user_avatar/discourse.openondemand.org/davide-q/32/1510_2.png) [@davide-q](https://discourse.openondemand.org/u/davide-q)\
**Post date:** [July 10, 2023, 9:05pm UTC](https://discourse.openondemand.org/t/connect-to-ondemand-launched-jupyter-server-from-vscode/2644/15 "2023-07-10T21:05:16Z")

</div>

> I don’t think so. It seems very dangerous to me to leave these URLs open to anyone.

Thanks for sharing this comment.

To be clear, I’m not suggesting to leave it “open to anyone” but to simply proxy that URL to something else (jupyter in this case). Jupyter itself is not “open to anyone” but requires a password or token (which OOD provides under the hood in the current implementation, so you authenticate only once rather than twice).  
What I was proposing, for this specific URL, is that OOD would just to the proxy to jupyter and let that handle the authentication.  
If it’s too much of hassle or something to get it right, I understand – but I suspect others would keep asking since VSCode is quite popular already and gaining even more among the jupyter crowd, so…

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex015/uploads/osc/original/2X/b/bae70bd0ed39a3ae769c2108155f4cb3e9da8385.png) [@system](https://discourse.openondemand.org/u/system)\
**Post date:** [January 6, 2024, 9:05pm UTC](https://discourse.openondemand.org/t/connect-to-ondemand-launched-jupyter-server-from-vscode/2644/16 "2024-01-06T21:05:18Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
