From ad8927112f01ed503b1fd42fd4c3d8a6219cad22 Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Fri, 12 Aug 2022 10:28:57 -0400 Subject: [PATCH] ssh: add more logging when connecting with bastion When a SSH bastion is used for connecting to a target, the operation is done completely silently, making it hard to understand if it is working as intended. To make it easier to follow the path that the command is taking, we add a few more INFO/DEBUG logs that parrot the actions it takes for connecting. --- communicator/step_connect_ssh.go | 2 ++ sdk-internals/communicator/ssh/connect.go | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/communicator/step_connect_ssh.go b/communicator/step_connect_ssh.go index 652b5c4b3..fce6175f6 100644 --- a/communicator/step_connect_ssh.go +++ b/communicator/step_connect_ssh.go @@ -165,6 +165,8 @@ func (s *StepConnectSSH) waitForSSH(state multistep.StateBag, ctx context.Contex var connFunc func() (net.Conn, error) address := fmt.Sprintf("%s:%d", host, port) if bAddr != "" { + log.Printf("[INFO] connecting with SSH to host %s through bastion at %s", + address, bAddr) // We're using a bastion host, so use the bastion connfunc connFunc = ssh.BastionConnectFunc( bProto, bAddr, bConf, "tcp", address) diff --git a/sdk-internals/communicator/ssh/connect.go b/sdk-internals/communicator/ssh/connect.go index 80bf0a9f4..4216ec35d 100644 --- a/sdk-internals/communicator/ssh/connect.go +++ b/sdk-internals/communicator/ssh/connect.go @@ -2,6 +2,7 @@ package ssh import ( "fmt" + "log" "net" "time" @@ -62,6 +63,9 @@ func BastionConnectFunc( return nil, fmt.Errorf("Error connecting to bastion: %s", err) } + log.Println("[DEBUG] connected to bastion host") + log.Println("[DEBUG] attempting connection to destination host") + // Connect through to the end host conn, err := bastion.Dial(proto, addr) if err != nil {