distrobox icon indicating copy to clipboard operation
distrobox copied to clipboard

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

Open tymonx opened this issue 1 year ago • 2 comments

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

  • The XAUTHORITY environment variable set using value from host side
  • GUI application is working

Logs

Desktop (please complete the following information):

  • Are you using podman, docker or lilipod?
podman
  • Which version or podman, docker or lilipod?
4.9.4
  • Which version of distrobox?
1.7.2.1
  • Which host distribution?
Kinoite 39
  • How did you install distrobox?
curl -s https://raw.githubusercontent.com/89luca89/distrobox/1.7.2.1/install | sh -s -- --prefix ~/.local

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 avatar May 09 '24 08:05 tymonx

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 avatar May 09 '24 09:05 tymonx

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.

tymonx avatar May 09 '24 10:05 tymonx