moul/assh

assh shouldn't log as ERROR until gateways are exhausted

soraxas opened this issue · 0 comments

I have configured a host in my assh.yml with several gateways, where:

myhost:
  Gateways:
  - direct
  - MY_FALLBACK_GATEWAY
  - MY_FALLBACK_GATEWAY_2

Currently, whenever a gateway fails to connect, it willl throw error instantly, even though there are still gateways left to try. Something like:

$ ssh myhost                                                                                                                                                        
2020/04/28 13:26:52 direct
ERROR	Failed to use 'direct' connection	{"error": "failed to dial: dial tcp 123.456.789.00:22: i/o timeout", "errorVerbose": "dial tcp 123.456.789.00:22: i/o timeout\nfailed to dial\nmoul.io/assh/v2/pkg/commands.proxyGo\n\tmoul.io/assh/v2/pkg/commands/proxy.go:457\nmoul.io/assh/v2/pkg/commands.proxyDirect\n\tmoul.io/assh/v2/pkg/commands/proxy.go:291\nmoul.io/assh/v2/pkg/commands.proxy\n\tmoul.io/assh/v2/pkg/commands/proxy.go:234\nmoul.io/assh/v2/pkg/commands.runProxyCommand\n\tmoul.io/assh/v2/pkg/commands/proxy.go:143\ngithub.com/spf13/cobra.(*Command).execute\n\tgithub.com/spf13/cobra@v0.0.6/command.go:840\ngithub.com/spf13/cobra.(*Command).ExecuteC\n\tgithub.com/spf13/cobra@v0.0.6/command.go:945\ngithub.com/spf13/cobra.(*Command).Execute\n\tgithub.com/spf13/cobra@v0.0.6/command.go:885\nmain.main\n\tmoul.io/assh/v2/main.go:13\nruntime.main\n\truntime/proc.go:203\nruntime.goexit\n\truntime/asm_amd64.s:1373"}
2020/04/28 13:26:54 MY_FALLBACK_GATEWAY
Welcome to Ubuntu 16.04.6 LTS (GNU/Linux 4.15.0-76-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

* BLAHBLAHBLAH
me@hostname:~$ 

What's frustrating is to see everytime is the extremely long error after the failed connections via direct (especially it's wrapped within terminal so it fills the entire screen).

The error comes from the logger here

logger().Error("Failed to use 'direct' connection", zap.Error(err))

What I am proposing is that, while logger is very useful to notify user when the connections is not working, the setups of fallback in assh relies on the fact that you can configure multiple gateways and automatically fallback. (i.e. for situations where you are ssh-ing into office (w/o gateway) or from home (needs gateway))

When using gateway like direct, the user might already expected it to fails most of the time.

A more nice approach might be only logs error after all gateways options are exhausted, e.g., save the error log in like a list, and only actually logs them after the for loop in

for _, gateway := range host.Gateways {

finishes? (i.e. after all gateways had been tried and none of them works)

Thanks for your great tool eitherway :)