Skip to content
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

Close proxycommand socket when its not needed anymore and resolve ssh zombies #4881

Merged
merged 12 commits into from
Apr 6, 2020

Conversation

eedgar
Copy link
Contributor

@eedgar eedgar commented Mar 9, 2020

Needs confirmation that this is written correctly from @eedgar (-- @punkrokk )
Paramiko has a bug that is not patched, that causes ssh proxy connected to not get closed.

eg. zombie ssh processes are left from the proxycommand

If I were to modify my st2.conf file as follows:

#/bin/bash
crudini --set /etc/st2/st2.conf ssh_runner use_ssh_config True
crudini --set /etc/st2/st2.conf ssh_runner ssh_config_file_path /root/.ssh/config
chown -R root:root /root/.ssh/*
chmod 600 /root/.ssh/config
chmod 600 /root/.ssh/id_rsa
  Host 10.1.*
    ProxyCommand ssh -o StrictHostKeyChecking=no bastion nc %h %p
    IdentityFile ~/.ssh/id_rsa
    User stanley

  Host bastion
    Hostname bastion.example.com
    IdentityFile ~/.ssh/id_rsa
    User stanley

We end up with zombie ssh connections. Paramiko has a bug, but it is not patched: paramiko/paramiko#789

This PR checks for sockets that are left open and closes them.

@pull-request-size pull-request-size bot added the size/S PR that changes 10-29 lines. Very easy to review. label Mar 9, 2020
@CLAassistant
Copy link

CLAassistant commented Mar 9, 2020

CLA assistant check
All committers have signed the CLA.

@punkrokk punkrokk requested review from arm4b, blag and nmaludy March 9, 2020 18:52
@punkrokk punkrokk added this to the 3.2.0 milestone Mar 9, 2020
@punkrokk
Copy link
Member

punkrokk commented Mar 9, 2020

@StackStorm/maintainers Can someone comment on how to update the Unit tests based on this find?

StackStorm/st2docs#965

@punkrokk punkrokk added the bug label Mar 9, 2020
@punkrokk punkrokk requested a review from a team March 9, 2020 19:03
@punkrokk
Copy link
Member

punkrokk commented Mar 9, 2020

@eedgar are you able to help us update the CI tests for this?

Copy link
Contributor

@blag blag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I spotted a bug preventing this from being adequately run and tested, as well as a lint issue.

Check out st2actions/tests/unit/test_paramiko_ssh.py for examples of unit tests of this code.

st2common/st2common/runners/paramiko_ssh.py Outdated Show resolved Hide resolved
st2common/st2common/runners/paramiko_ssh.py Show resolved Hide resolved
st2common/st2common/runners/paramiko_ssh.py Outdated Show resolved Hide resolved
Co-Authored-By: blag <blag@users.noreply.github.com>
@punkrokk punkrokk self-requested a review April 2, 2020 01:00
Copy link
Member

@punkrokk punkrokk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@blag blag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking much better. Would like some TODO comments so we can come back and improve this code once we're developing for Python 3.6+ only (eg: after ST2 v3.2 is released, which should be "soon").

st2actions/tests/unit/test_paramiko_ssh.py Show resolved Hide resolved
st2actions/tests/unit/test_paramiko_ssh.py Show resolved Hide resolved
Copy link
Contributor

@blag blag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

CHANGELOG.rst Outdated Show resolved Hide resolved
@eedgar eedgar requested a review from punkrokk April 3, 2020 22:08
CHANGELOG.rst Outdated Show resolved Hide resolved
@arm4b
Copy link
Member

arm4b commented Apr 6, 2020

Merging.

Thanks @eedgar for the contribution and @punkrokk @blag for the review and great effort in getting the PR reach the quality bar!

@arm4b arm4b merged commit 63dfed5 into StackStorm:master Apr 6, 2020
@punkrokk
Copy link
Member

punkrokk commented Apr 6, 2020

Really thanks to @eedgar for the 2nd effort here!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug size/S PR that changes 10-29 lines. Very easy to review.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants