METADATA 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515
  1. Metadata-Version: 2.1
  2. Name: sshtunnel
  3. Version: 0.4.0
  4. Summary: Pure python SSH tunnels
  5. Home-page: https://github.com/pahaz/sshtunnel
  6. Author: Pahaz White
  7. Author-email: pahaz.white@gmail.com
  8. License: MIT
  9. Download-URL: https://pypi.python.org/packages/source/s/sshtunnel/sshtunnel-0.4.0.zip
  10. Keywords: ssh tunnel paramiko proxy tcp-forward
  11. Platform: unix
  12. Platform: macos
  13. Platform: windows
  14. Classifier: Development Status :: 3 - Alpha
  15. Classifier: Intended Audience :: Developers
  16. Classifier: Topic :: Software Development :: Build Tools
  17. Classifier: License :: OSI Approved :: MIT License
  18. Classifier: Programming Language :: Python :: 2
  19. Classifier: Programming Language :: Python :: 2.7
  20. Classifier: Programming Language :: Python :: 3
  21. Classifier: Programming Language :: Python :: 3.4
  22. Classifier: Programming Language :: Python :: 3.5
  23. Classifier: Programming Language :: Python :: 3.6
  24. Classifier: Programming Language :: Python :: 3.7
  25. Classifier: Programming Language :: Python :: 3.8
  26. Description-Content-Type: text/x-rst
  27. Requires-Dist: paramiko (>=2.7.2)
  28. Provides-Extra: build_sphinx
  29. Requires-Dist: sphinx ; extra == 'build_sphinx'
  30. Requires-Dist: sphinxcontrib-napoleon ; extra == 'build_sphinx'
  31. Provides-Extra: dev
  32. Requires-Dist: check-manifest ; extra == 'dev'
  33. Provides-Extra: test
  34. Requires-Dist: tox (>=1.8.1) ; extra == 'test'
  35. |CircleCI| |AppVeyor| |readthedocs| |coveralls| |version|
  36. |pyversions| |license|
  37. **Author**: `Pahaz`_
  38. **Repo**: https://github.com/pahaz/sshtunnel/
  39. Inspired by https://github.com/jmagnusson/bgtunnel, which doesn't work on
  40. Windows.
  41. See also: https://github.com/paramiko/paramiko/blob/master/demos/forward.py
  42. Requirements
  43. -------------
  44. * `paramiko`_
  45. Installation
  46. ============
  47. `sshtunnel`_ is on PyPI, so simply run:
  48. ::
  49. pip install sshtunnel
  50. or ::
  51. easy_install sshtunnel
  52. or ::
  53. conda install -c conda-forge sshtunnel
  54. to have it installed in your environment.
  55. For installing from source, clone the
  56. `repo <https://github.com/pahaz/sshtunnel>`_ and run::
  57. python setup.py install
  58. Testing the package
  59. -------------------
  60. In order to run the tests you first need
  61. `tox <https://testrun.org/tox/latest/>`_ and run::
  62. python setup.py test
  63. Usage scenarios
  64. ===============
  65. One of the typical scenarios where ``sshtunnel`` is helpful is depicted in the
  66. figure below. User may need to connect a port of a remote server (i.e. 8080)
  67. where only SSH port (usually port 22) is reachable. ::
  68. ----------------------------------------------------------------------
  69. |
  70. -------------+ | +----------+
  71. LOCAL | | | REMOTE | :22 SSH
  72. CLIENT | <== SSH ========> | SERVER | :8080 web service
  73. -------------+ | +----------+
  74. |
  75. FIREWALL (only port 22 is open)
  76. ----------------------------------------------------------------------
  77. **Fig1**: How to connect to a service blocked by a firewall through SSH tunnel.
  78. If allowed by the SSH server, it is also possible to reach a private server
  79. (from the perspective of ``REMOTE SERVER``) not directly visible from the
  80. outside (``LOCAL CLIENT``'s perspective). ::
  81. ----------------------------------------------------------------------
  82. |
  83. -------------+ | +----------+ +---------
  84. LOCAL | | | REMOTE | | PRIVATE
  85. CLIENT | <== SSH ========> | SERVER | <== local ==> | SERVER
  86. -------------+ | +----------+ +---------
  87. |
  88. FIREWALL (only port 443 is open)
  89. ----------------------------------------------------------------------
  90. **Fig2**: How to connect to ``PRIVATE SERVER`` through SSH tunnel.
  91. Usage examples
  92. ==============
  93. API allows either initializing the tunnel and starting it or using a ``with``
  94. context, which will take care of starting **and stopping** the tunnel:
  95. Example 1
  96. ---------
  97. Code corresponding to **Fig1** above follows, given remote server's address is
  98. ``pahaz.urfuclub.ru``, password authentication and randomly assigned local bind
  99. port.
  100. .. code-block:: python
  101. from sshtunnel import SSHTunnelForwarder
  102. server = SSHTunnelForwarder(
  103. 'alfa.8iq.dev',
  104. ssh_username="pahaz",
  105. ssh_password="secret",
  106. remote_bind_address=('127.0.0.1', 8080)
  107. )
  108. server.start()
  109. print(server.local_bind_port) # show assigned local port
  110. # work with `SECRET SERVICE` through `server.local_bind_port`.
  111. server.stop()
  112. Example 2
  113. ---------
  114. Example of a port forwarding to a private server not directly reachable,
  115. assuming password protected pkey authentication, remote server's SSH service is
  116. listening on port 443 and that port is open in the firewall (**Fig2**):
  117. .. code-block:: python
  118. import paramiko
  119. import sshtunnel
  120. with sshtunnel.open_tunnel(
  121. (REMOTE_SERVER_IP, 443),
  122. ssh_username="",
  123. ssh_pkey="/var/ssh/rsa_key",
  124. ssh_private_key_password="secret",
  125. remote_bind_address=(PRIVATE_SERVER_IP, 22),
  126. local_bind_address=('0.0.0.0', 10022)
  127. ) as tunnel:
  128. client = paramiko.SSHClient()
  129. client.load_system_host_keys()
  130. client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
  131. client.connect('127.0.0.1', 10022)
  132. # do some operations with client session
  133. client.close()
  134. print('FINISH!')
  135. Example 3
  136. ---------
  137. Example of a port forwarding for the Vagrant MySQL local port:
  138. .. code-block:: python
  139. from sshtunnel import open_tunnel
  140. from time import sleep
  141. with open_tunnel(
  142. ('localhost', 2222),
  143. ssh_username="vagrant",
  144. ssh_password="vagrant",
  145. remote_bind_address=('127.0.0.1', 3306)
  146. ) as server:
  147. print(server.local_bind_port)
  148. while True:
  149. # press Ctrl-C for stopping
  150. sleep(1)
  151. print('FINISH!')
  152. Or simply using the CLI:
  153. .. code-block:: console
  154. (bash)$ python -m sshtunnel -U vagrant -P vagrant -L :3306 -R 127.0.0.1:3306 -p 2222 localhost
  155. Example 4
  156. ---------
  157. Opening an SSH session jumping over two tunnels. SSH transport and tunnels
  158. will be daemonised, which will not wait for the connections to stop at close
  159. time.
  160. .. code-block:: python
  161. import sshtunnel
  162. from paramiko import SSHClient
  163. with sshtunnel.open_tunnel(
  164. ssh_address_or_host=('GW1_ip', 20022),
  165. remote_bind_address=('GW2_ip', 22),
  166. ) as tunnel1:
  167. print('Connection to tunnel1 (GW1_ip:GW1_port) OK...')
  168. with sshtunnel.open_tunnel(
  169. ssh_address_or_host=('localhost', tunnel1.local_bind_port),
  170. remote_bind_address=('target_ip', 22),
  171. ssh_username='GW2_user',
  172. ssh_password='GW2_pwd',
  173. ) as tunnel2:
  174. print('Connection to tunnel2 (GW2_ip:GW2_port) OK...')
  175. with SSHClient() as ssh:
  176. ssh.connect('localhost',
  177. port=tunnel2.local_bind_port,
  178. username='target_user',
  179. password='target_pwd',
  180. )
  181. ssh.exec_command(...)
  182. CLI usage
  183. =========
  184. ::
  185. $ sshtunnel --help
  186. usage: sshtunnel [-h] [-U SSH_USERNAME] [-p SSH_PORT] [-P SSH_PASSWORD] -R
  187. IP:PORT [IP:PORT ...] [-L [IP:PORT [IP:PORT ...]]]
  188. [-k SSH_HOST_KEY] [-K KEY_FILE] [-S KEY_PASSWORD] [-t] [-v]
  189. [-V] [-x IP:PORT] [-c SSH_CONFIG_FILE] [-z] [-n]
  190. [-d [FOLDER [FOLDER ...]]]
  191. ssh_address
  192. Pure python ssh tunnel utils
  193. Version 0.4.0
  194. positional arguments:
  195. ssh_address SSH server IP address (GW for SSH tunnels)
  196. set with "-- ssh_address" if immediately after -R or -L
  197. optional arguments:
  198. -h, --help show this help message and exit
  199. -U SSH_USERNAME, --username SSH_USERNAME
  200. SSH server account username
  201. -p SSH_PORT, --server_port SSH_PORT
  202. SSH server TCP port (default: 22)
  203. -P SSH_PASSWORD, --password SSH_PASSWORD
  204. SSH server account password
  205. -R IP:PORT [IP:PORT ...], --remote_bind_address IP:PORT [IP:PORT ...]
  206. Remote bind address sequence: ip_1:port_1 ip_2:port_2 ... ip_n:port_n
  207. Equivalent to ssh -Lxxxx:IP_ADDRESS:PORT
  208. If port is omitted, defaults to 22.
  209. Example: -R 10.10.10.10: 10.10.10.10:5900
  210. -L [IP:PORT [IP:PORT ...]], --local_bind_address [IP:PORT [IP:PORT ...]]
  211. Local bind address sequence: ip_1:port_1 ip_2:port_2 ... ip_n:port_n
  212. Elements may also be valid UNIX socket domains:
  213. /tmp/foo.sock /tmp/bar.sock ... /tmp/baz.sock
  214. Equivalent to ssh -LPORT:xxxxxxxxx:xxxx, being the local IP address optional.
  215. By default it will listen in all interfaces (0.0.0.0) and choose a random port.
  216. Example: -L :40000
  217. -k SSH_HOST_KEY, --ssh_host_key SSH_HOST_KEY
  218. Gateway's host key
  219. -K KEY_FILE, --private_key_file KEY_FILE
  220. RSA/DSS/ECDSA private key file
  221. -S KEY_PASSWORD, --private_key_password KEY_PASSWORD
  222. RSA/DSS/ECDSA private key password
  223. -t, --threaded Allow concurrent connections to each tunnel
  224. -v, --verbose Increase output verbosity (default: ERROR)
  225. -V, --version Show version number and quit
  226. -x IP:PORT, --proxy IP:PORT
  227. IP and port of SSH proxy to destination
  228. -c SSH_CONFIG_FILE, --config SSH_CONFIG_FILE
  229. SSH configuration file, defaults to ~/.ssh/config
  230. -z, --compress Request server for compression over SSH transport
  231. -n, --noagent Disable looking for keys from an SSH agent
  232. -d [FOLDER [FOLDER ...]], --host_pkey_directories [FOLDER [FOLDER ...]]
  233. List of directories where SSH pkeys (in the format `id_*`) may be found
  234. .. _Pahaz: https://github.com/pahaz
  235. .. _sshtunnel: https://pypi.python.org/pypi/sshtunnel
  236. .. _paramiko: http://www.paramiko.org/
  237. .. |CircleCI| image:: https://circleci.com/gh/pahaz/sshtunnel.svg?style=svg
  238. :target: https://circleci.com/gh/pahaz/sshtunnel
  239. .. |AppVeyor| image:: https://ci.appveyor.com/api/projects/status/oxg1vx2ycmnw3xr9?svg=true&passingText=Windows%20-%20OK&failingText=Windows%20-%20Fail
  240. :target: https://ci.appveyor.com/project/pahaz/sshtunnel
  241. .. |readthedocs| image:: https://readthedocs.org/projects/sshtunnel/badge/?version=latest
  242. :target: http://sshtunnel.readthedocs.io/en/latest/?badge=latest
  243. :alt: Documentation Status
  244. .. |coveralls| image:: https://coveralls.io/repos/github/pahaz/sshtunnel/badge.svg?branch=master
  245. :target: https://coveralls.io/github/pahaz/sshtunnel?branch=master
  246. .. |pyversions| image:: https://img.shields.io/pypi/pyversions/sshtunnel.svg
  247. .. |version| image:: https://img.shields.io/pypi/v/sshtunnel.svg
  248. :target: `sshtunnel`_
  249. .. |license| image:: https://img.shields.io/pypi/l/sshtunnel.svg
  250. :target: https://github.com/pahaz/sshtunnel/blob/master/LICENSE
  251. Online documentation
  252. ====================
  253. Documentation may be found at `readthedocs`_.
  254. .. _readthedocs: https://sshtunnel.readthedocs.org/
  255. CONTRIBUTORS
  256. ============
  257. - `Cameron Maske`_
  258. - `Gustavo Machado`_
  259. - `Colin Jermain`_
  260. - `JM Fernández`_ - (big thanks!)
  261. - `Lewis Thompson`_
  262. - `Erik Rogers`_
  263. - `Mart Sõmermaa`_
  264. - `Chronial`_
  265. - `Dan Harbin`_
  266. - `Ignacio Peluffo`_
  267. - `Niels Zeilemaker`_
  268. - `Georgy Rylov`_
  269. - `Eddie Chiang`_
  270. - `kkrasovskii`_
  271. CHANGELOG
  272. =========
  273. - v.0.4.0 (`Pahaz`_)
  274. + Change the daemon mod flag for all tunnel threads (is not fully backward compatible) to prevent unexpected hangs (`#219`_)
  275. + Add docker based end to end functinal tests for Mongo/Postgres/MySQL (`#219`_)
  276. + Add docker based end to end hangs tests (`#219`_)
  277. - v.0.3.2 (`Pahaz`_, `JM Fernández`_)
  278. + Fix host key directory detection
  279. + Unify default ssh config folder to `~/.ssh`
  280. - v.0.3.1 (`Pahaz`_)
  281. + Increase open connection timeout to 10 secods
  282. - v.0.3.0 (`Pahaz`_)
  283. + Change default with context behavior to use `.stop(force=True)` on exit (is not fully backward compatible)
  284. + Remove useless `daemon_forward_servers = True` hack for hangs prevention (is not fully backward compatible)
  285. + Set transport keepalive to 5 second by default (disabled for version < 0.3.0)
  286. + Set default transport timeout to 0.1
  287. + Deprecate and remove `block_on_close` option
  288. + Fix "deadlocks" / "tunneling hangs" (`#173`_, `#201`_, `#162`_, `#211`_)
  289. - v.0.2.2 (`Pahaz`_)
  290. + Add `.stop(force=True)` for force close active connections (`#201`_)
  291. - v.0.2.1 (`Pahaz`_, `Eddie Chiang`_ and `kkrasovskii`_)
  292. + Fixes bug with orphan thread for a tunnel that is DOWN (`#170`_)
  293. - v.0.2.0 (`Georgy Rylov`_)
  294. + Support IPv6 without proxy command. Use built-in paramiko create socket logic. The logic tries to use ipv6 socket family first, then ipv4 socket family.
  295. - v.0.1.5 (`JM Fernández`_)
  296. + Introduce `block_on_close` attribute
  297. - v.0.1.4 (`Niels Zeilemaker`_)
  298. + Allow loading pkeys from `~/.ssh`
  299. - v.0.1.3 (`Ignacio Peluffo`_ and others)
  300. + ``pkey_file`` parameter updated to accept relative paths to user folder using ``~``
  301. + Several bugfixes
  302. - v.0.1.2 (`JM Fernández`_)
  303. + Fix #77
  304. - v.0.1.1 (`JM Fernández`_)
  305. + Fix #72
  306. - v.0.1.0 (`JM Fernández`_)
  307. + Add `tunnel_bindings` property
  308. + Several bugfixes (#49, #56, #57, #59, #60, #62, #64, #66, ...)
  309. (`Pahaz`_, `JM Fernández`_)
  310. + Add TRACE logging level (`JM Fernández`_)
  311. + Code and tests refactoring (`JM Fernández`_)
  312. + Drop python3.2 support
  313. - v.0.0.8 (`JM Fernández`_)
  314. + Merge `#31`_: Support Unix domain socket (local) forwarding (`Dan Harbin`_)
  315. + Simplify API (`JM Fernández`_)
  316. + Add sphinx-based documentation (`JM Fernández`_)
  317. + Add ``allow_agent`` (fixes `#36`_, `#46`_) (`JM Fernández`_)
  318. + Add ``compression`` (`JM Fernández`_)
  319. + Add ``__str__`` method (`JM Fernández`_)
  320. + Add test functions (`JM Fernández`_)
  321. + Fix default username when not provided and ssh_config file is skipped (`JM Fernández`_)
  322. + Fix gateway IP unresolvable exception catching (`JM Fernández`_)
  323. + Minor fixes (`JM Fernández`_)
  324. + Add AppVeyor support (`JM Fernández`_)
  325. - v.0.0.7 (`JM Fernández`_)
  326. + Tunnels can now be stopped and started safely (`#41`_) (`JM Fernández`_)
  327. + Add timeout to SSH gateway and keep-alive messages (`#29`_) (`JM Fernández`_)
  328. + Allow sending a pkey directly (`#43`_) (`Chronial`_)
  329. + Add ``-V`` CLI option to show current version (`JM Fernández`_)
  330. + Add coverage (`JM Fernández`_)
  331. + Refactoring (`JM Fernández`_)
  332. - v.0.0.6 (`Pahaz`_)
  333. + add ``-S`` CLI options for ssh private key password support (`Pahaz`_)
  334. - v.0.0.5 (`Pahaz`_)
  335. + add ``ssh_proxy`` argument, as well as ``ssh_config(5)`` ``ProxyCommand`` support (`Lewis Thompson`_)
  336. + add some python 2.6 compatibility fixes (`Mart Sõmermaa`_)
  337. + ``paramiko.transport`` inherits handlers of loggers passed to ``SSHTunnelForwarder`` (`JM Fernández`_)
  338. + fix `#34`_, `#33`_, code style and docs (`JM Fernández`_)
  339. + add tests (`Pahaz`_)
  340. + add CI integration (`Pahaz`_)
  341. + normal packaging (`Pahaz`_)
  342. + disable check distenation socket connection by ``SSHTunnelForwarder.local_is_up`` (`Pahaz`_) [changed default behavior]
  343. + use daemon mode = False in all threads by default; detail_ (`Pahaz`_) [changed default behavior]
  344. - v.0.0.4.4 (`Pahaz`_)
  345. + fix issue `#24`_ - hide ssh password in logs (`Pahaz`_)
  346. - v.0.0.4.3 (`Pahaz`_)
  347. + fix default port issue `#19`_ (`Pahaz`_)
  348. - v.0.0.4.2 (`Pahaz`_)
  349. + fix Thread.daemon mode for Python < 3.3 `#16`_, `#21`_ (`Lewis Thompson`_, `Erik Rogers`_)
  350. - v.0.0.4.1 (`Pahaz`_)
  351. + fix CLI issues `#13`_ (`Pahaz`_)
  352. - v.0.0.4 (`Pahaz`_)
  353. + daemon mode by default for all threads (`JM Fernández`_, `Pahaz`_) - *incompatible*
  354. + move ``make_ssh_forward_server`` to ``SSHTunnelForwarder.make_ssh_forward_server`` (`Pahaz`_, `JM Fernández`_) - *incompatible*
  355. + move ``make_ssh_forward_handler`` to ``SSHTunnelForwarder.make_ssh_forward_handler_class`` (`Pahaz`_, `JM Fernández`_) - *incompatible*
  356. + rename ``open`` to ``open_tunnel`` (`JM Fernández`_) - *incompatible*
  357. + add CLI interface (`JM Fernández`_)
  358. + support opening several tunnels at once (`JM Fernández`_)
  359. + improve stability and readability (`JM Fernández`_, `Pahaz`_)
  360. + improve logging (`JM Fernández`_, `Pahaz`_)
  361. + add ``raise_exception_if_any_forwarder_have_a_problem`` argument for opening several tunnels at once (`Pahaz`_)
  362. + add ``ssh_config_file`` argument support (`JM Fernández`_)
  363. + add Python 3 support (`JM Fernández`_, `Pahaz`_)
  364. - v.0.0.3 (`Pahaz`_)
  365. + add ``threaded`` option (`Cameron Maske`_)
  366. + fix exception error message, correctly printing destination address (`Gustavo Machado`_)
  367. + fix ``pip install`` failure (`Colin Jermain`_, `Pahaz`_)
  368. - v.0.0.1 (`Pahaz`_)
  369. + ``SSHTunnelForwarder`` class (`Pahaz`_)
  370. + ``open`` function (`Pahaz`_)
  371. .. _Pahaz: https://github.com/pahaz
  372. .. _Cameron Maske: https://github.com/cameronmaske
  373. .. _Gustavo Machado: https://github.com/gdmachado
  374. .. _Colin Jermain: https://github.com/cjermain
  375. .. _JM Fernández: https://github.com/fernandezcuesta
  376. .. _Lewis Thompson: https://github.com/lewisthompson
  377. .. _Erik Rogers: https://github.com/ewrogers
  378. .. _Mart Sõmermaa: https://github.com/mrts
  379. .. _Chronial: https://github.com/Chronial
  380. .. _Dan Harbin: https://github.com/RasterBurn
  381. .. _Ignacio Peluffo: https://github.com/ipeluffo
  382. .. _Niels Zeilemaker: https://github.com/NielsZeilemaker
  383. .. _Georgy Rylov: https://github.com/g0djan
  384. .. _Eddie Chiang: https://github.com/eddie-chiang
  385. .. _kkrasovskii: https://github.com/kkrasovskii
  386. .. _#13: https://github.com/pahaz/sshtunnel/issues/13
  387. .. _#16: https://github.com/pahaz/sshtunnel/issues/16
  388. .. _#19: https://github.com/pahaz/sshtunnel/issues/19
  389. .. _#21: https://github.com/pahaz/sshtunnel/issues/21
  390. .. _#24: https://github.com/pahaz/sshtunnel/issues/24
  391. .. _#29: https://github.com/pahaz/sshtunnel/issues/29
  392. .. _#31: https://github.com/pahaz/sshtunnel/issues/31
  393. .. _#33: https://github.com/pahaz/sshtunnel/issues/33
  394. .. _#34: https://github.com/pahaz/sshtunnel/issues/34
  395. .. _#36: https://github.com/pahaz/sshtunnel/issues/36
  396. .. _#41: https://github.com/pahaz/sshtunnel/issues/41
  397. .. _#43: https://github.com/pahaz/sshtunnel/issues/43
  398. .. _#46: https://github.com/pahaz/sshtunnel/issues/46
  399. .. _#170: https://github.com/pahaz/sshtunnel/issues/170
  400. .. _#201: https://github.com/pahaz/sshtunnel/issues/201
  401. .. _#162: https://github.com/pahaz/sshtunnel/issues/162
  402. .. _#173: https://github.com/pahaz/sshtunnel/issues/173
  403. .. _#201: https://github.com/pahaz/sshtunnel/issues/201
  404. .. _#211: https://github.com/pahaz/sshtunnel/issues/211
  405. .. _#219: https://github.com/pahaz/sshtunnel/issues/219
  406. .. _detail: https://github.com/pahaz/sshtunnel/commit/64af238b799b0e0057c4f9b386cda247e0006da9#diff-76bc1662a114401c2954deb92b740081R127