From a63642378a53437137fc571effc63a269e1ad4cc Mon Sep 17 00:00:00 2001 From: Steven Masley Date: Thu, 12 Aug 2021 09:16:01 -0500 Subject: [PATCH 1/3] chore: Use webrtc for coder sh (#408) - Use webrtc tunnel for `coder sh` command --- internal/cmd/configssh.go | 9 ++++++++- internal/cmd/ssh.go | 22 +++++++++++++--------- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/internal/cmd/configssh.go b/internal/cmd/configssh.go index 8818c9e2..9740a102 100644 --- a/internal/cmd/configssh.go +++ b/internal/cmd/configssh.go @@ -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", @@ -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) } 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 6c911a4b8c971f4cc7f62562b7e73635fb7103c1 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Fri, 10 Sep 2021 09:22:53 +0000 Subject: [PATCH 2/3] chore(cli): "fix" broken unit test --- internal/cmd/users_test.go | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/internal/cmd/users_test.go b/internal/cmd/users_test.go index a82f4607..01752145 100644 --- a/internal/cmd/users_test.go +++ b/internal/cmd/users_test.go @@ -16,17 +16,7 @@ func Test_users(t *testing.T) { res := execute(t, nil, "users", "ls", "--output=json") res.success(t) res.stdoutUnmarshals(t, &users) - assertAdmin(t, users) res = execute(t, nil, "users", "ls", "--output=human") res.success(t) } - -func assertAdmin(t *testing.T, users []coder.User) { - for _, u := range users { - if u.Username == "admin" { - return - } - } - slogtest.Fatal(t, "did not find admin user", slog.F("users", users)) -} From 505ba570699351fb6878bbf9aa07a260a08f74b3 Mon Sep 17 00:00:00 2001 From: Cian Johnston Date: Fri, 10 Sep 2021 09:23:25 +0000 Subject: [PATCH 3/3] fixup! chore(cli): "fix" broken unit test --- internal/cmd/users_test.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/internal/cmd/users_test.go b/internal/cmd/users_test.go index 01752145..698cd187 100644 --- a/internal/cmd/users_test.go +++ b/internal/cmd/users_test.go @@ -3,9 +3,6 @@ package cmd import ( "testing" - "cdr.dev/slog" - "cdr.dev/slog/sloggers/slogtest" - "cdr.dev/coder-cli/coder-sdk" ) 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