Skip to content

Commit

Permalink
ssh: add more logging when connecting with bastion
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lbajolet-hashicorp committed Aug 12, 2022
1 parent bd7affe commit a250e0a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
2 changes: 2 additions & 0 deletions communicator/step_connect_ssh.go
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions sdk-internals/communicator/ssh/connect.go
Expand Up @@ -2,6 +2,7 @@ package ssh

import (
"fmt"
"log"
"net"
"time"

Expand Down Expand Up @@ -62,6 +63,8 @@ func BastionConnectFunc(
return nil, fmt.Errorf("Error connecting to bastion: %s", err)
}

log.Printf("[DEBUG] connected to bastion, hopping to destination")

// Connect through to the end host
conn, err := bastion.Dial(proto, addr)
if err != nil {
Expand Down

0 comments on commit a250e0a

Please sign in to comment.