lima-vm / sshocker

ssh + reverse sshfs + port forwarder, in Docker-like CLI (predecessor of Lima)
Apache License 2.0
595 stars 29 forks source link

spaces in mount path causes failure to mount #10

Closed SvenDowideit closed 1 year ago

SvenDowideit commented 4 years ago

alternative Title: exec.Command with ssh doesn't work when there are spaces in args (I'm pondering how to best fix this for one of my apps too :) )

sven@x1carbon:/tmp/space path$ ./sshocker --debug -p 8080:80 -v .:/tmp/sshfs xeon
DEBU[0000] executing ssh for preparing sshfs: /usr/bin/ssh [ssh -o ControlMaster=auto -o ControlPath=~/.ssh/sshocker-%r@%h:%p-232029 -o ControlPersist=yes xeon -- mkdir -p /tmp/sshfs] 
DEBU[0000] executing ssh for remote sshfs: /usr/bin/ssh [ssh -o ControlMaster=auto -o ControlPath=~/.ssh/sshocker-%r@%h:%p-232029 -o ControlPersist=yes xeon -- sshfs :/tmp/space path /tmp/sshfs -o slave] 
DEBU[0000] starting sftp server for /tmp/space path     
DEBU[0000] generated script "wait-for-remote-ready" with map map[Dir:/tmp/sshfs MaxTrial:30]: "#!/bin/sh\nset -eu\ndir=\"/tmp/sshfs\"\nmax_trial=\"30\"\nLANG=C\nLC_ALL=C\nexport LANG LC_ALL\ni=0\nwhile : ; do\n  # FIXME: not really robust\n  if mount | grep \"on ${dir}\" | egrep -qw \"fuse.sshfs|osxfuse\"; then\n    echo '{\"return\":{}}'\n    exit 0\n  fi\n  sleep 1\n  if [ $i -ge ${max_trial} ]; then\n    echo >&2 \"sshfs does not seem to be mounted on ${dir}\"\n    exit 1\n  fi\n  i=$((i + 1))\ndone\n" 
DEBU[0000] executing ssh for script "wait-for-remote-ready": /usr/bin/ssh [ssh -o ControlMaster=auto -o ControlPath=~/.ssh/sshocker-%r@%h:%p-232029 -o ControlPersist=yes xeon -- /bin/sh] 
fuse: bad mount point `path': No such file or directory
DEBU[0000] sftp server for /tmp/space path exited with EOF (negligible)  error=EOF
DEBU[0031] executed script "wait-for-remote-ready", stdout="", stderr="sshfs does not seem to be mounted on /tmp/sshfs\n", err=failed to execute script "wait-for-remote-ready": stdout="", stderr="sshfs does not seem to be mounted on /tmp/sshfs\n": exit status 1 
WARN[0031] failed to confirm whether /tmp/sshfs [remote] is successfully mounted  error="failed to execute script \"wait-for-remote-ready\": stdout=\"\", stderr=\"sshfs does not seem to be mounted on /tmp/sshfs\\n\": exit status 1"
DEBU[0031] executing main SSH: /usr/bin/ssh [ssh -o ControlMaster=auto -o ControlPath=~/.ssh/sshocker-%r@%h:%p-232029 -o ControlPersist=yes -L 0.0.0.0:8080:localhost:80 xeon --] 
Last login: Thu Oct  8 10:03:54 2020 from 10.10.10.146
sven@xeon:~$ 
AkihiroSuda commented 4 years ago

exec.Command with ssh doesn't work when there are spaces in args

Injecting a shell script via stdin might be the easiest way

SvenDowideit commented 4 years ago

I was just playing with dumb ideas, and

    newArgs := append([]string{"ssh", "-4", hostname})
    for _, arg := range args {
        newArgs = append(newArgs, "\""+arg+"\"")
    }
    return RunLocally(newArgs...)

seems to "work"

AkihiroSuda commented 4 years ago

I think we can use this https://github.com/alessio/shellescape https://play.golang.org/p/xpUrKqkINqD