Skip to content
Merged
Show file tree
Hide file tree
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
13 changes: 12 additions & 1 deletion pkg/cmd/shell/shell.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package shell

import (
"bytes"
"fmt"
"io"
"os"
"os/exec"
"strings"
"time"

nodev1 "buf.build/gen/go/brevdev/devplane/protocolbuffers/go/devplaneapi/v1"
Expand Down Expand Up @@ -203,8 +206,9 @@ func runSSH(sshAlias string, host bool) error {
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)
}

var stderrBuf bytes.Buffer
sshCmd := exec.Command("bash", "-c", cmd) //nolint:gosec //cmd is user input
sshCmd.Stderr = os.Stderr
sshCmd.Stderr = io.MultiWriter(os.Stderr, &stderrBuf)
sshCmd.Stdout = os.Stdout
sshCmd.Stdin = os.Stdin

Expand All @@ -215,6 +219,13 @@ func runSSH(sshAlias string, host bool) error {

err = sshCmd.Run()
if err != nil {
stderrStr := stderrBuf.String()
if strings.Contains(stderrStr, "unix_listener") || strings.Contains(stderrStr, "path too long") {
fmt.Fprintf(os.Stderr, "\nbrev shell failed: SSH ControlPath socket path is too long for this system.\n")
fmt.Fprintf(os.Stderr, "Fix: run 'brev refresh' to regenerate your SSH config with the updated ControlPath.\n")
} else {
fmt.Fprintf(os.Stderr, "\nbrev shell failed. If the above SSH error is unclear, try running 'brev refresh' and reconnecting.\n")
}
return breverrors.WrapAndTrace(err)
}
return nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/ssh/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const workspaceSSHConfigTemplate = `Host {{ .Host }}
ForwardAgent yes
AddKeysToAgent yes
ControlMaster auto
ControlPath ~/.ssh/brev-control-%r@%h-%p
ControlPath ~/.ssh/brev-control-%C
ControlPersist 10m
RemoteCommand cd {{ .Dir }}; $SHELL

Expand Down
4 changes: 2 additions & 2 deletions pkg/ssh/sshconfigurer.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ const SSHConfigEntryTemplateV2 = `Host {{ .Alias }}
ForwardAgent yes
RequestTTY yes
ControlMaster auto
ControlPath ~/.ssh/brev-control-%r@%h-%p
ControlPath ~/.ssh/brev-control-%C
ControlPersist 10m
{{ if .RunRemoteCMD }}
RemoteCommand cd {{ .Dir }}; $SHELL
Expand All @@ -325,7 +325,7 @@ const SSHConfigEntryTemplateV3 = `Host {{ .Alias }}
ForwardAgent yes
RequestTTY yes
ControlMaster auto
ControlPath ~/.ssh/brev-control-%r@%h-%p
ControlPath ~/.ssh/brev-control-%C
ControlPersist 10m
Port {{ .Port }}
{{ if .RunRemoteCMD }}
Expand Down
40 changes: 20 additions & 20 deletions pkg/ssh/sshconfigurer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ Host %s
ForwardAgent yes
RequestTTY yes
ControlMaster auto
ControlPath ~/.ssh/brev-control-%%r@%%h-%%p
ControlPath ~/.ssh/brev-control-%%C
ControlPersist 10m
Port 22

Expand All @@ -168,7 +168,7 @@ Host %s-host
ForwardAgent yes
RequestTTY yes
ControlMaster auto
ControlPath ~/.ssh/brev-control-%%r@%%h-%%p
ControlPath ~/.ssh/brev-control-%%C
ControlPersist 10m
Port 22

Expand All @@ -185,7 +185,7 @@ Host %s
ForwardAgent yes
RequestTTY yes
ControlMaster auto
ControlPath ~/.ssh/brev-control-%%r@%%h-%%p
ControlPath ~/.ssh/brev-control-%%C
ControlPersist 10m
Port 22

Expand All @@ -202,7 +202,7 @@ Host %s-host
ForwardAgent yes
RequestTTY yes
ControlMaster auto
ControlPath ~/.ssh/brev-control-%%r@%%h-%%p
ControlPath ~/.ssh/brev-control-%%C
ControlPersist 10m
Port 22

Expand Down Expand Up @@ -323,7 +323,7 @@ func Test_makeSSHConfigEntryV2(t *testing.T) { //nolint:funlen // test
ForwardAgent yes
RequestTTY yes
ControlMaster auto
ControlPath ~/.ssh/brev-control-%r@%h-%p
ControlPath ~/.ssh/brev-control-%C
ControlPersist 10m
Port 20

Expand All @@ -340,7 +340,7 @@ Host testName2-host
ForwardAgent yes
RequestTTY yes
ControlMaster auto
ControlPath ~/.ssh/brev-control-%r@%h-%p
ControlPath ~/.ssh/brev-control-%C
ControlPersist 10m
Port 2022

Expand Down Expand Up @@ -378,7 +378,7 @@ Host testName2-host
ForwardAgent yes
RequestTTY yes
ControlMaster auto
ControlPath ~/.ssh/brev-control-%r@%h-%p
ControlPath ~/.ssh/brev-control-%C
ControlPersist 10m
Port 22

Expand All @@ -395,7 +395,7 @@ Host testName2-host
ForwardAgent yes
RequestTTY yes
ControlMaster auto
ControlPath ~/.ssh/brev-control-%r@%h-%p
ControlPath ~/.ssh/brev-control-%C
ControlPersist 10m
Port 22

Expand Down Expand Up @@ -434,7 +434,7 @@ Host testName2-host
ForwardAgent yes
RequestTTY yes
ControlMaster auto
ControlPath ~/.ssh/brev-control-%r@%h-%p
ControlPath ~/.ssh/brev-control-%C
ControlPersist 10m
Port 2022

Expand All @@ -451,7 +451,7 @@ Host testName2-host
ForwardAgent yes
RequestTTY yes
ControlMaster auto
ControlPath ~/.ssh/brev-control-%r@%h-%p
ControlPath ~/.ssh/brev-control-%C
ControlPersist 10m
Port 22

Expand Down Expand Up @@ -488,7 +488,7 @@ Host testName2-host
ForwardAgent yes
RequestTTY yes
ControlMaster auto
ControlPath ~/.ssh/brev-control-%r@%h-%p
ControlPath ~/.ssh/brev-control-%C
ControlPersist 10m

`,
Expand Down Expand Up @@ -524,7 +524,7 @@ Host testName2-host
ForwardAgent yes
RequestTTY yes
ControlMaster auto
ControlPath ~/.ssh/brev-control-%r@%h-%p
ControlPath ~/.ssh/brev-control-%C
ControlPersist 10m

`,
Expand Down Expand Up @@ -564,7 +564,7 @@ Host testName2-host
ForwardAgent yes
RequestTTY yes
ControlMaster auto
ControlPath ~/.ssh/brev-control-%r@%h-%p
ControlPath ~/.ssh/brev-control-%C
ControlPersist 10m

Host testName2-host
Expand All @@ -580,7 +580,7 @@ Host testName2-host
ForwardAgent yes
RequestTTY yes
ControlMaster auto
ControlPath ~/.ssh/brev-control-%r@%h-%p
ControlPath ~/.ssh/brev-control-%C
ControlPersist 10m

`,
Expand Down Expand Up @@ -808,7 +808,7 @@ Host testName1
ForwardAgent yes
RequestTTY yes
ControlMaster auto
ControlPath ~/.ssh/brev-control-%r@%h-%p
ControlPath ~/.ssh/brev-control-%C
ControlPersist 10m
Port 22

Expand All @@ -825,7 +825,7 @@ Host testName1-host
ForwardAgent yes
RequestTTY yes
ControlMaster auto
ControlPath ~/.ssh/brev-control-%r@%h-%p
ControlPath ~/.ssh/brev-control-%C
ControlPersist 10m
Port 22

Expand Down Expand Up @@ -874,7 +874,7 @@ Host testName1
ForwardAgent yes
RequestTTY yes
ControlMaster auto
ControlPath ~/.ssh/brev-control-%r@%h-%p
ControlPath ~/.ssh/brev-control-%C
ControlPersist 10m
Port 22

Expand All @@ -891,7 +891,7 @@ Host testName1-host
ForwardAgent yes
RequestTTY yes
ControlMaster auto
ControlPath ~/.ssh/brev-control-%r@%h-%p
ControlPath ~/.ssh/brev-control-%C
ControlPersist 10m
Port 22

Expand All @@ -911,7 +911,7 @@ Host testName1
ForwardAgent yes
RequestTTY yes
ControlMaster auto
ControlPath ~/.ssh/brev-control-%r@%h-%p
ControlPath ~/.ssh/brev-control-%C
ControlPersist 10m
Port 22

Expand All @@ -928,7 +928,7 @@ Host testName1-host
ForwardAgent yes
RequestTTY yes
ControlMaster auto
ControlPath ~/.ssh/brev-control-%r@%h-%p
ControlPath ~/.ssh/brev-control-%C
ControlPersist 10m
Port 22

Expand Down
Loading