jupyter / nb2kg

Other
73 stars 31 forks source link

Inconsistent behavior between WebSocketChannelsHandler and others #22

Closed dylanzjy closed 5 years ago

dylanzjy commented 5 years ago

Fix the inconsistent behavior between WebSocketChannelsHandler and the other Handlers when using NotebookApp.allow_origin configuration. The WebSocketChannelsHandler uses the check_origin method from WebSocketHandler by default.

The problem is discovered by following steps:

I'm using nb2kg with Jupyter Notebook to launch kernels on spark. The notebook server runs behind an nginx proxy. The NotebookApp.allow_origin was set as: c.NotebookApp.allow_origin = '*' However, the server returned 403 when the frontend connected to the successfully created kernel. The server showed the following logs: [D 12:54:07.104 NotebookApp] Initializing websocket connection /api/kernels/50852902-0ffe-4973-b550-a2424bf4f86d/channels [W 12:54:07.108 NotebookApp] 403 GET /api/kernels/50852902-0ffe-4973-b550-a2424bf4f86d/channels?session_id=E5BB1B111B8D4B4DAF798597772E5578 (10.244.0.91) 4.93ms referer=None [D 12:54:07.109 NotebookApp] Cross origin websockets not allowed

kevin-bates commented 4 years ago

@dylanzjy - I'm trying to reproduce the issue to apply your change in the notebook/gateway module (#5460) and I'm having trouble getting any cross origin issues to arise.

I'm new to Nginx and suspect my configuration isn't right, although I'm definitely hitting the Nginx server and routing to the Notebook Server (both on "node 2") with my Gateway server on "node 3" and my browser running on "node 1".

Are you able to share the basics of your Nginx configuration? It seems like the check origin is always checking the origin (which is the node2 server name) with the host (which is also the node2 server name), so it always succeeds.

Any information would be helpful - thank you!

dylanzjy commented 4 years ago

@dylanzjy - I'm trying to reproduce the issue to apply your change in the notebook/gateway module (#5460) and I'm having trouble getting any cross origin issues to arise.

I'm new to Nginx and suspect my configuration isn't right, although I'm definitely hitting the Nginx server and routing to the Notebook Server (both on "node 2") with my Gateway server on "node 3" and my browser running on "node 1".

Are you able to share the basics of your Nginx configuration? It seems like the check origin is always checking the origin (which is the node2 server name) with the host (which is also the node2 server name), so it always succeeds.

Any information would be helpful - thank you!

Is there a configuration which is like proxy_set_header Host $host in your nginx.conf or proxy.conf? If there is, delete it and try again. The WebSocketHandler gets the host from Host header and compare it with the origin, and maybe this header is updated by proxy_set_header. Sorry for not being able to provide my Nginx configuration, I'm not working on this any more, so I can't find it.

kevin-bates commented 4 years ago

That was exactly my problem - thank you so much!

Do you mind if I add you as a co-author on my Notebook PR since this is essentially your fix, just ported to the embedded nb2kg?

I would use: Co-authored-by: Dylan <dylan.yi@icloud.com>

dylanzjy commented 4 years ago

That was exactly my problem - thank you so much!

Do you mind if I add you as a co-author on my Notebook PR since this is essentially your fix, just ported to the embedded nb2kg?

I would use: Co-authored-by: Dylan <dylan.yi@icloud.com>

Never mind, it's my pleasure.