Skip to content

salt remote shell #8249

Closed
Closed

Description

@veetow

Hello,

I would personally find it extremely useful if salt provided a module for getting a remote command line shell (bash/powershell/whatever) on a minion. It should work something like this:

$ salt 'minion' shell.interactive user=root
[root@minion ~]#

The module should return an error if a glob or pattern is used which returns more than one minion, eg:

$ salt '*' shell.interactive user=root
Multiple minions matched the target. No command was sent, no jid was assigned.

Rationale:
Currently, my company uses HP Server Automation (formerly Opsware) which provides this feature via a command line tool called rosh. rosh allows you to open an interactive shell via the opsware agent with its own permissions model and associated ACLs.

I am very much willing to hack at this if we can agree upon its usefulness, feasibility, and functional requirements.

Thanks!

Activity

  1. basepi commented on Nov 4, 2013

    @basepi
    Contributor

    This would be cool! Thanks for the request!

  2. veetow commented on Nov 5, 2013

    @veetow
    Author

    Sure thing. Any thoughts on implementation details?

  3. UtahDave commented on Nov 5, 2013

    @UtahDave
    Contributor

    @veetow I've actually been thinking about this, too.

    Would it be too complicated to automatically create a reverse ssh tunnel and drop the user into the shell?

    What were your thoughts on implementation?

  4. veetow commented on Nov 5, 2013

    @veetow
    Author

    I'm not quite sure honestly. Given the encrypted master/minion communication all occurs via the push/pull queues, this seems like a non trivial problem to solve. And we can't necessarily rely on ssh since it might not exist on the minion (eg: Windows).

  5. veetow commented on Nov 5, 2013

    @veetow
    Author

    Unless we used something like paramiko on both ends...

  6. moreda commented on Nov 6, 2013

    @moreda
    Contributor

    Hi,

    In my case (and as @UtahDave suggested) the quick solution was reverse ssh tunnels:

    1. Configure a special user –let's call it the autossh user[1]– in the minion with a ssh key pair that allows logging into a sandbox ssh server. This user has to have the minimal privileges to be able to start a reverse ssh tunnel. The sandbox ssh server could be the same salt server, but it depends on your security restrictions and criteria.

    2. Once that's done, you could simply start a reverse ssh tunnel from the minion to the sandbox ssh server –let's assume it's the salt server– using:

      salt 'minion-id' cmd.run runas=autossh 'ssh -f salt -R2201:127.0.0.1:22 sleep 30' --async
      

      ... and you have 30 secs to log in using the just established tunnel at 2201 port :-)

    [1]: paying homage to good old autossh

  7. veetow commented on Nov 6, 2013

    @veetow
    Author

    That would work in a pinch, of course, but it's far from the clean, built-in, and ACL'd solution that I'm hoping for.

  8. moreda commented on Nov 6, 2013

    @moreda
    Contributor

    Yes, I totally agree with you that it could more integrated with a shell execution module , but as you wisely said it's a non-trivial problem.

    Somehow "canning" the reverse tunnel workaround as a way to have an interactive shell in a minion could be easier to implement. All in all, I think that the need of an interactive shell in a minion should be a last resource tool, because it defeats the "parallel and asynchronous" nature of a saltstack admin environment.

    Anyway, just my 2cents :-)

  9. veetow commented on Nov 6, 2013

    @veetow
    Author

    I'm happy for all the 2 cents. 👍

    However, I do disagree that a built in interactive shell module should be a last resort or that it somehow conflicts with the ethos of saltstack. The "parallel and asynchronous" nature of saltstack job execution need not be diminished by this additional proposed functionality. Opsware provides both features and, via my own personal experience, having both available in conjunction can be very useful when orchestrating complex logic.

    I think a corollary is the Peer-to-peer functionality. To me, that falls under this same type of perhaps not immediately fundamental functionality that greatly improves the usability of saltstack in certain scenarios.

  10. moreda commented on Nov 6, 2013

    @moreda
    Contributor

    I do agree that new functionalities won't hurt... and if this one is implemented, I'll be glad to use it instead of the workaround when needed :-)

  11. veetow commented on Nov 7, 2013

    @veetow
    Author

    Here's my current thinking, which is more or less what @moreda and @UtahDave were getting at, folded into the current master/minion communication process:

    image

    I think the beauty of using something like Paramiko is that we'd be implementing the client and server bits so that the saltstack-specific permissioning, certs, etc would all be baked in.

    Thoughts? Am I on the right track or way off base?

  12. kaithar commented on Nov 28, 2013

    @kaithar
    Contributor

    Thinking laterally for a moment, there are two distinct use cases...

    • 1/ a true shell that can run any interactive process.
    • 2/ an "emulated" shell with more restrictive requirements but with more robust handling.

    What's discussed thus far is basically 1... though as an alternative to reverse tunnel, you could write a module that controls the specific OS's equiv of a pty and dumb link the two, by passing the need for ssh and any firewall considerations.

    Number 2 has interesting notions though. On the master side you're basically building a shell program (although cookie if you figure out how to wrap a real shell, I bet it's possible) that you can run commands on, and it fires them off to the minion... like an interactive version of cmd.run, with added bonus:

    • you can restrict the command set to control what can be done and apply acl ... basically remote restricted shell
    • the shell is the same regardless of what the end system is, so you could have the same shell interface talking to windows as you do for linux
    • since it's routed over salt, the shell could operate in a disconnected form for shaky network connections (ddos conditions?).
    • salt also handles the authentication and connectivity, so no extra firewall considerations in either direction and no extra user authentication management on the minion side.
    • parallel shell isn't impossible, maybe something along the line of tentakel?
    • I'd envision editing being done in a similar way to sudoedit ... though that might not be practical for large files.
  13. nikicat commented on Mar 14, 2014

    @nikicat
    Contributor

    👍

  14. adamleff commented on Apr 3, 2014

    @adamleff

    +1. This would be immensely helpful.

  15. rominf commented on May 25, 2014

    @rominf
    Contributor

    👍 I would like to have this feature too.
    @kaithar, I think that building own shell emulator would be harder than the first variant. In my opinion "true" shell requires ncurses support (I want to use programs like vim and yast). Good auto-completion is also an issue (many users switched to zsh because of good auto-completion. I personally prefer fish).

  16. 10 remaining items

  17. h0jeZvgoxFepBQ2C commented on Jul 21, 2016

    @h0jeZvgoxFepBQ2C

    +1

  18. steverweber commented on Jul 22, 2016

    @steverweber
    Contributor

    think the "reverse ssh tunnel" tunnel idea would be nice... perhaps make a module and salt-runner that automates most of the dirty work.

    if we want something python based that perhaps could be wired over the salt communication pipes... should look at jupyter console code (linux/mac only).
    https://github.com/jupyter/jupyter_console

  19. dtmateojr commented on Jan 16, 2018

    @dtmateojr

    Hi there,

    Reviving a zombie thread here...

    I have coded something like a pseudo-interactive shell for saltstack. At the moment it simulates being in a real shell and does some very crude tab autocompletion and allows remote editing of files using vim. Hoping that someone would be interested in improving it. I am no programmer so please bear with me.

    https://github.com/dtmateojr/shalt

  20. angeloudy commented on Jun 18, 2018

    @angeloudy
    Contributor

    An interactive shell would be very useful. In our environment, salt master manages some minions in different locations and there are firewalls between them so I can't ssh to the minions directly. To run a command on the minion, I have to execute salt 'minion_id' cmd.run 'something', which is not effective if I want to run a lot of commands.

  21. stale commented on Oct 1, 2019

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

    If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

  22. godlike64 commented on Oct 2, 2019

    @godlike64

    Are there any plans for this? Still interested in this. Sometimes after a power outage at home I can recover my systems if salt and internet are back up, but it's pretty crude and this would save a lot of trouble.

    Is it feasible? Would @dtmateojr 's work be mergeable?

  23. stale commented on Oct 2, 2019

    @stale

    Thank you for updating this issue. It is no longer marked as stale.

  24. dtmateojr commented on Oct 2, 2019

    @dtmateojr

    @godlike64 It's ok if my code is not merged. It's just a single file anyway. Download the shalt script, put it in your salt master server and execute it directly.

    BTW, I have updated the README to show a sample session that demonstrates how I use this tool to manage hundreds of servers in our environment.

    Cheers,

  25. nswalters commented on Oct 3, 2019

    @nswalters

    👍

  26. stale commented on Jan 7, 2020

    @stale

    This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

    If this issue is closed prematurely, please leave a comment and we will gladly reopen the issue.

  27. waynegemmell commented on Aug 14, 2023

    @waynegemmell
    Contributor

    I too would like this as currently I get the IP address from the grains and then ssh from another terminal. It's just a convenience thing for me but possibly useful for recovery.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    CoreFeaturestale

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions