jupyter / tmpnb

Creates temporary Jupyter Notebook servers using Docker containers. [DEPRECATED - See BinderHub project]
https://github.com/jupyterhub/binderhub
BSD 3-Clause "New" or "Revised" License
528 stars 123 forks source link

Would it be possible to embed this into an iframe? #263

Open daeilkim opened 7 years ago

daeilkim commented 7 years ago

I keep getting this error when trying to run this on my localhost:

Refused to display 'http://127.0.0.1:8000/user/d8svgQA0OYAD/login?next=%2Fuser%2Fd8svgQA0OYAD%2Ftree' in a frame because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'self' http://127.0.0.1:8000/*".

I've seen other places where you can resolve something like this by modifying the configuration file within /root/.jupyter, but haven't been able to get it working on my end. Here is the [reference url] (https://github.com/jupyter/notebook/issues/886)

utsavkesharwani commented 7 years ago

@daeilkim - Were you able to find a fix for the same?

For individual jupyter notebook, I was able to make it work via following command:

jupyter notebook --NotebookApp.tornado_settings='{"headers":{"Content-Security-Policy":"frame-ancestors self http://localhost:9000; report-uri /api/security/csp-report" }}'

However, when running via tmpnp, I haven't figured out how to pass this setting. Trying following, but it doesn't seems to work:

  docker run -d \
      --net=host \
      --name=tmpnb \
      -e CONFIGPROXY_AUTH_TOKEN=$TOKEN \
      -v /var/run/docker.sock:/docker.sock \
      jupyter/tmpnb \
      python orchestrate.py \
          --container-user=jovyan \
          --pool-size=5 \
          --cull-timeout=30 \
          --cull-max=60 \
          --command="jupyter notebook \
              --no-browser \
              --port {port} \
              --ip=0.0.0.0 \
              --NotebookApp.base_url=/{base_path} \
              --NotebookApp.port_retries=0 \
              --NotebookApp.tornado_settings='{\"headers\": {\"Content-Security-Policy\": \"frame-ancestors self http://localhost:9000; report-uri /api/security/csp-report\"}}'
              --NotebookApp.token='' \
              --NotebookApp.disable_check_xsrf=True"
utsavkesharwani commented 7 years ago

Update:

I was able to make it work as follows:

Created a jupyter_notebook_config.py file with following contents:

c.NotebookApp.tornado_settings = {
    "headers": {
        "Content-Security-Policy": "frame-ancestors self http://localhost:9000; report-uri /api/security/csp-report"
    }
}

Then, created a dockerfile to build a new image on top of existing jupyter/tmpnb

FROM jupyter/tmpnb
ADD jupyter_notebook_config.py /etc/jupyter_notebook_config.py

And then created a new docker image by running following command:

docker build -t myjupyter:latest .

Then, to spawn tmpnb notebooks using myjupyter image, I used following command, with --image as additional parameter, and --NotebookApp.config_file as extra param:

python orchestrate.py --image=myjupyter --command='jupyter notebook --no-browser --port {port} --ip=0.0.0.0 --NotebookApp.config_file=/etc/jupyter_notebook_config.py --NotebookApp.base_url=/{base_path} --NotebookApp.port_retries=0' --container-user=jovyan
tobegit3hub commented 6 years ago

It works for me. Thanks @utsavkesharwani 👍

emptycrown commented 6 years ago

I followed the same process detailed by @utsavkesharwani, but when I ran python orchestrate.py ... I ended up with the following error. As a result, all my jupyter containers exited. Did you guys come across this?

Traceback (most recent call last):
  File "orchestrate.py", line 509, in <module>
    main()
  File "orchestrate.py", line 482, in main
    ioloop.run_sync(pool.heartbeat)
  File "/usr/local/lib/python3.4/site-packages/tornado/ioloop.py", line 453, in run_sync
    return future_cell[0].result()
  File "/usr/local/lib/python3.4/site-packages/tornado/concurrent.py", line 232, in result
    raise_exc_info(self._exc_info)
  File "<string>", line 3, in raise_exc_info
  File "/usr/local/lib/python3.4/site-packages/tornado/gen.py", line 1014, in run
    yielded = self.gen.throw(*exc_info)
  File "/srv/tmpnb/spawnpool.py", line 246, in heartbeat
    yield tasks
  File "/usr/local/lib/python3.4/site-packages/tornado/gen.py", line 1008, in run
    value = future.result()
  File "/usr/local/lib/python3.4/site-packages/tornado/concurrent.py", line 232, in result
    raise_exc_info(self._exc_info)
  File "<string>", line 3, in raise_exc_info
  File "/usr/local/lib/python3.4/site-packages/tornado/gen.py", line 789, in callback
    result_list.append(f.result())
  File "/usr/local/lib/python3.4/site-packages/tornado/concurrent.py", line 232, in result
    raise_exc_info(self._exc_info)
  File "<string>", line 3, in raise_exc_info
  File "/usr/local/lib/python3.4/site-packages/tornado/gen.py", line 1014, in run
    yielded = self.gen.throw(*exc_info)
  File "/srv/tmpnb/spawnpool.py", line 284, in _launch_container
    container_config=self.container_config)
  File "/usr/local/lib/python3.4/site-packages/tornado/gen.py", line 1008, in run
    value = future.result()
  File "/usr/local/lib/python3.4/site-packages/tornado/concurrent.py", line 232, in result
    raise_exc_info(self._exc_info)
  File "<string>", line 3, in raise_exc_info
  File "/usr/local/lib/python3.4/site-packages/tornado/gen.py", line 1017, in run
    yielded = self.gen.send(value)
  File "/srv/tmpnb/dockworker.py", line 212, in create_notebook_server
    host_port = container_network[0]['HostPort']
TypeError: 'NoneType' object is not subscriptable
utsavkesharwani commented 6 years ago

@EmptyCrown: Please share your dockerfile and full python orchestrate.py ... command. Will take a look.

Btw, you can also try posting on Jupyter's community. Even I got my answer from there. :smiley:

emptycrown commented 6 years ago

Thank you @utsavkesharwani.

I build the image just as you did. The command I ran was the following. I git cloned the tmpnb repo into tmpnb to get orchestrate.py.

CONFIGPROXY_AUTH_TOKEN=$TOKEN python3 tmpnb/orchestrate.py --image=myjupyter --command='jupyter notebook --no-browser --port {port} --ip=0.0.0.0 --NotebookApp.config_file=/etc/jupyter_notebook_config.py --NotebookApp.base_url=/{base_path} --NotebookApp.port_retries=0' --container-user=jovyan

Here is my Dockerfile:

FROM jupyter/tmpnb
ADD jupyter_notebook_config.py /etc/jupyter_notebook_config.py