Skip to content

Commit

Permalink
forward SSH_AUTH_SOCK in Go client (#848)
Browse files Browse the repository at this point in the history
Fixes #845

Signed-off-by: Daniel Müller <dan@unthought.org>
  • Loading branch information
unthought committed Apr 30, 2020
1 parent 2f46c5d commit 7ec77d3
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions pkg/ssh/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@ import (
"context"
"fmt"
"io"
"os"
"strings"
"time"

"github.com/okteto/okteto/pkg/log"
"golang.org/x/crypto/ssh"
"golang.org/x/crypto/ssh/agent"
"golang.org/x/crypto/ssh/terminal"
)

Expand Down Expand Up @@ -85,6 +87,18 @@ func Exec(ctx context.Context, remotePort int, tty bool, inR io.Reader, outW, er
}
}

sockEnvVar, ok := os.LookupEnv("SSH_AUTH_SOCK")
if !ok {
log.Info("SSH_AUTH_SOCK is not set, not forwarding socket")
} else {
if err := agent.ForwardToRemote(connection, sockEnvVar); err != nil {
log.Infof("failed to existing SSH_AUTH_SOCK('%s'): %s", sockEnvVar, err)
}
if err := agent.RequestAgentForwarding(session); err != nil {
log.Infof("failed to forward ssh agent to remote: %s", err)
}
}

stdin, err := session.StdinPipe()
if err != nil {
return fmt.Errorf("unable to setup stdin for session: %v", err)
Expand Down

0 comments on commit 7ec77d3

Please sign in to comment.