Hey everyone,
In Cannot run X applications on openSUSE Tumbleweed when using KDE we discussed a problem found in openSUSE where applications packaged as a snap doesn’t start in a KDE environment. Reason for this is that the necessary X11 authentication cookies are stored in a file inside /tmp on the host which isn’t shared with a snap.
Our X11 interface currently allows access to the following possible locations of the file specified in the XAUTHORITY environment variable:
# .ICEauthority files required for X authentication, per user
owner @{HOME}/.ICEauthority r,
# .Xauthority files required for X connections, per user
owner @{HOME}/.Xauthority r,
owner /{,var/}run/gdm{,3}/*/database r,
owner /{,var/}run/lightdm/authority/[0-9]* r,
owner /{,var/}run/lightdm/*/xauthority r,
owner /{,var/}run/user/*/gdm/Xauthority r,
If the XAUTHORITY environment variable points to one of these files we don’t have a problem and everything works as it should. However in some environments like KDE on openSUSE we can’t rely on this and don’t have the ability to fix the location of the file XAUTHORITY points to. Therefor we need to find another way to handle this problem more in general than only relying on a path we know and have in our AppArmor profiles.
I talked a bit with @zyga on IRC about possible solutions and what we came up with is the following:
When snap run gets executed, we parse the current XAUTHORITY environment variable and copy the file it points to into XDG_RUNTIME_DIR of the current user, more precisely at /run/user/$UID/snap.$SNAP_NAME/Xauthority. Afterwards we set XAUTHORITY to the new path. The snap application will still need to get access to that file by using the x11 interface, which will get an update to allow access the path too.
A preliminary implementation of this can be found here which I will submit as a PR once we agreed that this is the way forward.