Skip to content

Commit

Permalink
Merge pull request #1115 from secant/refuse-root
Browse files Browse the repository at this point in the history
refuse to run as root user
  • Loading branch information
minrk committed Feb 22, 2016
2 parents eeef56b + a11f81a commit b0fa952
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions notebook/notebookapp.py
Expand Up @@ -346,6 +346,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 @@ -445,6 +450,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 @@ -1100,6 +1109,13 @@ def start(self):
This method takes no arguments so all configuration and initialization
must be done prior to calling this method."""
try:
if os.geteuid() == 0:
self.log.critical("Running as root is not recommended. Use --allow-root to bypass.")
self.exit(1)
except AttributeError as e:
pass

super(NotebookApp, self).start()

info = self.log.info
Expand Down

0 comments on commit b0fa952

Please sign in to comment.