You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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!
Reacted by Dmitrii Okunev, Gabriel Le Breton, Jakub, Konstantin Baikov, Matthijs Kooijman, Dylan Lloyd, Roman Inflianskas, Nils Ballmann, Jonathan Wilbur, Gianluca Fioletti and 7 more
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).
In my case (and as @UtahDave suggested) the quick solution was reverse ssh tunnels:
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.
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 :-)
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.
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.
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:
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?
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.
👍 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).
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.
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.
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.
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?
@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.
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.
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.
Activity
basepi commentedon Nov 4, 2013
This would be cool! Thanks for the request!
veetow commentedon Nov 5, 2013
Sure thing. Any thoughts on implementation details?
UtahDave commentedon Nov 5, 2013
@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?
veetow commentedon Nov 5, 2013
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).
veetow commentedon Nov 5, 2013
Unless we used something like paramiko on both ends...
moreda commentedon Nov 6, 2013
Hi,
In my case (and as @UtahDave suggested) the quick solution was reverse ssh tunnels:
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.
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:
... and you have 30 secs to log in using the just established tunnel at 2201 port :-)
[1]: paying homage to good old autossh
veetow commentedon Nov 6, 2013
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.
moreda commentedon Nov 6, 2013
Yes, I totally agree with you that it could more integrated with a
shellexecution 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 :-)
veetow commentedon Nov 6, 2013
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.
moreda commentedon Nov 6, 2013
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 :-)
veetow commentedon Nov 7, 2013
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:
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?
kaithar commentedon Nov 28, 2013
Thinking laterally for a moment, there are two distinct use cases...
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:
nikicat commentedon Mar 14, 2014
👍
adamleff commentedon Apr 3, 2014
+1. This would be immensely helpful.
rominf commentedon May 25, 2014
👍 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
ncursessupport (I want to use programs likevimandyast). Good auto-completion is also an issue (many users switched tozshbecause of good auto-completion. I personally preferfish).10 remaining items
h0jeZvgoxFepBQ2C commentedon Jul 21, 2016
+1
steverweber commentedon Jul 22, 2016
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
dtmateojr commentedon Jan 16, 2018
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
angeloudy commentedon Jun 18, 2018
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.stale commentedon Oct 1, 2019
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.
godlike64 commentedon Oct 2, 2019
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?
stale commentedon Oct 2, 2019
Thank you for updating this issue. It is no longer marked as stale.
dtmateojr commentedon Oct 2, 2019
@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,
nswalters commentedon Oct 3, 2019
👍
stale commentedon Jan 7, 2020
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.
waynegemmell commentedon Aug 14, 2023
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.