Skip to content

Commit

Permalink
ssh: fix ssh args broken for some cases with layer enabled (#353)
Browse files Browse the repository at this point in the history
  • Loading branch information
abiosoft authored Jun 26, 2022
1 parent 2fbc0fd commit 1df2ea3
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
5 changes: 2 additions & 3 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"os"
"strings"

"github.com/abiosoft/colima/cli"
"github.com/abiosoft/colima/config"
Expand All @@ -16,6 +15,7 @@ import (
"github.com/abiosoft/colima/environment/host"
"github.com/abiosoft/colima/environment/vm/lima"
"github.com/abiosoft/colima/environment/vm/lima/limautil"
"github.com/abiosoft/colima/util"
log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -238,9 +238,8 @@ func (c colimaApp) SSH(layer bool, args ...string) error {
args = []string{"-q", "-t", resp.IPAddress, "--", "cd " + wd + " 2> /dev/null; bash --login"}
}

args = append(strings.Fields(cmdArgs), args...)
args = append(util.ShellSplit(cmdArgs), args...)
return cli.CommandInteractive("ssh", args...).Run()

}

func (c colimaApp) Status() error {
Expand Down
3 changes: 2 additions & 1 deletion environment/vm/lima/limautil/limautil.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

"github.com/abiosoft/colima/cli"
"github.com/abiosoft/colima/config"
"github.com/abiosoft/colima/util"
"gopkg.in/yaml.v3"
)

Expand Down Expand Up @@ -146,7 +147,7 @@ func ShowSSH(profileID string, layer bool, format string) (resp struct {
func replaceSSHCmd(cmd string, name string, ip string, port int) string {
var out []string

for _, s := range strings.Fields(cmd) {
for _, s := range util.ShellSplit(cmd) {
if port > 0 {
if strings.HasPrefix(s, "ControlPath=") {
s = "ControlPath=" + strconv.Quote(filepath.Join(config.Dir(), "ssh.sock"))
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.18

require (
github.com/fatih/color v1.12.0
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.2.1
golang.org/x/crypto v0.0.0-20220411220226-7b82a4e95df4
Expand Down Expand Up @@ -35,7 +36,6 @@ require (
require (
github.com/containers/gvisor-tap-vsock v0.3.0
github.com/docker/go-units v0.4.0
github.com/fsnotify/fsnotify v1.5.4
github.com/inconshreveable/mousetrap v1.0.0 // indirect
github.com/mattn/go-colorable v0.1.8 // indirect
github.com/mattn/go-isatty v0.0.12 // indirect
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,6 @@ github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoD
github.com/frankban/quicktest v1.11.3/go.mod h1:wRf/ReqHper53s+kmmSZizM8NamnL3IM0I9ntUbOk+k=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
github.com/fullsailor/pkcs7 v0.0.0-20190404230743-d7302db945fa/go.mod h1:KnogPXtdwXqoenmZCw6S+25EAm2MkxbG0deNDu4cbSA=
github.com/garyburd/redigo v0.0.0-20150301180006-535138d7bcd7/go.mod h1:NR3MbYisc3/PwhQ00EMzDiPmrwpPxAn5GI05/YaO1SY=
github.com/ghodss/yaml v0.0.0-20150909031657-73d445a93680/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
Expand Down Expand Up @@ -333,6 +331,8 @@ github.com/google/pprof v0.0.0-20210226084205-cbba55b83ad5/go.mod h1:kpwsk12EmLe
github.com/google/pprof v0.0.0-20210423192551-a2663126120b/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI=
github.com/google/renameio v1.0.0/go.mod h1:t/HQoYBZSsWSNK35C6CO/TpPLDVWvxOHboWUAweKUpk=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4=
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
github.com/google/subcommands v1.0.2-0.20190508160503-636abe8753b8/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
github.com/google/tcpproxy v0.0.0-20200125044825-b6bb9b5b8252 h1:tAkooHvRrtO8kFB6YOPTpLQok3Hfv1DNDXdNqgi29Ao=
github.com/google/tcpproxy v0.0.0-20200125044825-b6bb9b5b8252/go.mod h1:DavVbd41y+b7ukKDmlnPR4nGYmkWXR6vHUkjQNiHPBs=
Expand Down
15 changes: 15 additions & 0 deletions util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"os"
"runtime"
"strings"

"github.com/google/shlex"
"github.com/sirupsen/logrus"
)

// HomeDir returns the user home directory.
Expand Down Expand Up @@ -70,3 +73,15 @@ func RandomAvailablePort() int {

return listener.Addr().(*net.TCPAddr).Port
}

// ShellSplit splids cmd into arguments using.
func ShellSplit(cmd string) []string {
split, err := shlex.Split(cmd)
if err != nil {
logrus.Warnln("error splitting into args: %w", err)
logrus.Warnln("falling back to whitespace split", err)
split = strings.Fields(cmd)
}

return split
}

0 comments on commit 1df2ea3

Please sign in to comment.