How to access files outside of /home in snap apps?

I have just upgraded to a recent version of Ubuntu that uses snap apps, and I have trouble understanding how I’m supposed to use them to work with files outside of /home. I have three disks in my machine, a large photo library on sdb, backup drives, and other things. As snap apps are confined, they cannot access any of them.

Only solution I can think of, is to bind mount everything to some folder under /home, but that seems like a terrible thing to do every single time I want to look at a file. Searching the web brings up blog posts about "snap interfaces" and "snap connections", but it is unclear to me if that could be helpful.

So the question is: What is the intended method for using snap apps to work with files stored outside of /home?

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

what is the intended method for using snap apps to work with files stored outside of /home?

The snap should be designed to do that under confinement by making use of the removable-media interface. Connecting such an interface will grant confined access to drives mounted in /media as well as /mnt.

To see if the snap in question supports this, run snap connections <snap name>. For example, for Nextcloud:

$ snap connections nextcloud
Interface        Plug                       Slot           Notes
network          nextcloud:network          :network       -
network-bind     nextcloud:network-bind     :network-bind  -
removable-media  nextcloud:removable-media  -              -

Since nextcloud:removable-media has no associated slot, that means the interface is not connect, thus Nextcloud cannot access removable media. To connect it, we can run sudo snap connect nextcloud:removable-media. Then the connections look like the following:

$ snap connections nextcloud
Interface        Plug                       Slot              Notes
network          nextcloud:network          :network          -
network-bind     nextcloud:network-bind     :network-bind     -
removable-media  nextcloud:removable-media  :removable-media  manual

Now that the plug is connected to a slot, Nextcloud now has confined access to removable media in /media/ and /mnt. Other applications will work the same way if the developer built such functionality in. If they didn’t, log a bug! You can find where to log a bug with snap info <snap name>, for example:

$ snap info nextcloud
<snip>
contact:   https://github.com/nextcloud/nextcloud-snap
<snip>

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply