##// END OF EJS Templates
Merge pull request #7832 from minrk/default-secure-session...
Matthias Bussonnier -
r20576:478a8026 merge
parent child Browse files
Show More
@@ -30,7 +30,7 b' from IPython.kernel.zmq.kernelapp import ('
30 30 IPKernelApp
31 31 )
32 32 from IPython.kernel.zmq.pylab.config import InlineBackend
33 from IPython.kernel.zmq.session import Session, default_secure
33 from IPython.kernel.zmq.session import Session
34 34 from IPython.kernel.zmq.zmqshell import ZMQInteractiveShell
35 35 from IPython.kernel.connect import ConnectionFileMixin
36 36
@@ -338,7 +338,6 b' class IPythonConsoleApp(ConnectionFileMixin):'
338 338 IPythonConsoleApp.initialize(self,argv)
339 339 """
340 340 self.init_connection_file()
341 default_secure(self.config)
342 341 self.init_ssh()
343 342 self.init_kernel_manager()
344 343 self.init_kernel_client()
@@ -77,7 +77,7 b' from IPython.core.application import ('
77 77 from IPython.core.profiledir import ProfileDir
78 78 from IPython.kernel import KernelManager
79 79 from IPython.kernel.kernelspec import KernelSpecManager
80 from IPython.kernel.zmq.session import default_secure, Session
80 from IPython.kernel.zmq.session import Session
81 81 from IPython.nbformat.sign import NotebookNotary
82 82 from IPython.utils.importstring import import_item
83 83 from IPython.utils import submodule
@@ -764,9 +764,6 b' class NotebookApp(BaseIPythonApplication):'
764 764 self.ipython_kernel_argv = ["--profile-dir", self.profile_dir.location]
765 765
766 766 def init_configurables(self):
767 # force Session default to be secure
768 default_secure(self.config)
769
770 767 self.kernel_spec_manager = self.kernel_spec_manager_class(
771 768 parent=self,
772 769 ipython_dir=self.ipython_dir,
@@ -179,6 +179,8 b' class ZMQChannelsHandler(AuthenticatedZMQStreamHandler):'
179 179 # then request kernel info, waiting up to a certain time before giving up.
180 180 # We don't want to wait forever, because browsers don't take it well when
181 181 # servers never respond to websocket connection requests.
182 kernel = self.kernel_manager.get_kernel(self.kernel_id)
183 self.session.key = kernel.session.key
182 184 future = self.request_kernel_info()
183 185
184 186 def give_up():
@@ -124,7 +124,7 b' class InProcessKernel(IPythonKernel):'
124 124
125 125 def _session_default(self):
126 126 from IPython.kernel.zmq.session import Session
127 return Session(parent=self)
127 return Session(parent=self, key=b'')
128 128
129 129 def _shell_class_default(self):
130 130 return InProcessInteractiveShell
@@ -1,23 +1,13 b''
1 1 """A kernel manager for in-process kernels."""
2 2
3 #-----------------------------------------------------------------------------
4 # Copyright (C) 2013 The IPython Development Team
5 #
6 # Distributed under the terms of the BSD License. The full license is in
7 # the file COPYING, distributed as part of this software.
8 #-----------------------------------------------------------------------------
9
10 #-----------------------------------------------------------------------------
11 # Imports
12 #-----------------------------------------------------------------------------
3 # Copyright (c) IPython Development Team.
4 # Distributed under the terms of the Modified BSD License.
13 5
14 6 from IPython.utils.traitlets import Instance, DottedObjectName
15 7 from IPython.kernel.managerabc import KernelManagerABC
16 8 from IPython.kernel.manager import KernelManager
9 from IPython.kernel.zmq.session import Session
17 10
18 #-----------------------------------------------------------------------------
19 # Main kernel manager class
20 #-----------------------------------------------------------------------------
21 11
22 12 class InProcessKernelManager(KernelManager):
23 13 """A manager for an in-process kernel.
@@ -33,14 +23,18 b' class InProcessKernelManager(KernelManager):'
33 23 kernel = Instance('IPython.kernel.inprocess.ipkernel.InProcessKernel')
34 24 # the client class for KM.client() shortcut
35 25 client_class = DottedObjectName('IPython.kernel.inprocess.BlockingInProcessKernelClient')
36
26
27 def _session_default(self):
28 # don't sign in-process messages
29 return Session(key=b'', parent=self)
30
37 31 #--------------------------------------------------------------------------
38 32 # Kernel management methods
39 33 #--------------------------------------------------------------------------
40 34
41 35 def start_kernel(self, **kwds):
42 36 from IPython.kernel.inprocess.ipkernel import InProcessKernel
43 self.kernel = InProcessKernel()
37 self.kernel = InProcessKernel(parent=self, session=self.session)
44 38
45 39 def shutdown_kernel(self):
46 40 self._kill_kernel()
@@ -25,7 +25,7 b' class InProcessKernelTestCase(unittest.TestCase):'
25 25 def setUp(self):
26 26 self.km = InProcessKernelManager()
27 27 self.km.start_kernel()
28 self.kc = BlockingInProcessKernelClient(kernel=self.km.kernel)
28 self.kc = self.km.client()
29 29 self.kc.start_channels()
30 30 self.kc.wait_for_ready()
31 31
@@ -61,7 +61,7 b' class InProcessKernelTestCase(unittest.TestCase):'
61 61 kernel.shell.run_cell('print("foo")')
62 62 self.assertEqual(io.stdout, 'foo\n')
63 63
64 kc = BlockingInProcessKernelClient(kernel=kernel)
64 kc = BlockingInProcessKernelClient(kernel=kernel, session=kernel.session)
65 65 kernel.frontends.append(kc)
66 66 kc.execute('print("bar")')
67 67 out, err = assemble_output(kc.iopub_channel)
@@ -24,7 +24,7 b' class InProcessKernelManagerTestCase(unittest.TestCase):'
24 24 self.assert_(km.has_kernel)
25 25 self.assert_(km.kernel is not None)
26 26
27 kc = BlockingInProcessKernelClient(kernel=km.kernel)
27 kc = km.client()
28 28 self.assert_(not kc.channels_running)
29 29
30 30 kc.start_channels()
@@ -49,7 +49,7 b' class InProcessKernelManagerTestCase(unittest.TestCase):'
49 49 """
50 50 km = InProcessKernelManager()
51 51 km.start_kernel()
52 kc = BlockingInProcessKernelClient(kernel=km.kernel)
52 kc = km.client()
53 53 kc.start_channels()
54 54 kc.wait_for_ready()
55 55 kc.execute('foo = 1')
@@ -60,7 +60,7 b' class InProcessKernelManagerTestCase(unittest.TestCase):'
60 60 """
61 61 km = InProcessKernelManager()
62 62 km.start_kernel()
63 kc = BlockingInProcessKernelClient(kernel=km.kernel)
63 kc = km.client()
64 64 kc.start_channels()
65 65 kc.wait_for_ready()
66 66 km.kernel.shell.push({'my_bar': 0, 'my_baz': 1})
@@ -75,7 +75,7 b' class InProcessKernelManagerTestCase(unittest.TestCase):'
75 75 """
76 76 km = InProcessKernelManager()
77 77 km.start_kernel()
78 kc = BlockingInProcessKernelClient(kernel=km.kernel)
78 kc = km.client()
79 79 kc.start_channels()
80 80 kc.wait_for_ready()
81 81 km.kernel.shell.user_ns['foo'] = 1
@@ -92,7 +92,7 b' class InProcessKernelManagerTestCase(unittest.TestCase):'
92 92 """
93 93 km = InProcessKernelManager()
94 94 km.start_kernel()
95 kc = BlockingInProcessKernelClient(kernel=km.kernel)
95 kc = km.client()
96 96 kc.start_channels()
97 97 kc.wait_for_ready()
98 98 kc.execute('%who')
@@ -36,7 +36,7 b' from .heartbeat import Heartbeat'
36 36 from .ipkernel import IPythonKernel
37 37 from .parentpoller import ParentPollerUnix, ParentPollerWindows
38 38 from .session import (
39 Session, session_flags, session_aliases, default_secure,
39 Session, session_flags, session_aliases,
40 40 )
41 41 from .zmqshell import ZMQInteractiveShell
42 42
@@ -342,7 +342,6 b' class IPKernelApp(BaseIPythonApplication, InteractiveShellApp,'
342 342 @catch_config_error
343 343 def initialize(self, argv=None):
344 344 super(IPKernelApp, self).initialize(argv)
345 default_secure(self.config)
346 345 self.init_blackhole()
347 346 self.init_connection_file()
348 347 self.init_poller()
@@ -122,7 +122,7 b' def default_secure(cfg):'
122 122 If Session.key/keyfile have not been set, set Session.key to
123 123 a new random UUID.
124 124 """
125
125 warnings.warn("default_secure is deprecated", DeprecationWarning)
126 126 if 'Session' in cfg:
127 127 if 'key' in cfg.Session or 'keyfile' in cfg.Session:
128 128 return
@@ -315,8 +315,11 b' class Session(Configurable):'
315 315
316 316 # message signature related traits:
317 317
318 key = CBytes(b'', config=True,
319 help="""execution key, for extra authentication.""")
318 key = CBytes(config=True,
319 help="""execution key, for signing messages.""")
320 def _key_default(self):
321 return str_to_bytes(str(uuid.uuid4()))
322
320 323 def _key_changed(self):
321 324 self._new_auth()
322 325
@@ -433,6 +436,7 b' class Session(Configurable):'
433 436 # ensure self._session_default() if necessary, so bsession is defined:
434 437 self.session
435 438 self.pid = os.getpid()
439 self._new_auth()
436 440
437 441 @property
438 442 def msg_id(self):
@@ -1,16 +1,9 b''
1 """test building messages with streamsession"""
1 """test building messages with Session"""
2 2
3 #-------------------------------------------------------------------------------
4 # Copyright (C) 2011 The IPython Development Team
5 #
6 # Distributed under the terms of the BSD License. The full license is in
7 # the file COPYING, distributed as part of this software.
8 #-------------------------------------------------------------------------------
9
10 #-------------------------------------------------------------------------------
11 # Imports
12 #-------------------------------------------------------------------------------
3 # Copyright (c) IPython Development Team.
4 # Distributed under the terms of the Modified BSD License.
13 5
6 import hmac
14 7 import os
15 8 import uuid
16 9 from datetime import datetime
@@ -71,6 +64,10 b' class TestSession(SessionTestCase):'
71 64 # ensure floats don't come out as Decimal:
72 65 self.assertEqual(type(new_msg['content']['b']),type(new_msg['content']['b']))
73 66
67 def test_default_secure(self):
68 self.assertIsInstance(self.session.key, bytes)
69 self.assertIsInstance(self.session.auth, hmac.HMAC)
70
74 71 def test_send(self):
75 72 ctx = zmq.Context.instance()
76 73 A = ctx.socket(zmq.PAIR)
@@ -91,9 +88,10 b' class TestSession(SessionTestCase):'
91 88 self.assertEqual(new_msg['parent_header'],msg['parent_header'])
92 89 self.assertEqual(new_msg['metadata'],msg['metadata'])
93 90 self.assertEqual(new_msg['buffers'],[b'bar'])
94
91
95 92 content = msg['content']
96 93 header = msg['header']
94 header['date'] = datetime.now()
97 95 parent = msg['parent_header']
98 96 metadata = msg['metadata']
99 97 msg_type = header['msg_type']
@@ -109,7 +107,9 b' class TestSession(SessionTestCase):'
109 107 self.assertEqual(new_msg['metadata'],msg['metadata'])
110 108 self.assertEqual(new_msg['parent_header'],msg['parent_header'])
111 109 self.assertEqual(new_msg['buffers'],[b'bar'])
112
110
111 header['date'] = datetime.now()
112
113 113 self.session.send(A, msg, ident=b'foo', buffers=[b'bar'])
114 114 ident, new_msg = self.session.recv(B)
115 115 self.assertEqual(ident[0], b'foo')
@@ -48,7 +48,7 b' from IPython.utils.localinterfaces import localhost, public_ips'
48 48 from IPython.utils.traitlets import Instance, Unicode, Bool, List, Dict, TraitError
49 49
50 50 from IPython.kernel.zmq.session import (
51 Session, session_aliases, session_flags, default_secure
51 Session, session_aliases, session_flags,
52 52 )
53 53
54 54 from IPython.parallel.controller.heartmonitor import HeartMonitor
@@ -314,8 +314,6 b' class IPControllerApp(BaseParallelApplication):'
314 314 # no need to wite back the same file
315 315 self.write_connection_files = False
316 316
317 # switch Session.key default to secure
318 default_secure(self.config)
319 317 self.log.debug("Config changed")
320 318 self.log.debug(repr(self.config))
321 319
General Comments 0
You need to be logged in to leave comments. Login now