Environment overwrites XDG_DATA_DIRS

Bug #1801814 reported by Sebastian Cruz
20
This bug affects 3 people
Affects Status Importance Assigned to Milestone
flatpak (Ubuntu)
Fix Released
Undecided
Andrew Hayzen
Focal
Fix Released
Undecided
Andrew Hayzen

Bug Description

[Impact]

Flatpak gdm environment overwrites any custom configuration (eg in ~/.config/environment.d ) while using the Wayland session.

[Test Case]

Create a local environment configuration

$ mkdir -p ~/.config/environment.d
$ echo "XDG_DATA_DIRS=${XDG_DATA_DIRS}:/tmp" >> ~/.config/environment.d/test.conf

Reboot and ensure you use the Wayland session. Then check your XDG_DATA_DIRS from systemctl, the issue occurs when /tmp is not set, the issue is resolved if it is set.

$ systemctl --user show-environment |grep XDG_DATA_DIRS

[Regression Potential]

Low. This only affects users using the Wayland session with a custom environment (which are both non-standard configuration).

[Original Description]

Package contains this file:

/usr/share/gdm/env.d/flatpak.env

With this single line content:

XDG_DATA_DIRS=$HOME/.local/share/flatpak/exports/share/:/var/lib/flatpak/exports/share/:/usr/local/share/:/usr/share/

This is setting the XDG_DATA_DIRS variable, irrespective of it's preexisting value.

In my system I have snapd installed and I have a local configuration for that variable under .config/environment.d/, which gets overwritten and causes issues.

----

1) The release of Ubuntu you are using, via 'lsb_release -rd' or System -> About Ubuntu

Description: Ubuntu 18.10
Release: 18.10

2) The version of the package you are using, via 'apt-cache policy pkgname' or by checking in Software Center

flatpak:
  Installed: 1.0.4-1
  Candidate: 1.0.4-1
  Version table:
 *** 1.0.4-1 500
        500 http://ie.archive.ubuntu.com/ubuntu cosmic/universe amd64 Packages
        100 /var/lib/dpkg/status

3) What you expected to happen

To have XDG_DATA_DIRS variable populated with the package's value as well as my own.

4) What happened instead

Only the configuration from flatpak's package survived.

ProblemType: Bug
DistroRelease: Ubuntu 18.10
Package: flatpak 1.0.4-1
ProcVersionSignature: Ubuntu 4.18.0-10.11-generic 4.18.12
Uname: Linux 4.18.0-10-generic x86_64
ApportVersion: 2.20.10-0ubuntu13
Architecture: amd64
CurrentDesktop: GNOME
Date: Tue Nov 6 00:55:32 2018
InstallationDate: Installed on 2018-05-16 (173 days ago)
InstallationMedia: Ubuntu 18.04 LTS "Bionic Beaver" - Release amd64 (20180426)
SourcePackage: flatpak
UpgradeStatus: Upgraded to cosmic on 2018-10-18 (18 days ago)

Revision history for this message
Sebastian Cruz (default50) wrote :
Revision history for this message
Andrew Hayzen (ahayzen) wrote :

Thank you for taking the time to report this bug and helping to make Ubuntu better.

The .config/environment.d docs [0] and some info around gdm/env.d [1] don't seem to be too clear which order they would be loaded. But I would expect that the system gdm is loaded first then the local user one. So it seems strange that your local environment.d doesn't override.

The flatpak.env file is located here [2] upstream, I would report a bug upstream [3] as they may have more ideas as to how to resolve this issue. Also providing your local configuration file in .config/environment.d may be useful.

Testing this myself, if i run "/usr/lib/systemd/user-environment-generators/30-systemd-environment-d-generator" it shows the correct override of XDG_DATA_DIRS, but "systemctl --user show-environment" doesn't show XDG_DATA_DIRS being overridden - however it does show additional env vars.

So it could be something odd happening in systemd ? I'm unsure if this is specifically a flatpak bug yet, lets see what upstream and others say.

0 - https://www.freedesktop.org/software/systemd/man/environment.d.html
1 - https://wiki.gnome.org/Initiatives/Wayland/SessionStart#Environment_variables
2 - https://github.com/flatpak/flatpak/blob/master/env.d/flatpak.env.in
3 - https://github.com/flatpak/flatpak/issues

