mattbrictson/airbrussh

Remote user missing if set through ssh_options

felixbuenemann opened this issue · 10 comments

Currently the remote user in the formatter is empty, if it's set in the ssh_options as opposed to in the server config:

set :application, 'foo'
set :server, 'bar.com'
set :ssh_options, auth_methods: %w(publickey), user: fetch(:application)

server fetch(:server), roles: %w(web app db)

This will display @bar.com instead foo@bar.com for the remote user.

I guess the logic would have to be:

  • Check if the host has a user
  • Check if the ssh_options define a user
  • Fallback to local_user (or whatever is used currently to determine the local user)

Thanks for the report!

I don't quick understand what you mean in your third point: "fallback to local_user". Do you mean the equivalent of running whoami on the remote host? I don't know if there is precedence for that in SSHKit.

I can definitely check the ssh_options, though, which should fix this particular issue.

If no user is specified, sshkit uses either the user from ~/.ssh/config, or if not defined, the current local user, just like ssh example.com would do.

Maybe there's a way to ask sshkit for the actual user it is going to use?

The user is determined by net-ssh, which is the underlying library that SSHKit uses. If we had access to the net-ssh Session object, we could probably get the user from it, but the session is not currently exposed by SSHKit's logging facility.

If you think there is a strong case to be made for logging the actual user (as implied by ~/.ssh/config, for example), I suggest you open an SSHKit issue requesting it.

In the meantime, do you think checking for ssh_options[:user] is an acceptable interim fix?

Yes I think it is.

Falling back to the local user, if we're not sure it is actually correct is probably a bad idea…

This is a bit tricker than I thought (see my failed attempt in PR #66), so I am going to put this on the back-burner for now. Addressing this issue means Airbrussh will have to make some assumptions about how net-ssh works, which makes me a little uncomfortable.

@felixbuenemann if you want to take a stab at a PR I will consider merging it.

Hmm, can't you access the global ssh_options from inside the formatter?

@felixbuenemann I think my PR will work after all. Let's move the conversation over to #66.

Fixed by #66.

This will be included in Airbrussh 0.8.0 (release date TBD).

Released today in Airbrussh 0.8.0.