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

Added ability to specify agent socket #360

Merged
merged 1 commit into from Apr 28, 2016

Conversation

alongoldboim
Copy link
Contributor

@alongoldboim alongoldboim commented Apr 27, 2016

Adding the option to specify a socket that will be used, this is useful in case we have multiple agents running and multiple users using the net-ssh at the same time (that's why changing the ENV variable is not really practical).

@mfazekas
Copy link
Collaborator

Thanks much for the PR, can you please describe your usecase?
Rather than passing a connection have you considered passing a factory that makes the connection?

@alongoldboim
Copy link
Contributor Author

@mfazekas didn't quite get your comment, could you elaborate please?

@mfazekas
Copy link
Collaborator

Sorry i was not reading your change carefully enough. I assumed agent_socket is an actual socket, but since you're passing it to agent_socket_factory.open it's likely meant to be an address rather than socket.

So your version is this:

Net::SSH::start(user,host,agent_socket_addres:'/foo/bar')

what i was asking is this:

Net::SSH::start(user,host,agent_socket_factory: ->{ UNIXSocket.open('/foo/bar') })

But again, please explain your usecase.

@alongoldboim
Copy link
Contributor Author

alongoldboim commented Apr 27, 2016

Adding the option to specify a socket that will be used, this is useful in case we have multiple agents running and multiple users using the net-ssh at the same time (that's why changing the ENV variable is not really practical).

I've placed the desc later on :).
@mfazekas thanks for the review, added needed fixes.

@mfazekas
Copy link
Collaborator

multiple users with multiple agents sounds an esoteric usecase.

I find custom_socket_factory name confusing. We only use it for agent connections, so the name would be better to reflect that.

@alongoldboim
Copy link
Contributor Author

alongoldboim commented Apr 27, 2016

Its a multi tenant app that uses net-ssh for some actions, the user inserts his private key, hence all the users passwords will be cached on the same ssh-agent which is a security issue.
The name you suggested 'agent_socket_factory' is the name of the existing function, so i can't use it, what other name do you suggest?

@simon3z
Copy link

simon3z commented Apr 27, 2016

multiple users with multiple agents sounds an esoteric usecase.

Hi @mfazekas think of a multi-tenant management application.
You want different users to be able to manage hosts belonging to their tenant... but you wouldn't want to collect all the keys in the same ssh-agent.

And remember that "multiple users with multiple agents" is the original design of ssh-agent. In a linux machine you run an ssh-agent per user, because ssh-agent is not multi-tenant itself and you don't want to cache all the keys in a single place for all the users.

@mfazekas
Copy link
Collaborator

mfazekas commented Apr 27, 2016

I'd suggest renamig that method it can be just socket_class it's a private method anyway. And have the option named as agent_socket_factory or agent_connection_factory.

@mfazekas
Copy link
Collaborator

@simon3z, @alongoldboim thanks for clarifying the usecase, it makes sense that way.

@alongoldboim
Copy link
Contributor Author

@mfazekas Needed changes were made and tests fixed, please review again :)

@@ -357,7 +357,7 @@ def auth_agent_channel(session, channel, packet)
channel[:invisible] = true

begin
agent = Authentication::Agent.connect(logger)
agent = Authentication::Agent.connect(logger, self.session.options[:agent_socket_factory])
Copy link
Collaborator

Choose a reason for hiding this comment

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

can't we just write session vs self.session

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed.

@mfazekas
Copy link
Collaborator

Looks good to me, a test would be good to have.

@alongoldboim alongoldboim force-pushed the add_socket_option branch 2 times, most recently from 12ddcf5 to e7a7438 Compare April 28, 2016 07:41
@alongoldboim
Copy link
Contributor Author

@mfazekas Added test to make sure that if we pass a lambda it will use its value instead of the regular ENV.

@mfazekas mfazekas merged commit 0d7c245 into net-ssh:master Apr 28, 2016
@mfazekas
Copy link
Collaborator

Thanks much!

@simon3z
Copy link

simon3z commented Apr 29, 2016

@mfazekas thanks!

@mfazekas is there any chance to have a new release soon?

@mfazekas
Copy link
Collaborator

i'll try to release 4.0.0.alpha4 this weekend

@alongoldboim
Copy link
Contributor Author

alongoldboim commented May 1, 2016

Hey @mfazekas, I'm trying the new fix and i got a small problem you might help me with, I'm trying to do a nested ssh and for some reason the forwarding doesn't work (works if agent_socket_factory isn't passed), debugging the code it seems it uses the correct agent with the correct socket, what did i miss ? :)

require 'net/ssh'
agent_socket = "/tmp/ssh/ssh_a"
FileUtils.mkdir_p '/tmp/ssh_manageiq'
system "ssh-agent -a #{agent_socket}"
Net::SSH.start('10.35.4.213', 'root', :paranoid => false, :forward_agent => true, :agent_socket_factory => ->{ UNIXSocket.open(agent_socket) },
               :key_data => ['key']) do |ssh|
  res = ssh.exec!("ssh -o 'StrictHostKeyChecking no' root@10.35.4.163" + " echo $?")
end

the problem is that the agent.identities arn't being set.

@alongoldboim
Copy link
Contributor Author

@mfazekas i though net-ssh will add the key we connect with to the running agent automatically, apparently it doesn't, ill just do it manually, maybe we should consider adding the current key to the agent by default?

@mfazekas
Copy link
Collaborator

mfazekas commented May 2, 2016

I assume there might be usecase where auto adding the programatically defined key_data to agent automatically is not desirable. So maybe an option to add that to session.

@alongoldboim
Copy link
Contributor Author

@mfazekas your right, when ill get some time ill do a patch for that as well.
Regarding the release any ETA on that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants