Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make cookie_secret configurable #3373

Merged
merged 3 commits into from Jun 4, 2013
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion IPython/frontend/html/notebook/base/handlers.py
Expand Up @@ -147,7 +147,10 @@ def get_current_user(self):

@property
def cookie_name(self):
return self.settings.get('cookie_name', '')
default_cookie_name = 'username-{host}'.format(
host=self.request.host,
).replace(':', '-')
return self.settings.get('cookie_name', default_cookie_name)

@property
def password(self):
Expand Down
14 changes: 11 additions & 3 deletions IPython/frontend/html/notebook/notebookapp.py
Expand Up @@ -83,7 +83,7 @@
from IPython.utils.localinterfaces import LOCALHOST
from IPython.utils import submodule
from IPython.utils.traitlets import (
Dict, Unicode, Integer, List, Bool,
Dict, Unicode, Integer, List, Bool, Bytes,
DottedObjectName
)
from IPython.utils import py3compat
Expand Down Expand Up @@ -164,9 +164,8 @@ def init_settings(self, ipython_app, kernel_manager, notebook_manager,
static_url_prefix = url_path_join(base_project_url,'/static/'),

# authentication
cookie_secret=os.urandom(1024),
cookie_secret=ipython_app.cookie_secret,
login_url=url_path_join(base_project_url,'/login'),
cookie_name='username-%s' % uuid.uuid4(),
read_only=ipython_app.read_only,
password=ipython_app.password,

Expand Down Expand Up @@ -339,6 +338,15 @@ def _ip_changed(self, name, old, new):
keyfile = Unicode(u'', config=True,
help="""The full path to a private key file for usage with SSL/TLS."""
)

cookie_secret = Bytes(b'', config=True,
help="""The random bytes used to secure cookies.
By default this is a new random number every time you start the Notebook.
Set it to a value in a config file to enable logins to persist across server sessions.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want to add a warning "do not shared config files with cookies secret in it" ?
Also we could make the cookie secret maybe in another file in the security folder, or elsewhere.
you configure a path, and if this path is set then server write a random key on it and is able to find it next time.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note added

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes, config files are python file, you can read it from here... so merging away.

"""
)
def _cookie_secret_default(self):
return os.urandom(1024)

password = Unicode(u'', config=True,
help="""Hashed password to use for web authentication.
Expand Down