From 4d7ef4899eb50cc376ebcce3db5daa011a740de6 Mon Sep 17 00:00:00 2001 From: MinRK Date: Mon, 10 Oct 2011 14:47:16 -0700 Subject: [PATCH] enable HMAC message signing by default in notebook kernels This is separate from previous, because it is more likely to be rejected. It requires the the Session objects in Handlers get a reference all the way back up to the IPython App that started the environment. --- IPython/frontend/html/notebook/handlers.py | 8 +++++++- IPython/frontend/html/notebook/kernelmanager.py | 3 ++- IPython/frontend/html/notebook/notebookapp.py | 8 +++++++- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/IPython/frontend/html/notebook/handlers.py b/IPython/frontend/html/notebook/handlers.py index 997c03fb2..124537440 100644 --- a/IPython/frontend/html/notebook/handlers.py +++ b/IPython/frontend/html/notebook/handlers.py @@ -173,7 +173,13 @@ class ZMQStreamHandler(websocket.WebSocketHandler): class AuthenticatedZMQStreamHandler(ZMQStreamHandler): def open(self, kernel_id): self.kernel_id = kernel_id.decode('ascii') - self.session = Session() + try: + cfg = self.application.ipython_app.config + except AttributeError: + # protect from the case where this is run from something other than + # the notebook app: + cfg = None + self.session = Session(config=cfg) self.save_on_message = self.on_message self.on_message = self.on_first_message diff --git a/IPython/frontend/html/notebook/kernelmanager.py b/IPython/frontend/html/notebook/kernelmanager.py index 1148f70c1..f3fe6a661 100644 --- a/IPython/frontend/html/notebook/kernelmanager.py +++ b/IPython/frontend/html/notebook/kernelmanager.py @@ -70,7 +70,8 @@ class MultiKernelManager(LoggingConfigurable): kernel_id = unicode(uuid.uuid4()) # use base KernelManager for each Kernel km = KernelManager(connection_file=os.path.join( - self.connection_dir, "kernel-%s.json" % kernel_id) + self.connection_dir, "kernel-%s.json" % kernel_id), + config=self.config, ) km.start_kernel(**kwargs) self._kernels[kernel_id] = km diff --git a/IPython/frontend/html/notebook/notebookapp.py b/IPython/frontend/html/notebook/notebookapp.py index e2a0ee962..7d26c3309 100644 --- a/IPython/frontend/html/notebook/notebookapp.py +++ b/IPython/frontend/html/notebook/notebookapp.py @@ -44,7 +44,7 @@ from .notebookmanager import NotebookManager from IPython.core.application import BaseIPythonApplication from IPython.core.profiledir import ProfileDir -from IPython.zmq.session import Session +from IPython.zmq.session import Session, default_secure from IPython.zmq.zmqshell import ZMQInteractiveShell from IPython.zmq.ipkernel import ( flags as ipkernel_flags, @@ -128,6 +128,10 @@ aliases.update({ 'notebook-dir': 'NotebookManager.notebook_dir', }) +# remove ipkernel flags that are singletons, and don't make sense in +# multi-kernel evironment: +aliases.pop('f', None) + notebook_aliases = [u'port', u'ip', u'keyfile', u'certfile', u'ws-hostname', u'notebook-dir'] @@ -231,6 +235,8 @@ class IPythonNotebookApp(BaseIPythonApplication): # Don't let Qt or ZMQ swallow KeyboardInterupts. signal.signal(signal.SIGINT, signal.SIG_DFL) + # force Session default to be secure + default_secure(self.config) # Create a KernelManager and start a kernel. self.kernel_manager = MappingKernelManager( config=self.config, log=self.log, kernel_argv=self.kernel_argv,