-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Problem/Opportunity
The --x11 option does not add the required lines to the .Xauthority file inside the docker.
Steps to reproduce
sc docker run <example image> --x11 bash
xauth: file /home/user/.Xauthority does not exist
xauth: (argv):1: key contains odd number of or non-hex characters
Expected Behavior
Prior to running the docker run command, the users .Xauthority file should be read for their display (found in the DISPLAY env variable). Once the container has started, an .Xauthority file should be created in the internal users home directory and the line that was read prior should be written into it, with the hostname changed to that of the docker. This along with forwarding the DISPLAY env variable should allow the user to use X11 forwarding from inside the docker container.
In bash this looks like
if [[ "${docker_x11}" == "1" ]];then
# Grab the line for the user display from their xauthority file
local xauth_line="$(xauth list $DISPLAY || false)"
# Change the host name of the display to the internal hostname of the docker
xauth_line=${xauth_line/${HOSTNAME}/${docker_image_name}}
# When the docker starts it needs to create an Xauthority file for the interal user in the docker
# Then the modified xauth line for the users display needs to be added to it
# this is required for using the x11 display from inside the docker
docker_shell_command=( 'touch $HOME/.Xauthority;' "xauth add ${xauth_line};" ${docker_shell_command[@]} )Actual Behavior
It currently is reading the hosts $HOME variable, rather than the one inside the container, and creating the .Xauthority file there. It is also not doing the find and replace correctly for the xauth add and it's leading to it having both the old hash and new replaced hash concatenated together with /None/ in the middle.
touch /home/<username on host>/.Xauthority; xauth add <host machine name>/unix:15 MIT-MAGIC-COOKIE-1 1091429e792dc77b4aa193bd38ae1998/None/<username on host>_gstreamer-playground_1765984356-400619520
When this has run once, it breaks the users current .Xauthority file on the host, meaning sc docker cannot read it on subsequent runs, leading to the following error.
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "/opt/pyenv/pyenvironments/versions/sc/lib/python3.11/site-packages/sc/__main__.py", line 4, in <module>
entry_point()
File "/opt/pyenv/pyenvironments/versions/sc/lib/python3.11/site-packages/sc/cli.py", line 49, in entry_point
cli()
File "/opt/pyenv/pyenvironments/versions/sc/lib/python3.11/site-packages/click/core.py", line 1485, in __call__
return self.main(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/pyenv/pyenvironments/versions/sc/lib/python3.11/site-packages/click/core.py", line 1406, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "/opt/pyenv/pyenvironments/versions/sc/lib/python3.11/site-packages/click/core.py", line 1873, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/pyenv/pyenvironments/versions/sc/lib/python3.11/site-packages/click/core.py", line 1873, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/pyenv/pyenvironments/versions/sc/lib/python3.11/site-packages/click/core.py", line 1269, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/pyenv/pyenvironments/versions/sc/lib/python3.11/site-packages/click/core.py", line 824, in invoke
return callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/pyenv/pyenvironments/versions/sc/lib/python3.11/site-packages/sc/docker_cli.py", line 49, in run
SCDocker().run(
File "/opt/pyenv/pyenvironments/versions/sc/lib/python3.11/site-packages/sc/docker/docker.py", line 132, in run
docker_command = self._generate_docker_run_command(image, tag, container_name, image_name, x11, volumes, command)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/pyenv/pyenvironments/versions/sc/lib/python3.11/site-packages/sc/docker/docker.py", line 489, in _generate_docker_run_command
docker_args += [f"{image}:{tag}", self._generate_bash_command(command, container_name, x11)]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/opt/pyenv/pyenvironments/versions/sc/lib/python3.11/site-packages/sc/docker/docker.py", line 501, in _generate_bash_command
bash_command += self._setup_xauth(container_name)
TypeError: can only concatenate str (not "NoneType") to str
sc docker run needs to test the .Xauthority file exists and xauth list $DISPLAY is successful otherwise it should warn the user that x11 isn't possible, before launching the container.
Notes (Optional)
No response