Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 22a6958

Browse files
committed
Use webrtc for coder sh
1 parent edc273f commit 22a6958

File tree

2 files changed

+22
-11
lines changed

2 files changed

+22
-11
lines changed

internal/cmd/configssh.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,12 @@ func makeSSHConfig(binPath, workspaceName, privateKeyFilepath string) string {
251251
entry := fmt.Sprintf(
252252
`Host coder.%s
253253
HostName coder.%s
254-
ProxyCommand "%s" tunnel %s 12213 stdio
254+
ProxyCommand %s
255255
StrictHostKeyChecking no
256256
ConnectTimeout=0
257257
IdentitiesOnly yes
258258
IdentityFile="%s"
259-
`, workspaceName, workspaceName, binPath, workspaceName, privateKeyFilepath)
259+
`, workspaceName, workspaceName, proxyCommand(binPath, workspaceName, true), privateKeyFilepath)
260260

261261
if runtime.GOOS == "linux" || runtime.GOOS == "darwin" {
262262
entry += ` ControlMaster auto
@@ -268,6 +268,13 @@ func makeSSHConfig(binPath, workspaceName, privateKeyFilepath string) string {
268268
return entry
269269
}
270270

271+
func proxyCommand(binPath, workspaceName string, quoted bool) string {
272+
if quoted {
273+
binPath = fmt.Sprintf("%q", binPath)
274+
}
275+
return fmt.Sprintf(`%s tunnel %s 12213 stdio`, binPath, workspaceName)
276+
}
277+
271278
func writeStr(filename, data string) error {
272279
return ioutil.WriteFile(filename, []byte(data), 0777)
273280
}

internal/cmd/ssh.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package cmd
22

33
import (
44
"fmt"
5-
"net/url"
65
"os"
76
"os/exec"
87
"os/user"
@@ -41,10 +40,7 @@ func shell(cmd *cobra.Command, args []string) error {
4140
if err != nil {
4241
return err
4342
}
44-
me, err := client.Me(ctx)
45-
if err != nil {
46-
return err
47-
}
43+
4844
workspace, err := findWorkspace(ctx, client, args[0], coder.Me)
4945
if err != nil {
5046
return err
@@ -60,9 +56,9 @@ func shell(cmd *cobra.Command, args []string) error {
6056
if err != nil {
6157
return err
6258
}
63-
u, err := url.Parse(wp.EnvproxyAccessURL)
64-
if err != nil {
65-
return err
59+
60+
if !wp.SSHEnabled {
61+
return clog.Error("SSH is disabled on this Workspace")
6662
}
6763

6864
usr, err := user.Current()
@@ -75,13 +71,21 @@ func shell(cmd *cobra.Command, args []string) error {
7571
if err != nil {
7672
return err
7773
}
74+
75+
binPath, err := binPath()
76+
if err != nil {
77+
return xerrors.Errorf("Failed to get executable path: %w", err)
78+
}
79+
7880
ssh := exec.CommandContext(ctx,
7981
"ssh", "-i"+privateKeyFilepath,
80-
fmt.Sprintf("%s-%s@%s", me.Username, workspace.Name, u.Hostname()),
82+
"-o"+fmt.Sprintf("ProxyCommand=%s", proxyCommand(binPath, workspace.Name, false)),
83+
workspace.Name,
8184
)
8285
if len(args) > 1 {
8386
ssh.Args = append(ssh.Args, args[1:]...)
8487
}
88+
8589
ssh.Stderr = os.Stderr
8690
ssh.Stdout = os.Stdout
8791
ssh.Stdin = os.Stdin

0 commit comments

Comments
 (0)