Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 8 additions & 1 deletion internal/cmd/configssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ func makeSSHConfig(binPath, workspaceName, privateKeyFilepath string, additional
}
options = append(options,
fmt.Sprintf("HostName coder.%s", workspaceName),
fmt.Sprintf("ProxyCommand %q tunnel %s 12213 stdio", binPath, workspaceName),
fmt.Sprintf("ProxyCommand %s", proxyCommand(binPath, workspaceName, true)),
"StrictHostKeyChecking no",
"ConnectTimeout=0",
"IdentitiesOnly yes",
Expand All @@ -279,6 +279,13 @@ func makeSSHConfig(binPath, workspaceName, privateKeyFilepath string, additional
return fmt.Sprintf("Host coder.%s\n\t%s\n\n", workspaceName, strings.Join(options, "\n\t"))
}

func proxyCommand(binPath, workspaceName string, quoted bool) string {
if quoted {
binPath = fmt.Sprintf("%q", binPath)
}
return fmt.Sprintf(`%s tunnel %s 12213 stdio`, binPath, workspaceName)
}

func writeStr(filename, data string) error {
return ioutil.WriteFile(filename, []byte(data), 0777)
}
Expand Down
22 changes: 13 additions & 9 deletions internal/cmd/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"fmt"
"net/url"
"os"
"os/exec"
"os/user"
Expand Down Expand Up @@ -41,10 +40,7 @@ func shell(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
me, err := client.Me(ctx)
if err != nil {
return err
}

workspace, err := findWorkspace(ctx, client, args[0], coder.Me)
if err != nil {
return err
Expand All @@ -60,9 +56,9 @@ func shell(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
u, err := url.Parse(wp.EnvproxyAccessURL)
if err != nil {
return err

if !wp.SSHEnabled {
return clog.Error("SSH is disabled on this Workspace")
}

usr, err := user.Current()
Expand All @@ -75,13 +71,21 @@ func shell(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}

binPath, err := binPath()
if err != nil {
return xerrors.Errorf("Failed to get executable path: %w", err)
}

ssh := exec.CommandContext(ctx,
"ssh", "-i"+privateKeyFilepath,
fmt.Sprintf("%s-%s@%s", me.Username, workspace.Name, u.Hostname()),
"-o"+fmt.Sprintf("ProxyCommand=%s", proxyCommand(binPath, workspace.Name, false)),
workspace.Name,
)
if len(args) > 1 {
ssh.Args = append(ssh.Args, args[1:]...)
}

ssh.Stderr = os.Stderr
ssh.Stdout = os.Stdout
ssh.Stdin = os.Stdin
Expand Down