Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions pkg/cmd/shell/shell.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ func runShellCommand(t *terminal.Terminal, sstore ShellStore, workspaceNameOrID
// legacy environments wont support this and cause errrors,
// but we don't want to block the user from using the shell
_ = writeconnectionevent.WriteWCEOnEnv(sstore, workspace.DNS)
err = runSSH(sshName)
err = runSSH(sshName, host)
if err != nil {
return breverrors.WrapAndTrace(err)
}
Expand All @@ -144,9 +144,15 @@ func runShellCommand(t *terminal.Terminal, sstore ShellStore, workspaceNameOrID
return nil
}

func runSSH(sshAlias string) error {
func runSSH(sshAlias string, host bool) error {
sshAgentEval := "eval $(ssh-agent -s)"
cmd := fmt.Sprintf("%s && ssh %s", sshAgentEval, sshAlias)
var cmd string
if host {
cmd = fmt.Sprintf("%s && ssh %s", sshAgentEval, sshAlias)
} else {
// SSH into VM and respect container WORKDIR if containerized, otherwise use default directory
cmd = fmt.Sprintf("%s && ssh -t %s 'DIR=$(readlink -f /proc/1/cwd 2>/dev/null || pwd); cd \"$DIR\" || echo \"Warning: Could not access container directory\" >&2; exec -l ${SHELL:-/bin/sh}'", sshAgentEval, sshAlias)
}

sshCmd := exec.Command("bash", "-c", cmd) //nolint:gosec //cmd is user input
sshCmd.Stderr = os.Stderr
Expand Down
Loading