balena-io / balena-cli

The official balena CLI tool.
Apache License 2.0
455 stars 141 forks source link

balena ssh: Cannot execute command on service / container #2342

Open pdcastro opened 3 years ago

pdcastro commented 3 years ago

It is possible to pipe a command to balena ssh <UUID> and get it executed on the host OS:

$ echo 'pwd; exit;' | DEBUG=1 balena ssh 21c67b8
...
[debug] [/usr/bin/ssh, -t, -o, LogLevel=ERROR, -o, StrictHostKeyChecking=no, -o, UserKnownHostsFile=/dev/null, gh_paulo_castro@ssh.balena-devices.com, host 21c67b8d08ac75f2aa457274050ea01c]
=============================================================
    Welcome to balenaOS
=============================================================
/home/root

However, the same does not work to run a command in a container / service, i.e. balena ssh <UUID> <service-name>:

$ echo 'pwd; exit;' | DEBUG=1 balena ssh 21c67b8 foo
...
[debug] [/usr/bin/ssh, -t, -o, LogLevel=ERROR, -o, StrictHostKeyChecking=no, -o, UserKnownHostsFile=/dev/null, gh_paulo_castro@ssh.balena-devices.com, enter 21c67b8d08ac75f2aa457274050ea01c dcad1660ec1a4d61b797957a422506d8ac6d22af5f0417e0c833c46627ddb021]

I understand this is a limitation of the balena-proxy backend service, which prevents stdin from being piped through to a container. The following issue needs to be resolved first: https://github.com/balena-io/balena-proxy/issues/466 (private repo).

Known Workarounds

pdcastro commented 3 years ago