Xpra-org / xpra

Persistent remote applications for X11; screen sharing for X11, MacOS and MSWindows.
https://xpra.org/
GNU General Public License v2.0
1.98k stars 169 forks source link

cli ssh assumes host is command #2867

Closed totaam closed 4 years ago

totaam commented 4 years ago

Issue migrated from trac ticket # 2867

component: android | priority: major | resolution: fixed

2020-08-28 18:48:54: humbletang created the issue


I'm using xpra to start a graphical application on a host machine that is reached after 2 previous ssh connections. Unfortunately for some reason the way I write the connection command it has some problems. it currently treats the host of the xpra server as a command to run.

xpra start --ssh="ssh user@bastion ssh shell.bastion" ssh://user@activejob --remote-xpra="/home/u4/user/base_xpra" -d ssh
2020-08-28 10:46:03,287 parse_ssh_string(ssh user@bastion ssh shell.bastion)
Warning: vendor 'Intel Open Source Technology Center' is greylisted,
 you may want to turn off OpenGL if you encounter bugs
2020-08-28 10:46:04,207 Xpra GTK3 X11 client version 4.0.2-26625 64-bit
2020-08-28 10:46:04,319  running on Linux Ubuntu 20.04 focal
2020-08-28 10:46:04,322  window manager is 'GNOME Shell'
2020-08-28 10:46:04,349 Warning: failed to import opencv:
2020-08-28 10:46:04,349  No module named 'cv2'
2020-08-28 10:46:04,350  webcam forwarding is disabled
2020-08-28 10:46:04,669 GStreamer version 1.16.2 for Python 3.8.2 64-bit
2020-08-28 10:46:04,670 Warning: no pulseaudio information available
2020-08-28 10:46:04,670  No module named 'distutils.spawn'
2020-08-28 10:46:04,830 No OpenGL_accelerate module loaded: No module named 'OpenGL_accelerate'
2020-08-28 10:46:05,111 Warning: vendor 'Intel Open Source Technology Center' is greylisted,
2020-08-28 10:46:05,111  you may want to turn off OpenGL if you encounter bugs
2020-08-28 10:46:05,216 OpenGL enabled with Mesa DRI Intel(R) HD Graphics 4000 (IVB GT2)
2020-08-28 10:46:05,229 executing ssh command: "ssh" "user@bastion" "ssh" "shell.bastion" "-l" "user" "-T" "activejob" "sh -c 'xpra initenv;if [ -x /home/u4/user/base_xpra ]; then /home/u4/user/base_xpra _proxy_start "--ssh=ssh user@bastion ssh shell.bastion" "--debug=ssh" "--remote-xpra=/home/u4/user/base_xpra";else echo "no run-xpra command found"; exit 1; fi'"
2020-08-28 10:46:05,355  keyboard settings: rules=evdev, model=pc105, layout=us
2020-08-28 10:46:05,358  desktop size is 1366x768 with 1 screen:
2020-08-28 10:46:05,358   :0.0 (361x203 mm - DPI: 96x96) workarea: 1294x741 at 72x27
2020-08-28 10:46:05,358     BOE LVDS-1 (309x173 mm - DPI: 112x112)
bash: activejob: command not found
bash: line 2: syntax error near unexpected token `('
bash: line 2: `Tp��~�g�fc՟�&�V�&���L%\��Z�d3�{�ZX'�k���i�^�yb���Y�r���c�j�NZ@RfT�ibS����-Np�nJ�F�wbS���lI�W��+��!��0�)dr�ᤣ�j�5'�8�M[���&�B���n�M7*�k
                                                                    �N�[S����R�U�wZi��g�0_�����ĺ|�2�k��u��g9r�#��x�h���/�`/i�/O;�ЫN9Q��nDnڷ(2�<�Q�j:s7�o�]�'k��匎�Dz�#;�s��mW�ł��Wve+�Ŝ���80�i�~�`FG�����U+�VGw�����ذ3�
                                                       %
                                                        ����  ��Ŋ5Ә��ʆ�X�6\����Y;s���(���u˭7� ��Fa��s�<тr��8��歠޹�qo;
                                       �{�~`-��D�$��ɏ�oH���_�X�{�kY�nQRH�"3�r)��{�
�j5�M�vknՊЙ0uF%���ɛVĶ"g5��g�ّt�(P����}���ʆZ)�_�W��bwl�<R�4t�����ju��v+j�egӹl����@�hu���\��+dץ�n
              ,�K>1԰���=n���p��C'
/home/u4/user/base_xpra: line 2: singularity: command not found
2020-08-28 10:46:07,606 Error: failed to receive anything, not an xpra server?
2020-08-28 10:46:07,606   could also be the wrong protocol, username, password or port
2020-08-28 10:46:07,607   or the session was not found
2020-08-28 10:46:07,607 Connection lost
totaam commented 4 years ago

Here's a more simple test case, without using remote-xpra (which is not relevant to this ticket), and using variations on localhost to keep things simple.

First, no hop:

xpra attach --ssh="ssh -v" ssh://antoine@localhost/ -d ssh
parse_ssh_string(ssh -v)
executing ssh command: "ssh" "-v" "-l" "antoine" "-T" "localhost" \
    "sh -c 'xpra initenv;if .. exit 1; fi'"

With one hop - using 127.0.0.1 to distinguish it from localhost:

xpra attach --ssh="ssh -v -A localhost ssh -v" ssh://antoine@127.0.0.1/ -d ssh
parse_ssh_string(ssh -v -A localhost ssh -v)
executing ssh command: "ssh" "-v" "-A" "localhost" "ssh" "-v" "-l" "antoine" "-T" "127.0.0.1" "sh -c 'xpra initenv;if .. exit 1; fi'"

With two hops - using localhost.localdomain to distinguish that part:

xpra attach --ssh="ssh -v -A localhost ssh -v -A localhost.localdomain ssh -v" ssh://antoine@127.0.0.1/ -d ssh
parse_ssh_string(ssh -v -A localhost ssh -v -A localhost.localdomain ssh -v)
executing ssh command: "ssh" "-v" "-A" "localhost" "ssh" "-v" "-A" "localhost.localdomain" "ssh" "-v" "-l" "antoine" "-T" "127.0.0.1" "sh -c 'xpra initenv;if .. exit 1; fi'"

It still fails mysteriously with 2 hops, which I will investigate.


But your command was never going to work, it should have been something like:

xpra start --ssh="ssh user1@host1 ssh user2@host2 ssh" ssh://user3@host3

To go 1-2-3.

totaam commented 4 years ago

2020-09-17 18:45:55: humbletang commented


Thanks for looking into this further, and yes that last ssh in the --ssh="...... ssh" appears to be what was missing leading to the final host being treated as a command to run. I'm certainly still looking for ways to not require the numerous hops as that is the best case scenario, but that's not an xpra related issue =D. Thanks again!

totaam commented 4 years ago

This is because the command is being parsed multiple times.

We can't reliably count how many ssh strings we find in the ssh command to then decide how much escaping to do because ssh could also be used as an argument, ie: ssh -v -l ssh. But that's still better than nothing, so that's what I've done in r27578 and all the commands from comment:2 now work properly. This new code can be disabled with the XPRA_SSH_MAGIC_QUOTES=0 env var.

@humbletang: please test and close. (you can either apply the small patch or wait for the next beta builds)

totaam commented 4 years ago

2020-10-05 23:41:32: humbletang commented


Hi there,

Thanks for the info here. I'll make sure I add the extra escaped quotes where necessary and include the final "ssh" in the --ssh flag's contents if I'm trying to do multiple hops.

take care!

totaam commented 4 years ago

I'll make sure I add the extra escaped quotes

Adding quotes should not be needed. The new code should do the right thing.

You do need the final "ssh" in the command though.

totaam commented 4 years ago

Caused a regression with plink: #2891.