Skip to content

Commit

Permalink
Backport PR #2421: Cannot run Jupyter lab subcommands from root
Browse files Browse the repository at this point in the history
  • Loading branch information
gnestor committed Jul 3, 2017
1 parent bfb4764 commit 2c96ad2
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions notebook/notebookapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,11 @@ def start(self):
"""
)

flags['allow-root']=(
{'NotebookApp' : {'allow_root' : True}},
"Allow the notebook to be run from root user."
)

# Add notebook manager flags
flags.update(boolean_flag('script', 'FileContentsManager.save_script',
'DEPRECATED, IGNORED',
Expand Down Expand Up @@ -438,6 +443,10 @@ def _log_format_default(self):
help="Set the Access-Control-Allow-Credentials: true header"
)

allow_root = Bool(False, config=True,
help="Whether to allow the user to run the notebook as root."
)

default_url = Unicode('/tree', config=True,
help="The default URL to redirect to from `/`"
)
Expand Down Expand Up @@ -1194,8 +1203,19 @@ def start(self):
This method takes no arguments so all configuration and initialization
must be done prior to calling this method."""

super(NotebookApp, self).start()

if not self.allow_root:
# check if we are running as root, and abort if it's not allowed
try:
uid = os.geteuid()
except AttributeError:
uid = -1 # anything nonzero here, since we can't check UID assume non-root
if uid == 0:
self.log.critical("Running as root is not recommended. Use --allow-root to bypass.")
self.exit(1)

info = self.log.info
for line in self.notebook_info().split("\n"):
info(line)
Expand Down

0 comments on commit 2c96ad2

Please sign in to comment.