Pyinfra: proxycommand not being used

Created on 15 Apr 2021  路  7Comments  路  Source: Fizzadar/pyinfra

Describe the bug

My ssh config file uses a Match directive to set the value of ProxyCommand. This works with openssh, and also works with paramiko if I run it by hand, but doesn't work from pyinfra.

To Reproduce

Install pyinfra and paramiko[invoke] (for Match support). Create an ssh config like this:

Match host <hostname>
  ProxyCommand <command>

Then try to execute a simple command on :
pyinfra exec -- whoami

Expected behavior

I expect pyinfra to connect and execute "whoami" and show me the output.

Meta

pyinfra was installed into a pristine virtualenv, using pip.

pyinfra --support
--> Support information:

    If you are having issues with pyinfra or wish to make feature requests, please
    check out the GitHub issues at https://github.com/Fizzadar/pyinfra/issues .
    When adding an issue, be sure to include the following:

    System: Darwin
      Platform: macOS-11.2.3-x86_64-i386-64bit
      Release: 20.3.0
      Machine: x86_64
    pyinfra: v1.3.10
    Executable: /Users/anandb/.venv/pyinfra/bin/pyinfra
    Python: 3.8.2 (CPython, Clang 12.0.0 (clang-1200.0.32.29))
pyinfra -vv --debug <hostname> exec -- whoami
--> Loading config...
--> Loading inventory...
    [pyinfra_cli.inventory] Creating fake inventory...

--> Connecting to hosts...
    [pyinfra.api.connectors.ssh] Connecting to: <hostname> ({'allow_agent': True, 'look_for_keys': True, 'hostname': '<hostname>', 'timeout': 10})
    [hostname] Could not connect ([Errno None] Unable to connect to port 22 on A.B.C.D)
    [pyinfra.api.state] Failing hosts: hostname
--> pyinfra error: No hosts remaining!
Bug

All 7 comments

Hi @anandb-ripencc! Thanks for the report here - I believe this could be related to the customised SSH client, which actually exists to support proxyjumping. Great to hear the proxycommand does work with Paramiko, it's possible the original proxyjump issue has been solved in paramiko, in which case this whole custom client can be removed. If not I'll look into how to fix the match support!

I believe the issue here is the Match support, added in paramiko 2.7; pyinfra contains an out of date inlined version of SSHConfig with support for include directives. I'm not a fan of this because this exact situation occurrs.

I'm going to remove and reimplement include support by inlining the included files before parsing, leaving the parsing back to paramiko. Will also bump the minimum paramiko version to 2.7.

Thanks for this confirmation Nick! I shall await a new release of pyinfra with this fix.

I've just released this in v1.3.11!

I just tried out this new version, and it failed on me with a giant backtrace! I've attached the backtrace here.

pyinfra-debug.log

@anandb-ripencc this looks like it's caused by Match exec ... support from invoke, I believe this is the error: https://github.com/gevent/gevent/issues/1268

Disabling gevent patching of thread/subprocess does appear to fix the issue, but also breaks pyinfra parallelism and asynchronous speed :/ I've created a new issue to track this, need to think about the options here.

Thanks for the update and explanation. I'll follow #574 for news.

Was this page helpful?
0 / 5 - 0 ratings