Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USB portal (cont.) #1354

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft

USB portal (cont.) #1354

wants to merge 10 commits into from

Conversation

hfiguiere
Copy link
Collaborator

This supercede #1238

@hfiguiere hfiguiere force-pushed the usb-portal branch 2 times, most recently from cb66d92 to f28ffdf Compare May 6, 2024 02:29
refi64 and others added 5 commits May 18, 2024 20:44
The USB portal is the middleman between sandboxed apps, and the
devices connected and available to the host system. This is the
first version of the portal.

Device filtering
================

Sandboxed apps must declare which USB devices they support ahead
of time. This information is read by the XDG Desktop Portal and
used to determine which USB devices will be exposed to requesting
apps. On Flatpak, these allowed and blocked devices are set by the
"--usb" and "--no-usb" arguments against "flatpak build-finish"
and "flatpak run". "--devices=all" does not influence the portal.

Blocking a device always take precedence over allowing them, even
when a blanket permission ("--devices=all") is set.

Individual devices are assigned a unique identifier by the portal,
which is used for all further interactions. This unique identifier
is completely random and independent of the device. Permission
checks are in place to not allow apps to try and guess device ids
without having permission to access then.

Permissions
===========

There are 2 dynamic permissions managed by the USB portal in the
permission store:

 1. Blanket USB permission: per-app permission to use any methods
    of the USB portal. Without this permission, apps must not be
    able to do anything - enumerate, monitor, or acquire - with
    the USB portal. [1]

 2. Specific device permission: per-app permission to acquire a
    specific USB device, down to the serial number.

Enumerating devices
===================

There are 2 ways for apps to learn about devices:

 - Apps can call the EnumerateDevices() method, which gives a
   snapshot of the current devices to the app.

 - Apps can create a device monitoring session with CreateSession()
   which sends the list of available devices on creation, and also
   notifies the app about connected and disconnected devices.

Only devices that the app is allowed to see are reported in both
cases.

The udev properties exposed by device enumeration is limited to a
well known subset of properties. [2]

Device acquisition & release
============================

Once an app has determined which devices it wants to access, the
app can call the AcquireDevices() method. This method may prompt
a dialog for the user to allow or deny the app from accessing
specific devices.

If permission is granted, XDG Desktop Portal tries to open the
device file on the behalf of the requesting app, and pass down
the file descriptor to that file. [3]

Co-Authored By: Georges Basile Stavracas Neto
<[email protected]>

---

[1] Exceptionally, apps can release previously acquired devices,
even when this permission is disabled. This is so because we
don't yet have kernel-sided USB revoking. With USB revoking in
place, it would be possible to hard-cut app access right when
the app permission changes.

[2] This patch uses a hardcoded list. There is no mechanism for
apps to influence which other udev properties are fetched. This
approach is open to suggestions - it may be necessary to expose
more information more liberally through the portal.

[3] This is clearly not ideal. The ideal approach is to go through
logind's TakeDevice() method. However, that will add significant
complexity to the portal, since this logind method can only be
called by the session controller (i.e. the only executable capable
of calling TakeControl() in the session - usually the compositor).
This can and probably should be implemented in a subsequent round
of improvements to the USB portal.
- ignore if query is NULL
- don't add a NULL to the queries ptr_array

Signed-off-by: Hubert Figuière <[email protected]>
- It's device-file
- Release device doesn't need a window identifier

Signed-off-by: Hubert Figuière <[email protected]>
@hfiguiere hfiguiere force-pushed the usb-portal branch 2 times, most recently from 6cda6df to ce2b214 Compare May 20, 2024 00:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Needs Triage
Development

Successfully merging this pull request may close these issues.

None yet

2 participants