-
Notifications
You must be signed in to change notification settings - Fork 287
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
Migrate SSH tunneling from pyzmq #335
Merged
minrk
merged 2 commits into
jupyter:master
from
reef-technologies:migrate_ssh_tunneling_from_pyzmq
Feb 7, 2018
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from jupyter_client.ssh.tunnel import * |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# | ||
# This file is adapted from a paramiko demo, and thus licensed under LGPL 2.1. | ||
# Original Copyright (C) 2003-2007 Robey Pointer <robeypointer@gmail.com> | ||
# Edits Copyright (C) 2010 The IPython Team | ||
# | ||
# Paramiko is free software; you can redistribute it and/or modify it under the | ||
# terms of the GNU Lesser General Public License as published by the Free | ||
# Software Foundation; either version 2.1 of the License, or (at your option) | ||
# any later version. | ||
# | ||
# Paramiko is distrubuted in the hope that it will be useful, but WITHOUT ANY | ||
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR | ||
# A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | ||
# details. | ||
# | ||
# You should have received a copy of the GNU Lesser General Public License | ||
# along with Paramiko; if not, write to the Free Software Foundation, Inc., | ||
# 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA. | ||
|
||
""" | ||
Sample script showing how to do local port forwarding over paramiko. | ||
|
||
This script connects to the requested SSH server and sets up local port | ||
forwarding (the openssh -L option) from a local port through a tunneled | ||
connection to a destination reachable from the SSH server machine. | ||
""" | ||
|
||
from __future__ import print_function | ||
|
||
import logging | ||
import select | ||
try: # Python 3 | ||
import socketserver | ||
except ImportError: # Python 2 | ||
import SocketServer as socketserver | ||
|
||
logger = logging.getLogger('ssh') | ||
|
||
|
||
class ForwardServer (socketserver.ThreadingTCPServer): | ||
daemon_threads = True | ||
allow_reuse_address = True | ||
|
||
|
||
class Handler (socketserver.BaseRequestHandler): | ||
|
||
def handle(self): | ||
try: | ||
chan = self.ssh_transport.open_channel('direct-tcpip', | ||
(self.chain_host, self.chain_port), | ||
self.request.getpeername()) | ||
except Exception as e: | ||
logger.debug('Incoming request to %s:%d failed: %s' % (self.chain_host, | ||
self.chain_port, | ||
repr(e))) | ||
return | ||
if chan is None: | ||
logger.debug('Incoming request to %s:%d was rejected by the SSH server.' % | ||
(self.chain_host, self.chain_port)) | ||
return | ||
|
||
logger.debug('Connected! Tunnel open %r -> %r -> %r' % (self.request.getpeername(), | ||
chan.getpeername(), (self.chain_host, self.chain_port))) | ||
while True: | ||
r, w, x = select.select([self.request, chan], [], []) | ||
if self.request in r: | ||
data = self.request.recv(1024) | ||
if len(data) == 0: | ||
break | ||
chan.send(data) | ||
if chan in r: | ||
data = chan.recv(1024) | ||
if len(data) == 0: | ||
break | ||
self.request.send(data) | ||
chan.close() | ||
self.request.close() | ||
logger.debug('Tunnel closed ') | ||
|
||
|
||
def forward_tunnel(local_port, remote_host, remote_port, transport): | ||
# this is a little convoluted, but lets me configure things for the Handler | ||
# object. (SocketServer doesn't give Handlers any way to access the outer | ||
# server normally.) | ||
class SubHander (Handler): | ||
chain_host = remote_host | ||
chain_port = remote_port | ||
ssh_transport = transport | ||
ForwardServer(('127.0.0.1', local_port), SubHander).serve_forever() | ||
|
||
|
||
__all__ = ['forward_tunnel'] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should now be
from .ssh
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.