Add ability to set a default SSH user for kssh#18
Conversation
This feature is useful when using jumpboxes combined with ssh configs. For example, imagine you have an SSH config that translates to this command: ``` ssh -J jump.example.com server.internal ``` When run via kssh, you want it to use the `developer` user but when run via ssh you want it to use your username as the user (the default when no user is specified). Prior to this change, that was not possible. Now, kssh does two new things: 1. kssh --set-default-user It is now possible to set a default SSH user to use with kssh. This is implemented via an SSH config file that applies a User directive to all hosts. This config file then inherits from the default ssh config file at ~/.ssh/config. This makes it possible to set a default user without modifying the user's ssh config file. 2. kssh now adds to the SSH agent by default Now by default kssh adds to the running ssh agent. This is necessary in order for jumpboxes to work since they rely on ssh agent forwarding. As part of this, I also had to tweak the tests to make all of this work properly.
|
|
||
| var AlternateSSHConfigFile = shared.ExpandPathWithTilde("~/.ssh/kssh-config") | ||
|
|
||
| func CreateDefaultUserConfigFile() (bool, error) { |
There was a problem hiding this comment.
am i reading this correctly?
this function:
- checks ~/.ssh/kssh.config for an ssh username
- if it's there, writes it into ~/.ssh/kssh-config
- returns true if it did that, and false in any other case.
my first thought is that these two configs should have names that are more different from one another. maybe the first one could be ~/.kssh/config.json or ~/.ssh/kssh.json. just something that distinguishes these two a little better.
my second thought is that this function is doing a weird combination of things. maybe it should be two functions: one that ensures local ssh config reflects any changes in local kssh config (e.g. PushKsshConfigToSsh or UpdateLocalSshConfig or ...?) and another that fetches whatever the current state is of our configured situation.
Or maybe GetSshUserFromConfig that returns the username from the config(s), keeps them in sync, etc.
This seems a little more decoupled / extensible than called Create and returning a boolean.
There was a problem hiding this comment.
Yeah, I think you're right that having it return a boolean was a little messy. Changed to have it only return an error. What do you think of this change?
|
|
||
| func BenchmarkLoadConfigs(b *testing.B) { | ||
| os.Remove("~/.ssh/kssh.config") | ||
| os.Remove("~/.ssh/kssh-config.json") |
There was a problem hiding this comment.
NAB: it's a little sloppy that this file is named in so many different places. it would be nicer if it were in just one place and pulled in everywhere it's needed.
There was a problem hiding this comment.
Yeah, I definitely agree. I've tried to keep it to a minimum but the split between the go codebase and the python integration tests make it difficult (at least without adding some avdl etc).
xgess
left a comment
There was a problem hiding this comment.
little request for text/name changes in warnAboutAlternateConfig. then ![]()
This feature is useful when using jumpboxes combined with ssh configs. For example, imagine you have an SSH
config that translates to this command:
When run via kssh, you want it to use the
developeruser but when run via ssh you want it to use yourusername as the user (the default when no user is specified). Prior to this change, that was not possible.
Now, kssh does two new things:
It is now possible to set a default SSH user to use with kssh. This is implemented via an SSH config
file that applies a User directive to all hosts. This config file then inherits from the default ssh
config file at ~/.ssh/config. This makes it possible to set a default user without modifying the
user's ssh config file.
Now by default kssh adds to the running ssh agent. This is necessary in order for jumpboxes to work
since they rely on ssh agent forwarding.
As part of this, I also had to tweak the tests to make all of this work properly.