-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
images/datascience-notebook/scripts/jupyter_server_config.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
# Copyright (c) Jupyter Development Team. | ||
# Distributed under the terms of the Modified BSD License. | ||
# mypy: ignore-errors | ||
import os | ||
import stat | ||
import subprocess | ||
from pathlib import Path | ||
|
||
from jupyter_core.paths import jupyter_data_dir | ||
|
||
c = get_config() # noqa: F821 | ||
c.ServerApp.ip = "0.0.0.0" | ||
c.ServerApp.open_browser = False | ||
c.ServerApp.tornado_settings = {'headers': {'Content-Security-Policy': "frame-ancestors *;"}} | ||
|
||
# TEMP: Disable RTC until bugs fixed with URL modification | ||
c.YDocExtension.disable_rtc = True | ||
|
||
# to output both image/svg+xml and application/pdf plot formats in the notebook file | ||
c.InlineBackend.figure_formats = {"png", "jpeg", "svg", "pdf"} | ||
|
||
# https://github.com/jupyter/notebook/issues/3130 | ||
c.FileContentsManager.delete_to_trash = False | ||
|
||
# Generate a self-signed certificate | ||
OPENSSL_CONFIG = """\ | ||
[req] | ||
distinguished_name = req_distinguished_name | ||
[req_distinguished_name] | ||
""" | ||
if "GEN_CERT" in os.environ: | ||
dir_name = Path(jupyter_data_dir()) | ||
dir_name.mkdir(parents=True, exist_ok=True) | ||
pem_file = dir_name / "notebook.pem" | ||
|
||
# Generate an openssl.cnf file to set the distinguished name | ||
cnf_file = Path(os.getenv("CONDA_DIR", "/usr/lib")) / "ssl/openssl.cnf" | ||
if not cnf_file.exists(): | ||
cnf_file.write_text(OPENSSL_CONFIG) | ||
|
||
# Generate a certificate if one doesn't exist on a disk | ||
subprocess.check_call( | ||
[ | ||
"openssl", | ||
"req", | ||
"-new", | ||
"-newkey=rsa:2048", | ||
"-days=365", | ||
"-nodes", | ||
"-x509", | ||
"-subj=/C=XX/ST=XX/L=XX/O=generated/CN=generated", | ||
f"-keyout={pem_file}", | ||
f"-out={pem_file}", | ||
] | ||
) | ||
# Restrict access to the file | ||
pem_file.chmod(stat.S_IRUSR | stat.S_IWUSR) | ||
c.ServerApp.certfile = str(pem_file) | ||
|
||
# Change default umask for all subprocesses of the Server if set in the environment | ||
if "NB_UMASK" in os.environ: | ||
os.umask(int(os.environ["NB_UMASK"], 8)) |