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 18, 2022
1 parent 28533d7 commit ad89271
Show file tree
Hide file tree
Showing 2 changed files with 6 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
4 changes: 4 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,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 {
Expand Down

0 comments on commit ad89271

Please sign in to comment.