Skip to content

Commit 2a57992

Browse files
committed
fix: added logging for ssh and also renamed socket file
1 parent 443941f commit 2a57992

4 files changed

Lines changed: 35 additions & 24 deletions

File tree

pkg/cmd/shell/shell.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package shell
22

33
import (
4+
"bytes"
45
"fmt"
6+
"io"
57
"os"
68
"os/exec"
9+
"strings"
710
"time"
811

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

209+
var stderrBuf bytes.Buffer
206210
sshCmd := exec.Command("bash", "-c", cmd) //nolint:gosec //cmd is user input
207-
sshCmd.Stderr = os.Stderr
211+
sshCmd.Stderr = io.MultiWriter(os.Stderr, &stderrBuf)
208212
sshCmd.Stdout = os.Stdout
209213
sshCmd.Stdin = os.Stdin
210214

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

216220
err = sshCmd.Run()
217221
if err != nil {
222+
stderrStr := stderrBuf.String()
223+
if strings.Contains(stderrStr, "unix_listener") || strings.Contains(stderrStr, "path too long") {
224+
fmt.Fprintf(os.Stderr, "\nbrev shell failed: SSH ControlPath socket path is too long for this system.\n")
225+
fmt.Fprintf(os.Stderr, "Fix: run 'brev refresh' to regenerate your SSH config with the updated ControlPath.\n")
226+
} else {
227+
fmt.Fprintf(os.Stderr, "\nbrev shell failed. If the above SSH error is unclear, try running 'brev refresh' and reconnecting.\n")
228+
}
218229
return breverrors.WrapAndTrace(err)
219230
}
220231
return nil

pkg/ssh/ssh.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ const workspaceSSHConfigTemplate = `Host {{ .Host }}
3939
ForwardAgent yes
4040
AddKeysToAgent yes
4141
ControlMaster auto
42-
ControlPath ~/.ssh/brev-%C
42+
ControlPath ~/.ssh/brev-control-%C
4343
ControlPersist 10m
4444
RemoteCommand cd {{ .Dir }}; $SHELL
4545

pkg/ssh/sshconfigurer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ const SSHConfigEntryTemplateV2 = `Host {{ .Alias }}
305305
ForwardAgent yes
306306
RequestTTY yes
307307
ControlMaster auto
308-
ControlPath ~/.ssh/brev-%C
308+
ControlPath ~/.ssh/brev-control-%C
309309
ControlPersist 10m
310310
{{ if .RunRemoteCMD }}
311311
RemoteCommand cd {{ .Dir }}; $SHELL
@@ -325,7 +325,7 @@ const SSHConfigEntryTemplateV3 = `Host {{ .Alias }}
325325
ForwardAgent yes
326326
RequestTTY yes
327327
ControlMaster auto
328-
ControlPath ~/.ssh/brev-%C
328+
ControlPath ~/.ssh/brev-control-%C
329329
ControlPersist 10m
330330
Port {{ .Port }}
331331
{{ if .RunRemoteCMD }}

pkg/ssh/sshconfigurer_test.go

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ Host %s
151151
ForwardAgent yes
152152
RequestTTY yes
153153
ControlMaster auto
154-
ControlPath ~/.ssh/brev-%%C
154+
ControlPath ~/.ssh/brev-control-%%C
155155
ControlPersist 10m
156156
Port 22
157157
@@ -168,7 +168,7 @@ Host %s-host
168168
ForwardAgent yes
169169
RequestTTY yes
170170
ControlMaster auto
171-
ControlPath ~/.ssh/brev-%%C
171+
ControlPath ~/.ssh/brev-control-%%C
172172
ControlPersist 10m
173173
Port 22
174174
@@ -185,7 +185,7 @@ Host %s
185185
ForwardAgent yes
186186
RequestTTY yes
187187
ControlMaster auto
188-
ControlPath ~/.ssh/brev-%%C
188+
ControlPath ~/.ssh/brev-control-%%C
189189
ControlPersist 10m
190190
Port 22
191191
@@ -202,7 +202,7 @@ Host %s-host
202202
ForwardAgent yes
203203
RequestTTY yes
204204
ControlMaster auto
205-
ControlPath ~/.ssh/brev-%%C
205+
ControlPath ~/.ssh/brev-control-%%C
206206
ControlPersist 10m
207207
Port 22
208208
@@ -323,7 +323,7 @@ func Test_makeSSHConfigEntryV2(t *testing.T) { //nolint:funlen // test
323323
ForwardAgent yes
324324
RequestTTY yes
325325
ControlMaster auto
326-
ControlPath ~/.ssh/brev-%C
326+
ControlPath ~/.ssh/brev-control-%C
327327
ControlPersist 10m
328328
Port 20
329329
@@ -340,7 +340,7 @@ Host testName2-host
340340
ForwardAgent yes
341341
RequestTTY yes
342342
ControlMaster auto
343-
ControlPath ~/.ssh/brev-%C
343+
ControlPath ~/.ssh/brev-control-%C
344344
ControlPersist 10m
345345
Port 2022
346346
@@ -378,7 +378,7 @@ Host testName2-host
378378
ForwardAgent yes
379379
RequestTTY yes
380380
ControlMaster auto
381-
ControlPath ~/.ssh/brev-%C
381+
ControlPath ~/.ssh/brev-control-%C
382382
ControlPersist 10m
383383
Port 22
384384
@@ -395,7 +395,7 @@ Host testName2-host
395395
ForwardAgent yes
396396
RequestTTY yes
397397
ControlMaster auto
398-
ControlPath ~/.ssh/brev-%C
398+
ControlPath ~/.ssh/brev-control-%C
399399
ControlPersist 10m
400400
Port 22
401401
@@ -434,7 +434,7 @@ Host testName2-host
434434
ForwardAgent yes
435435
RequestTTY yes
436436
ControlMaster auto
437-
ControlPath ~/.ssh/brev-%C
437+
ControlPath ~/.ssh/brev-control-%C
438438
ControlPersist 10m
439439
Port 2022
440440
@@ -451,7 +451,7 @@ Host testName2-host
451451
ForwardAgent yes
452452
RequestTTY yes
453453
ControlMaster auto
454-
ControlPath ~/.ssh/brev-%C
454+
ControlPath ~/.ssh/brev-control-%C
455455
ControlPersist 10m
456456
Port 22
457457
@@ -488,7 +488,7 @@ Host testName2-host
488488
ForwardAgent yes
489489
RequestTTY yes
490490
ControlMaster auto
491-
ControlPath ~/.ssh/brev-%C
491+
ControlPath ~/.ssh/brev-control-%C
492492
ControlPersist 10m
493493
494494
`,
@@ -524,7 +524,7 @@ Host testName2-host
524524
ForwardAgent yes
525525
RequestTTY yes
526526
ControlMaster auto
527-
ControlPath ~/.ssh/brev-%C
527+
ControlPath ~/.ssh/brev-control-%C
528528
ControlPersist 10m
529529
530530
`,
@@ -564,7 +564,7 @@ Host testName2-host
564564
ForwardAgent yes
565565
RequestTTY yes
566566
ControlMaster auto
567-
ControlPath ~/.ssh/brev-%C
567+
ControlPath ~/.ssh/brev-control-%C
568568
ControlPersist 10m
569569
570570
Host testName2-host
@@ -580,7 +580,7 @@ Host testName2-host
580580
ForwardAgent yes
581581
RequestTTY yes
582582
ControlMaster auto
583-
ControlPath ~/.ssh/brev-%C
583+
ControlPath ~/.ssh/brev-control-%C
584584
ControlPersist 10m
585585
586586
`,
@@ -808,7 +808,7 @@ Host testName1
808808
ForwardAgent yes
809809
RequestTTY yes
810810
ControlMaster auto
811-
ControlPath ~/.ssh/brev-%C
811+
ControlPath ~/.ssh/brev-control-%C
812812
ControlPersist 10m
813813
Port 22
814814
@@ -825,7 +825,7 @@ Host testName1-host
825825
ForwardAgent yes
826826
RequestTTY yes
827827
ControlMaster auto
828-
ControlPath ~/.ssh/brev-%C
828+
ControlPath ~/.ssh/brev-control-%C
829829
ControlPersist 10m
830830
Port 22
831831
@@ -874,7 +874,7 @@ Host testName1
874874
ForwardAgent yes
875875
RequestTTY yes
876876
ControlMaster auto
877-
ControlPath ~/.ssh/brev-%C
877+
ControlPath ~/.ssh/brev-control-%C
878878
ControlPersist 10m
879879
Port 22
880880
@@ -891,7 +891,7 @@ Host testName1-host
891891
ForwardAgent yes
892892
RequestTTY yes
893893
ControlMaster auto
894-
ControlPath ~/.ssh/brev-%C
894+
ControlPath ~/.ssh/brev-control-%C
895895
ControlPersist 10m
896896
Port 22
897897
@@ -911,7 +911,7 @@ Host testName1
911911
ForwardAgent yes
912912
RequestTTY yes
913913
ControlMaster auto
914-
ControlPath ~/.ssh/brev-%C
914+
ControlPath ~/.ssh/brev-control-%C
915915
ControlPersist 10m
916916
Port 22
917917
@@ -928,7 +928,7 @@ Host testName1-host
928928
ForwardAgent yes
929929
RequestTTY yes
930930
ControlMaster auto
931-
ControlPath ~/.ssh/brev-%C
931+
ControlPath ~/.ssh/brev-control-%C
932932
ControlPersist 10m
933933
Port 22
934934

0 commit comments

Comments
 (0)