question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Embedding in iframe

See original GitHub issue

When I try to embedd tljh in iframe with below settings in jupyter_config.py file

c.JupyterHub.tornado_settings = {
    'headers': {
         'Content-Security-Policy': 'frame-ancestors self *',
    }
}
c.Spawner.args = ["'--NotebookApp.tornado_settings={'headers': {'Content-Security-Policy': 'frame-ancestors self * ', }}'"]

I am getting following error when I try to start user server. Any idea what is wrong?

> May 03 14:03:25 instance-5 python3[31964]:     KeyError: "'headers'"
May 03 14:03:25 instance-5 python3[31964]:         USERID=self.user.id
May 03 14:03:25 instance-5 python3[31964]:       File "/opt/tljh/hub/lib/python3.6/site-packages/systemdspawner/systemdspawner.py", line 157, in _expand_user_vars
May 03 14:03:25 instance-5 python3[31964]:         args=[self._expand_user_vars(a) for a in self.get_args()],
May 03 14:03:25 instance-5 python3[31964]:       File "/opt/tljh/hub/lib/python3.6/site-packages/systemdspawner/systemdspawner.py", line 280, in <listcomp>
May 03 14:03:25 instance-5 python3[31964]:         args=[self._expand_user_vars(a) for a in self.get_args()],
May 03 14:03:25 instance-5 python3[31964]:       File "/opt/tljh/hub/lib/python3.6/site-packages/systemdspawner/systemdspawner.py", line 280, in start
May 03 14:03:25 instance-5 python3[31964]:         url = await gen.with_timeout(timedelta(seconds=spawner.start_timeout), f)
May 03 14:03:25 instance-5 python3[31964]:       File "/opt/tljh/hub/lib/python3.6/site-packages/jupyterhub/user.py", line 409, in spawn
May 03 14:03:25 instance-5 python3[31964]:         raise e
May 03 14:03:25 instance-5 python3[31964]:       File "/opt/tljh/hub/lib/python3.6/site-packages/jupyterhub/user.py", line 489, in spawn

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:12

github_iconTop GitHub Comments

4reactions
AmalVijayancommented, Feb 25, 2020

Here is a work around,

  1. Have a common notebook configuration file for all the users who log into Jupyterhub.
  2. Pass the configuration file as spawner args.

Follow the procedure below:

  1. Create a file named jupyter_notebook_config.py in a specific location say /home/shared_config/

You can either create the file manually using a text editor like vim or generate a default coinfig file using jupyter notebook with the following command

jupyter notebook --generate-config

Note that the above command requires jupyter notebook to be installed (pip3 install jupyterhub notebook)

After the installation if you face an error related to ruamel.yaml version on loading the tljh-config, execute the following command: pip3 install ruamel.yaml==0.15.*

  1. Open the jupyter_notebook_config.py file that you created above and add the following code:

c.NotebookApp.tornado_settings={'headers': {'Content-Security-Policy': "frame-ancestors * 'self' "}} change the permission of the file using the following code: chmod -R 755 /home/shared_config/jupyter_notebook_config.py

  1. Open you jupyterhub configuration file (by default located in /opt/tljh/config/jupyterhub_config.d/jupyterhub_config.py) and add the following code:

Note: you can generate jupyterhub configuration file using the following command: jupyterhub --generate-config

c.Spawner.args = [ '--config=/home/shared_config/jupyter_notebook_config.py']

  1. Reload the tljf-config using the following command:

sudo tljf-config reload

  1. Happy coding !!

Here is what my config looks like

– /opt/tljh/config/jupyterhub_config.d/jupyterhub_config.py

c.JupyterHub.tornado_settings = {'headers': {'Content-Security-Policy': "frame-ancestors * 'self' "}} c.Spawner.args = [ '--config=/home/ubuntu/jupyter_notebook_config.py']

– /home/shared_config/jupyter_notebook_config.py

c.NotebookApp.tornado_settings={'headers': {'Content-Security-Policy': "frame-ancestors * 'self' "}}

Some useful references and related issues:

0reactions
kaivalyapendsecommented, Nov 1, 2022

@AmalVijayan Hi Amal, I am facing the same issue. I have replicated your steps but still getting the error as : Blocked autofocusing on a <input> element in a cross-origin subframe. For the pages ahead of the login page. Login page is rendering fine but not able to login.

Could anyone throw some light on this?

Read more comments on GitHub >

github_iconTop Results From Across the Web

What Is an Iframe? [+ How to Embed Content With Iframes]
As mentioned, we use iframe to embed an HTML document onto a page. Alternatively, embed is used to embed other types of content,...
Read more >
From object to iframe — other embedding technologies
First, go to YouTube and find a video you like. · Below the video, you'll find a Share button — select this to...
Read more >
How to Create and Embed an Iframe
To embed an iframe in a content page, select Interactive layout, choose the HTML block and paste the iframe code there. You can...
Read more >
HTML iframe tag - W3Schools
The <iframe> tag specifies an inline frame. An inline frame is used to embed another document within the current HTML document.
Read more >
What is iFrame? How to Embed iFrame in WordPress?
You should only embed an iframe code into your website if it is from a reliable source, and you are certain about the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found