From 22a6958e490f38f59f974878a51d0f7a0d07c9b4 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Tue, 3 Aug 2021 12:47:37 -0500 Subject: [PATCH 1/2] Use webrtc for coder sh --- internal/cmd/configssh.go | 11 +++++++++-- internal/cmd/ssh.go | 22 +++++++++++++--------- 2 files changed, 22 insertions(+), 11 deletions(-) diff --git a/internal/cmd/configssh.go b/internal/cmd/configssh.go index 3fc693d1..c8e826ba 100644 --- a/internal/cmd/configssh.go +++ b/internal/cmd/configssh.go @@ -251,12 +251,12 @@ func makeSSHConfig(binPath, workspaceName, privateKeyFilepath string) string { entry := fmt.Sprintf( `Host coder.%s HostName coder.%s - ProxyCommand "%s" tunnel %s 12213 stdio + ProxyCommand %s StrictHostKeyChecking no ConnectTimeout=0 IdentitiesOnly yes IdentityFile="%s" -`, workspaceName, workspaceName, binPath, workspaceName, privateKeyFilepath) +`, workspaceName, workspaceName, proxyCommand(binPath, workspaceName, true), privateKeyFilepath) if runtime.GOOS == "linux" || runtime.GOOS == "darwin" { entry += ` ControlMaster auto @@ -268,6 +268,13 @@ func makeSSHConfig(binPath, workspaceName, privateKeyFilepath string) string { return entry } +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) } diff --git a/internal/cmd/ssh.go b/internal/cmd/ssh.go index cec588a6..983ec3f4 100644 --- a/internal/cmd/ssh.go +++ b/internal/cmd/ssh.go @@ -2,7 +2,6 @@ package cmd import ( "fmt" - "net/url" "os" "os/exec" "os/user" @@ -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 @@ -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() @@ -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 From ea1372fa397c4c60284555344991f661db2044c2 Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Wed, 11 Aug 2021 22:07:58 -0500 Subject: [PATCH 2/2] Forgot a line in the merge --- internal/cmd/configssh.go | 1 + 1 file changed, 1 insertion(+) diff --git a/internal/cmd/configssh.go b/internal/cmd/configssh.go index d3ce9f58..9740a102 100644 --- a/internal/cmd/configssh.go +++ b/internal/cmd/configssh.go @@ -45,6 +45,7 @@ func configSSHCmd() *cobra.Command { RunE: configSSH(&configpath, &remove, &additionalOptions), } cmd.Flags().StringVar(&configpath, "filepath", filepath.Join("~", ".ssh", "config"), "override the default path of your ssh config file") + cmd.Flags().StringSliceVarP(&additionalOptions, "option", "o", []string{}, "additional options injected in the ssh config (ex. disable caching with \"-o ControlPath=none\")") cmd.Flags().BoolVar(&remove, "remove", false, "remove the auto-generated Coder ssh config") return cmd pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy