sassoftware / saspy

A Python interface module to the SAS System. It works with Linux, Windows, and Mainframe SAS as well as with SAS in Viya.
https://sassoftware.github.io/saspy
Other
367 stars 149 forks source link

ssh parameter list #460

Closed saspyrate closed 2 years ago

saspyrate commented 2 years ago

It's me again with another (small) feature request. Hope that's alright ;-)

Would it be possible to allow a list in the configuration for the ssh option? This would make it possible to use sshpass and other stuff.

Currently, the example configuration looks as follow:

ssh      = {'saspath' : '/opt/sasinside/SASHome/SASFoundation/9.4/bin/sas_en',
            'ssh'     : '/usr/bin/ssh',
            'host'    : 'remote.linux.host', 
            'encoding': 'latin1',
            'options' : ["-fullstimer"]
            }

I'd like to be able to change it to the following:

ssh      = {'saspath' : '/opt/sasinside/SASHome/SASFoundation/9.4/bin/sas_en',
            'ssh'     : ['/usr/bin/sshpass', '-p', '"TOP_SECRET_PASSWORD"', '/usr/bin/ssh'],
            'host'    : 'remote.linux.host', 
            'encoding': 'latin1',
            'options' : ["-fullstimer"]
            }
tomweber-sas commented 2 years ago

So, I've looked into this sshpass and it does seem to work, from my linux system at least (it doesn't exist on my pc). You mention 'other stuff'; are there other things really or just this sshpass command? I don't think just any arbitrary command and options is a good way to go on this. Just anything won't really work, but this is an ssh specific command to use w/ ssh, so it does make sense. Given that I need to build out the parameters for the fork and exec, just so, in python, I'd prefer a separate key for this, like sshpass, to augment the ssh key that will still need to be provided and is still the key that determines the SSH access method.

I've prototyped this using sshpassfor the executable (/usr/bin/sshpass or whatever), andsshpassparms` for the list of whichever parms you want to use with it; there are several different choices, so a list for those is what I need. So, like this:

sshp = {'saspath': '/opt/sasinside/SASHome/SASFoundation/9.4/bin/sas_u8', 
        'host': 'tom64-4.unx.sas.com', 
        'ssh': '/usr/bin/ssh', 
        'sshpass': '/usr/bin/sshpass', 
        #'sshpass'parms: ['-f', '/file/with/password'],
        'sshpass'parms: ['-p', 'mypassword'],
        #'sshpass'parms: ['-e'],   # pw is in env var SSHPASS
       }

I've pushed this to main, so you can try it out and see if it works for you like expected. Let me know what you think. Tom

saspyrate commented 2 years ago

Perfect, that lets me do what I was looking for. I just tested it. Thank you for the quick implementation!

You mention 'other stuff'; are there other things really or just this sshpass command?

I've got my own small wrapper script around sshpass to fetch the password. But I can just pass that and its arguments to the newly introduced options sshpassand sshpassparms. So everything's fine.

tomweber-sas commented 2 years ago

Cool. And this is actually a nice way to get around having to set up passwordless ssh, especially in a container or other temporary environment. Having the options to provide a pw through automated ways is helpful; and it seems to work right, which is the biggest deal :)

tomweber-sas commented 2 years ago

I'm going to close this. I've just built a new version (V4.3.0) which includes this feature, so it's available now here, on Pypi, and soon on Conda (once the bot notices and builds). Tom