Skip to content

Commit 1a7b7dd

Browse files
authored
Merge pull request #5320 from trajano/patch-1
disable pseudoterminal creation
2 parents 211a540 + f3c2c26 commit 1a7b7dd

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

cli/connhelper/connhelper.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ func getConnectionHelper(daemonURL string, sshFlags []string) (*ConnectionHelper
5252
args = append(args, "--host", "unix://"+sp.Path)
5353
}
5454
sshFlags = addSSHTimeout(sshFlags)
55+
sshFlags = disablePseudoTerminalAllocation(sshFlags)
5556
args = append(args, "system", "dial-stdio")
5657
return commandconn.New(ctx, "ssh", append(sshFlags, sp.Args(args...)...)...)
5758
},
@@ -79,3 +80,14 @@ func addSSHTimeout(sshFlags []string) []string {
7980
}
8081
return sshFlags
8182
}
83+
84+
// disablePseudoTerminalAllocation disables pseudo-terminal allocation to
85+
// prevent SSH from executing as a login shell
86+
func disablePseudoTerminalAllocation(sshFlags []string) []string {
87+
for _, flag := range sshFlags {
88+
if flag == "-T" {
89+
return sshFlags
90+
}
91+
}
92+
return append(sshFlags, "-T")
93+
}

cli/connhelper/connhelper_test.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package connhelper
22

33
import (
4+
"reflect"
45
"testing"
56

67
"gotest.tools/v3/assert"
@@ -29,3 +30,36 @@ func TestSSHFlags(t *testing.T) {
2930
assert.DeepEqual(t, addSSHTimeout(tc.in), tc.out)
3031
}
3132
}
33+
34+
func TestDisablePseudoTerminalAllocation(t *testing.T) {
35+
testCases := []struct {
36+
name string
37+
sshFlags []string
38+
expected []string
39+
}{
40+
{
41+
name: "No -T flag present",
42+
sshFlags: []string{"-v", "-oStrictHostKeyChecking=no"},
43+
expected: []string{"-v", "-oStrictHostKeyChecking=no", "-T"},
44+
},
45+
{
46+
name: "Already contains -T flag",
47+
sshFlags: []string{"-v", "-T", "-oStrictHostKeyChecking=no"},
48+
expected: []string{"-v", "-T", "-oStrictHostKeyChecking=no"},
49+
},
50+
{
51+
name: "Empty sshFlags",
52+
sshFlags: []string{},
53+
expected: []string{"-T"},
54+
},
55+
}
56+
57+
for _, tc := range testCases {
58+
t.Run(tc.name, func(t *testing.T) {
59+
result := disablePseudoTerminalAllocation(tc.sshFlags)
60+
if !reflect.DeepEqual(result, tc.expected) {
61+
t.Errorf("expected %v, got %v", tc.expected, result)
62+
}
63+
})
64+
}
65+
}

0 commit comments

Comments
 (0)