Revision history for this message
Andrew Hayzen (ahayzen) wrote :

I also wonder if /etc/profile.d/ are having an affect, as in there I have flatpak.sh and xdg_dirs_desktop_session.sh. [4] mentions how the order of loading these was incorrect at one point in time for Debian and GNOME systems (but this was for PATH which is more of a special case). Also I'm not super familiar with the sequence of how these are loaded, so might be wrong :-)

4 - https://github.com/systemd/systemd/issues/6414

Revision history for this message
Sebastian Cruz (default50) wrote :

Should've mentioned that this happens when using GNOME session under Wayland.

Initially I found (IIRC on another Ubuntu bug) that snaps would not have icons showing in GNOME, and traced it back to XDG_DATA_DIRS not being correctly set for Wayland since there's no shell parsing .profile, .bashrc and the likes when initiating session. The workaround I successfully implemented was by adding this environment.d configuration:

    $ cat .config/environment.d/60-snap-icons-and-bin.conf
    PATH=$PATH:/snap/bin
    XDG_DATA_DIRS=${XDG_DATA_DIRS:-/usr/local/share:/usr/share}:/var/lib/snapd/desktop

At some point after that I installed flatpak and that overrides the config as I'm mentioning in this report. Took a while for me to pinpoint it to this interaction since I only noticed the issue after a reboot, which I seldomly do, and not just after installing flatpak.

For the record, I do have /etc/profile.d/flatpak.sh in place.

I did my homework now and reviewed upstream issues [0]. There are 2 already reported issues related to this especifically (flatpak vs snap), [1] and [2]. Then there's a more general bug report, regarding XDG_DATA_DIRS, from GNOME here [3]. And lastly, there's an apparent fix for this as a pull request for flatpak here [4], which is very recent.

So maybe it's just a matter of relating this bug to those and just track them until the solution is implemented?

[0] - https://github.com/flatpak/flatpak/issues
[1] - https://github.com/flatpak/flatpak/issues/25
[2] - https://github.com/flatpak/flatpak/issues/2087
[3] - https://gitlab.gnome.org/GNOME/glib/issues/1176
[4] - https://github.com/flatpak/flatpak/pull/2122

Revision history for this message
Andrew Hayzen (ahayzen) wrote :

Thanks for investigating further, yes [0] seems to be the issue upstream. I'll keep an eye on the pull request/issue and hopefully it will land into a release that can be SRU'd :-)

0 - https://github.com/flatpak/flatpak/issues/25

Changed in flatpak (Ubuntu):
status: New → Confirmed
Revision history for this message
Nick Zatkovich (nzatkovich) wrote :

Confirming this bug. More distressingly, after removing flatpak from my system with apt, this change persisted; it left /etc/profile.d/flatpak.sh on my system which would automatically run on my main user, since it still had some leftover files in .local/share/flatpak, and would crash the desktop session upon logging in when it couldn't find relevant dependency.

Revision history for this message
dasojdaosidasoi (asdadfjuoasd-deactivatedaccount) wrote :

this is still happening on ubuntu 20.04

Revision history for this message
Geoff Hickey (trapgate) wrote :

I've just run into this on 20.04 also. Installing flatpak broke all the snaps in my Wayland session because of the way flatpak overwrites the XDG_DATA_DIRS envar. It doesn't break snaps in xorg sessions.

Removing flatpak to try to make Wayland sessions usable again breaks gnome-session on both xorg and Wayland. It crashes on login with this error:

Jul 07 02:48:51 serenity gnome-session[3205]: gnome-session-binary[3205]: GLib-GIO-ERROR: No GSettings schemas are installed on the system
Jul 07 02:48:51 serenity gnome-session[3205]: aborting...
Jul 07 02:48:51 serenity gnome-session-binary[3205]: GLib-GIO-ERROR: No GSettings schemas are installed on the system
                                                     aborting...

I've tried various things to try to get flatpak off the system, but no luck. Wayland is still broken.

The upstream bugs here are all closed, but the bugfixes aren't effective on Wayland sessions, and the uninstall problems appear to be new.

Revision history for this message
Simon McVittie (smcv) wrote :

