StackStorm / st2

StackStorm (aka "IFTTT for Ops") is event-driven automation for auto-remediation, incident responses, troubleshooting, deployments, and more for DevOps and SREs. Includes rules engine, workflow, 160 integration packs with 6000+ actions (see https://exchange.stackstorm.org) and ChatOps. Installer at https://docs.stackstorm.com/install/index.html
https://stackstorm.com/
Apache License 2.0
6.06k stars 746 forks source link

Paramiko error: encountered RSA key, expected OPENSSH key #5781

Open garadar opened 1 year ago

garadar commented 1 year ago

SUMMARY

I succeed to run core.remote (ssh conf is okay) but action linux.wait_for_ssh provided by st2 installation return error:

Paramiko error: encountered RSA key, expected OPENSSH key

STACKSTORM VERSION

(cluster)-[xxx@admxx ~]$ st2 --version 
st2 3.7.0, on Python 3.6.8
OS, environment, install method
(cluster)-[xxx@admxx ~]$ cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core)

Steps to reproduce the problem

Requirement:

Steps:

  1. Run: st2 run core.remote hosts=node300 cmd=whoami -> OK
  2. Run: st2 run linux.wait_for_ssh hostname=node300 sleep_delay=2 retries=2 -> KO

Expected Results

My ssh config is good:

(cluster)-[xxx@admxx ~]$ su - stanley
(cluster)-[stanley@admxx ~]$ 
(cluster)-[stanley@admxx~]$ ssh node300
(cluster)-[stanley@node300 ~]$ 

core.remote is working:

(cluster)-[xxx@admxx ~]$ st2 run core.remote  hosts=node300 cmd=whoami
.
id: 635111284ba4844998622a74
action.ref: core.remote
context.user: st2admin
parameters: 
  cmd: whoami
  hosts: node300
status: succeeded
start_timestamp: Thu, 20 Oct 2022 09:13:12 UTC
end_timestamp: Thu, 20 Oct 2022 09:13:13 UTC
result: 
  node300:
    failed: false
    return_code: 0
    stderr: ''
    stdout: stanley
    succeeded: true

Actual Results

the action linux.wait_for_ssh return the error:

Paramiko error: not a valid OPENSSH private key file

(cluster)-[xxx@admxx ~]$ st2 run linux.wait_for_ssh hostname=node300 sleep_delay=2  retries=2
id: 635114334ba4844998622a7a
action.ref: linux.wait_for_ssh
context.user: st2admin
parameters: 
  hostname: node300
  retries: 2
  sleep_delay: 2
status: failed
start_timestamp: Thu, 20 Oct 2022 09:26:11 UTC
end_timestamp: Thu, 20 Oct 2022 09:26:15 UTC
result: 
  exit_code: 1
  result: None
  stderr: "st2.actions.python.BaseAction: INFO     Neither "password" nor "keyfile" parameter provided, defaulting to using "/home/stanley/.ssh/id_rsa.pub" key file
st2.actions.python.BaseAction: DEBUG    SSH connection attempt: 1
st2.actions.python.BaseAction: INFO     Attempt 1 failed (Error connecting to host node300 with connection parameters {'hostname': 'node300', 'allow_agent': False, 'look_for_keys': False, 'timeout': 3, 'username': 'stanley', 'port': 22, 'key_filename': '/home/stanley/.ssh/id_rsa.pub'}.Paramiko error: not a valid OPENSSH private key file.), sleeping for 2 seconds...
st2.actions.python.BaseAction: DEBUG    SSH connection attempt: 2
st2.actions.python.BaseAction: INFO     Attempt 2 failed (Error connecting to host node300 with connection parameters {'hostname': 'node300', 'allow_agent': False, 'look_for_keys': False, 'timeout': 3, 'username': 'stanley', 'port': 22, 'key_filename': '/home/stanley/.ssh/id_rsa.pub'}.Paramiko error: not a valid OPENSSH private key file.), sleeping for 2 seconds...
Traceback (most recent call last):
  File "/opt/stackstorm/st2/lib/python3.6/site-packages/python_runner/python_action_wrapper.py", line 395, in <module>
    obj.run()
  File "/opt/stackstorm/st2/lib/python3.6/site-packages/python_runner/python_action_wrapper.py", line 214, in run
    output = action.run(**self._parameters)
  File "/opt/stackstorm/packs/linux/actions/wait_for_ssh.py", line 71, in run
    raise Exception("Exceeded max retries (%s)" % (retries))
Exception: Exceeded max retries (2)
"
  stdout: ''

Thanks! :)

arm4b commented 1 year ago

Thanks for reporting this, sounds like a bug!

The code for linux.wait_for_ssh action is here: https://github.com/StackStorm/st2/blob/master/contrib/linux/actions/wait_for_ssh.py and contributions to fix the issue are welcome!

nirutgupta commented 1 year ago

@garadar where are you keeping the ssh files ?

garadar commented 1 year ago

@nirutgupta for the user stanley in $HOME/.ssh