Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python3: Fabric 2.4.0 ProxyJump and ssh_config

The documentation leaves a lot to be desired when wanting to use ssh_config. Can someone provide proof of concept code on how to actually import the ssh_config?

To add on to my lack of understanding, I'm also not sure why the following code does not work since it appears my ssh_config is loaded. The only way to get into Host C is through Host B. The only way to get into Host B is through Host A. I am using ProxyJump.

Non-working example:

>>> from fabric import Connection
>>> c = Connection('HOST_C')
>>> print(c)
<Connection host=HOST_C gw=proxyjump>
>>> print(c.ssh_config)
{'serveraliveinterval': '60', 'tcpkeepalive': 'yes', 'stricthostkeychecking': 'no', 'forwardagent': 'yes', 'proxyjump': 'HOST_A,HOST_B', 'hostname': 'HOST_C'}
>>> c.run('hostname')
Secsh channel 0 open FAILED: open failed: Administratively prohibited
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<decorator-gen-3>", line 2, in run
  File "/Users/username/code/fabric/venv/lib/python3.7/site-packages/fabric/connection.py", line 29, in opens
    self.open()
  File "/Users/username/code/fabric/venv/lib/python3.7/site-packages/fabric/connection.py", line 608, in open
    kwargs["sock"] = self.open_gateway()
  File "/Users/username/code/fabric/venv/lib/python3.7/site-packages/fabric/connection.py", line 640, in open_gateway
    self.gateway.open()
  File "/Users/username/code/fabric/venv/lib/python3.7/site-packages/fabric/connection.py", line 608, in open
    kwargs["sock"] = self.open_gateway()
  File "/Users/username/code/fabric/venv/lib/python3.7/site-packages/fabric/connection.py", line 655, in open_gateway
    src_addr=("", 0),
  File "/Users/username/code/fabric/venv/lib/python3.7/site-packages/paramiko/transport.py", line 944, in open_channel
    raise e
paramiko.ssh_exception.ChannelException: (1, 'Administratively prohibited')

Working example:

>>> from fabric import Connection
>>> d = Connection('HOST_C', gateway=Connection('HOST_B', gateway=Connection('HOST_A')))
>>> print(d)
<Connection host=HOST_C gw=proxyjump>
>>> print(d.ssh_config)
{'serveraliveinterval': '60', 'tcpkeepalive': 'yes', 'stricthostkeychecking': 'no', 'forwardagent': 'yes', 'proxyjump': 'HOST_A,HOST_B', 'hostname': 'HOST_C'}
>>> d.run('hostname')
HOST_C
<Result cmd='hostname' exited=0>

On an unrelated note, as of python 3.7.1, I am receiving the following errors with Paramiko. The cryptography package is on version 2.5. Any insight on why this might be occurring?

/Users/username/code/virtenv3/lib/python3.7/site-packages/paramiko/ecdsakey.py:164: CryptographyDeprecationWarning: Support for unsafe construction of public numbers from encoded data will be removed in a future version. Please use EllipticCurvePublicKey.from_encoded_point
  self.ecdsa_curve.curve_class(), pointinfo
/Users/username/code/virtenv3/lib/python3.7/site-packages/paramiko/kex_ecdh_nist.py:39: CryptographyDeprecationWarning: encode_point has been deprecated on EllipticCurvePublicNumbers and will be removed in a future version. Please use EllipticCurvePublicKey.public_bytes to obtain both compressed and uncompressed point encoding.
  m.add_string(self.Q_C.public_numbers().encode_point())
/Users/username/code/virtenv3/lib/python3.7/site-packages/paramiko/kex_ecdh_nist.py:96: CryptographyDeprecationWarning: Support for unsafe construction of public numbers from encoded data will be removed in a future version. Please use EllipticCurvePublicKey.from_encoded_point
  self.curve, Q_S_bytes
/Users/username/code/virtenv3/lib/python3.7/site-packages/paramiko/kex_ecdh_nist.py:111: CryptographyDeprecationWarning: encode_point has been deprecated on EllipticCurvePublicNumbers and will be removed in a future version. Please use EllipticCurvePublicKey.public_bytes to obtain both compressed and uncompressed point encoding.
  hm.add_string(self.Q_C.public_numbers().encode_point())
like image 772
Fauxsys Avatar asked Sep 27 '26 06:09

Fauxsys


1 Answers

see workaround on paramiko's github https://github.com/paramiko/paramiko/issues/1369#issuecomment-456940895 workaround

like image 187
anapsix Avatar answered Sep 29 '26 21:09

anapsix



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!