Flatpak allows sandboxed apps to interact with the rest of the system via portals. Portals are simply D-Bus services that are designed to be safe to expose to untrusted apps.
Principles
There are several principles that have guided the design of the existing portals.
Keep the user in control
To achieve this, most portals will show a dialog to let the user accept or deny the applications’ request. This is not a hard rule — in some cases, a dialog is just not practical.
Avoid yes/no questions
Direct questions about permissions tend to be dismissed without much thought, since they get in the way of the task at hand. Therefore, portals avoid this kind of question whenever possible and instead just let the user get on with the task.
For example, when an app is requesting to open a file on the host, we just present the user with a fille chooser. By selecting a file, the user implicitly grants the application access to the file. Or he can cancel the file selection and implicitly deny the applications’ request.
Don’t be annoying
Nothing is worse than having to answer the same question over and over. Portals make use of a database to record previous decisions and avoid asking repeatedly for the same thing.
Practice
The database used by portals is called the permission store. The permission store is organized in tables, with a table for each portal that needs one. It has a D-Bus api, but it is more convenient to explore it using the recently added flatpak commands:
flatpak permission-list flatpak permission-list devices flatpak permission-list desktop-used-apps video/webm
The first command will list all permissions in all tables, the second will show the content of the “devices” table, and the last one will show just the row for video/webm in the “desktop-used-apps” table.
There are also commands that deal with permissions on a per-application basis.
flatpak permission-show org.gnome.Epiphany flatpak permission-reset org.gnome.Epiphany
The first command will show all the permissions that apply to the application, the second will remove all permissions for the application.
And more…
The most important table in the permission store is the “documents” table, where the documents portal stores information about host files that have been exported for applications. The documents portal makes the exported files available via a fuse filesystem at
/run/user/1000/doc
A useful subdirectory here is by-app, where the exported files are visible on a per-application bases (when setting up a sandbox, flatpak makes only this part of the document store available inside the sandbox).
It is instructive to browse this filesystem, but flatpak also has a dedicated set of commands for exploring the contents of the documents portal.
flatpak document-list flatpak document-list org.gnome.Epiphany
The first command lists all exported files, the second shows only the files that are exported for an individual application.
flatpak document-info $HOME/example.pdf
This command shows information about a file that is exported in the document portal, such as which applications have access to it, and what they are allowed to do.
Lastly, there are document-export and document-unexport commands that allow to add or remove files from the document portal.
Summary
If you want to explore how portals work, or just need to double-check which files an app has access to, flatpak has tools that let you do so conveniently.