This is believed to be fixed by version 1.8.1-1, which converts the gdm env.d fragment into an example file (moving it from usr/share/gdm/env.d to usr/share/doc/flatpak/examples/etc/gdm3/env.d). If Ubuntu developers want to backport that change to 20.04, please see commit b634ea2a in the Debian packaging.

Revision history for this message
Andrew Hayzen (ahayzen) wrote :

@smcv Thanks for the info ! I'm going to look at backporting that change into 20.04 with the 1.6.5 SRU I'm currently doing.

Changed in flatpak (Ubuntu):
status: Confirmed → In Progress
assignee: nobody → Andrew Hayzen (ahayzen)
Andrew Hayzen (ahayzen)
description: updated
Changed in flatpak (Ubuntu):
status: In Progress → Fix Released
Andrew Hayzen (ahayzen)
Changed in flatpak (Ubuntu Focal):
status: New → In Progress
assignee: nobody → Andrew Hayzen (ahayzen)
Changed in flatpak (Ubuntu Bionic):
status: New → Confirmed
Revision history for this message
Chris Halse Rogers (raof) wrote : Please test proposed package

Hello Sebastian, or anyone else affected,

Accepted flatpak into focal-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/flatpak/1.6.5-0ubuntu0.1 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested, what testing has been performed on the package and change the tag from verification-needed-focal to verification-done-focal. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-focal. In either case, without details of your testing we will not be able to proceed.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance for helping!

N.B. The updated package will be released to -updates after the bug(s) fixed by this package have been verified and the package has been in -proposed for a minimum of 7 days.

Changed in flatpak (Ubuntu Focal):
status: In Progress → Fix Committed
tags: added: verification-needed verification-needed-focal
Revision history for this message
Andrew Hayzen (ahayzen) wrote :

Awesome, thanks !

I have run the flatpak test plan on a Focal VM, which passed all tests successfully - I have noted the version of flatpak used below. Autopkgtest's are also passing. I have also used the test case for this bug to ensure the environment variables are set correctly in a Wayland session - which passed successfully. Therefore I am marking this as verification-done-focal.

$ apt policy flatpak
flatpak:
  Installed: 1.6.5-0ubuntu0.1
  Candidate: 1.6.5-0ubuntu0.1
  Version table:
 *** 1.6.5-0ubuntu0.1 500
        500 http://gb.archive.ubuntu.com/ubuntu focal-proposed/universe amd64 Packages
        100 /var/lib/dpkg/status
     1.6.3-1 500
        500 http://gb.archive.ubuntu.com/ubuntu focal/universe amd64 Packages

tags: added: verification-done-focal
removed: verification-needed-focal
Revision history for this message
Chris Halse Rogers (raof) wrote : Update Released

The verification of the Stable Release Update for flatpak has completed successfully and the package is now being released to -updates. Subsequently, the Ubuntu Stable Release Updates Team is being unsubscribed and will not receive messages about this bug report. In the event that you encounter a regression using the package from -updates please report a new bug using ubuntu-bug and tag the bug report regression-update so we can easily find any regressions.

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package flatpak - 1.6.5-0ubuntu0.1

---------------
flatpak (1.6.5-0ubuntu0.1) focal; urgency=medium

  * New upstream release 1.6.5 (LP: #1884594)
    - Backports some of the OCI authenticator fixes from the 1.7 series
    - Fix a use-after free in libflatpak
    - Don't list p2p downgrades in list of available updates
    - Install gdm env.d fragment, but only as an example file.
      It is harmful on systems where environment.d(5) works (in particular
      systems using systemd), because it overwrites additions to the
      XDG_DATA_DIRS coming from other app frameworks like Snap.
      However, using either this fragment or manual configuration might
      be necessary on non-systemd systems. See
      /usr/share/doc/flatpak/README.Debian for more details. (LP: #1801814)
    - debian/flatpak.README.Debian: Add

 -- Andrew Hayzen <email address hidden> Wed, 08 Jul 2020 00:34:35 +0000

Changed in flatpak (Ubuntu Focal):
status: Fix Committed → Fix Released
no longer affects: flatpak (Ubuntu Bionic)
Revision history for this message
Andrew Hayzen (ahayzen) wrote :

Not sure why this bug has been marked as "no longer affects Ubuntu Bionic", it was only fixed in Focal and Groovy, I believe Bionic could still have the bug.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.