89luca89 / distrobox

Use any linux distribution inside your terminal. Enable both backward and forward compatibility with software and freedom to use whatever distribution you’re more comfortable with. Mirror available at: https://gitlab.com/89luca89/distrobox
https://distrobox.it/
GNU General Public License v3.0
10.19k stars 419 forks source link

[Error] XAUTHORITY is not set because host-spawn is not working. Move env setup to distrobox-enter #1383

Closed tymonx closed 6 months ago

tymonx commented 6 months ago

This kinda a bug and change request /suggestion in the same time.

Describe the bug The XAUTHORITY environment variable is not set because the host-spawn is not working.

This is Linux distro and OS environment specific. Cannot reproduce easy without Virtual Machine.

  1. Install stable distrobox:
curl -s https://raw.githubusercontent.com/89luca89/distrobox/1.7.2.1/install | sh -s -- --prefix ~/.local
  1. Create new container using distrobox:
distrobox create --name <name> --init --image <image>
  1. Enter into created container:
distrobox enter <name>
  1. Try to print XAUTHORITY:
echo $AXUTHORITY

It will return nothing.

  1. Try to run anything using host-spawn:
host-spawn env

It will return nothing.

  1. Try to run any GUI application:
Authorization required, but no authorization protocol specified
Application initialization failed: couldn't connect to display ":0"

To Reproduce

Not that easy to reproduce that. Unknown reason why the host-spawn is not working. Linux distro specific, Kinoite version 39.

Expected behavior

Logs

Desktop (please complete the following information):

Additional context

I want to propose a change request. I can prepare a Pull Request. If we move setting the XAUTHORITY environment variable and XAUTH from the distrobox-init to the distrobox-enter and simple use --env container option, then we could remove need of host-spawn call from container side and simplify logic in the same time.

tymonx commented 6 months ago

It seems that distrobox enter adds --env XAUTHORITY=${XAUTHORITY} anyway in that generic for-loop: https://github.com/89luca89/distrobox/blob/1.7.2.1/distrobox-enter#L443

But still it is not present when doing:

env | grep XAUTHORITY

But if I run created container by distrobox create using podman exec:

podman exec --interactive --tty --detach-keys="" --user=root --workdir="${HOME}" --env XAUTHORITY <container> su "${USER}" --pty

Then the XAUTHORITY environment variable is not empty. I'm trying to narrow the issue here. Above command is also ran by distrobox enter. After podman exec and before <container> the distrobox enter adds bunch of additionals --env. Something is causing that the XAUTHORITY environment variable is unset after switching from root to user.

tymonx commented 6 months ago

Short story. When --env DISPLAY=:0 is present, it will clear XAUTHORITY. I have been using custom AlmaLinux OS 9.3 with added user etc.. Somehow when calling su "${USER}" --pty when switching from root to user by distrobox enter, it clears XAUTHORITY environment variable. With vanilla AlmaLinux OS 9.3 it doesn't happen.

Not working host-spawn in distrobox-init is OK/not relavant for me because it should be fixed by distrobox-enter and --env XAUTHORITY from this loop https://github.com/89luca89/distrobox/blob/1.7.2.1/distrobox-enter#L443

I will try to narrow problem in my custom container image based on AlmaLinux OS 9.3 and share minimum Dockerfile to reproduce that.