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

Camera: use an empty app id for host apps #1512

Merged
merged 1 commit into from
Dec 3, 2024

Conversation

grulja
Copy link
Contributor

@grulja grulja commented Nov 12, 2024

Sending an app id that doesn't resolve to valid app info (e.g. a desktop file is not found) will automatically reject camera request, because the backend is not able to verify whether the app (based on app id) runs in the background. Same will happen if the app id resolves to an app where our app was started from. This happens for example when you start apps
in GNOME using Alt + F2, where we get invalid app id from cgroups and since it doesn't find opened application window for this app, it will automatically reject the request. Using an empty id fixes this problem.

@grulja grulja requested a review from jadahl November 12, 2024 09:32
@grulja grulja force-pushed the only-resolved-app-id branch from e2deb6d to 655bfd7 Compare November 12, 2024 09:57
@grulja grulja changed the title Camera: use an empty app id in access dialog in case of empty app info Camera: use an empty app id in access dialog in case of invalid app id Nov 12, 2024
@grulja grulja force-pushed the only-resolved-app-id branch from 655bfd7 to 28439bd Compare November 12, 2024 11:00
@grulja grulja changed the title Camera: use an empty app id in access dialog in case of invalid app id Camera: use an empty app id in access dialog in case of empty app info Nov 12, 2024
@grulja grulja force-pushed the only-resolved-app-id branch from 28439bd to 4da5500 Compare November 12, 2024 11:41
Copy link
Collaborator

@swick swick left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current version looks good to me

@grulja grulja force-pushed the only-resolved-app-id branch from 4da5500 to be7f2f4 Compare November 12, 2024 13:14
@grulja
Copy link
Contributor Author

grulja commented Nov 12, 2024

@jadahl any final word? If no, can you merge it? I seem to have power to do it myself, but probably shouldn't as I'm not a maintainer here :)

@jadahl
Copy link
Collaborator

jadahl commented Nov 12, 2024

Since this changes policy about how to deal with permissions (even though only for non-sandboxed apps), I think we should let it sit here for a few days. If no objections, then it can land.

@grulja grulja force-pushed the only-resolved-app-id branch from 5df4a8f to 754d413 Compare November 20, 2024 09:41
@A6GibKm
Copy link
Contributor

A6GibKm commented Nov 20, 2024

Would it make sense to add a app-id option to the options in AccessCamera?

@swick
Copy link
Collaborator

swick commented Nov 20, 2024

If we want to provide a way for apps to specify their app id (only when the app id cannot be inferred) then it probably makes sense to add a new interface just for that to avoid having to add it to every portal.

IOW, I think this is out of scope here.

@jadahl
Copy link
Collaborator

jadahl commented Nov 20, 2024

Indeed out of scope, right now, the app id is always inferred and never explicitly set by apps.

@A6GibKm
Copy link
Contributor

A6GibKm commented Nov 20, 2024

Would a window handle improve the situation compared to an app-id? Anyways, yeah this is out of scope.

This MR looks good to me, but I missed an explanation of why the empty string fixes the issue.

@jadahl
Copy link
Collaborator

jadahl commented Nov 20, 2024

Would a window handle improve the situation compared to an app-id? Anyways, yeah this is out of scope.

Window handles are always about window management stacking order, i.e. placing a dialog on top of another window, which isn't needed here.

This MR looks good to me, but I missed an explanation of why the empty string fixes the issue.

It's to handle cases where one e.g. runs some app from a terminal and gets an cgroup that resolves to some bogus "app id". Detecting that and falling back to "" means the portal backend can handle it as "this is an unidentifiable app".

Copy link
Member

@GeorgesStavracas GeorgesStavracas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@grulja
Copy link
Contributor Author

grulja commented Nov 21, 2024

What happens with the set_permission_sync (app_id, ...) call below?

https://github.com/flatpak/xdg-desktop-portal/pull/1512/files#diff-3ca5b7fe0d5c5156df93b05804d4ef171f7db564c50377417500da159ee67ab4R153-R157

Not sure what you are thinking of, but it will store the permission with an invalid app-id. In the case I'm trying to fix it will store the permission for firefox so the next time it tries to get access to the camera (assuming FF is started the same way as before) it will not ask for permission. I already talked to Jonas about this before and there is no point trying to get the right app-id for non-sandboxed apps, because apps can easily pretend they are different app. Even starting apps from terminal will end up asking for access as the terminal app instead.

@jadahl
Copy link
Collaborator

jadahl commented Nov 21, 2024

Not sure what you are thinking of, but it will store the permission with an invalid app-id.

Might make more sense to put something more predictable there. I see 4 (or 5) options:

  1. Still pass around the actual app ID, but only if it resolves to a valid app info. If no app info, query with "" and store the response as "" in the permission store.
  2. Still pass around the actual app ID, but only if it resolves to a valid app info. If no app info, query with "" but never store anything in the permission store.
  3. Always pass around "" as the app ID for host apps, and store the response as "" in the permission store.
  4. Always pass around "" as the app ID for host apps, but never store any response in the permission store.

Option 1 means apps launched properly integrate properly, and when they are launched "incorrectly" (from a terminal, or anything else that doesn't create the right cgroup namespace) they will get the "global" permission. A bit inconsistent.

Option 2 means apps launched properly can remember permission, but when launched "incorrectly" they will be nagged every time. Also a bit inconsistent.

Option 3 means all host apps are treated as one single remembered thing, meaning once host Firefox is granted, it won't query later when any other host app asks for camera access.

Option 4 means all host apps get nagged every time no matter what.

What is done now is another thing: store a potentially arbitrary app ID in the permission store (e.g. completely random terminal session "id"), I think we probably should avoid.

Option 3 and 4 results in consistency, which I'd argue makes most sense.

Or perhaps there is a 5th option, which is option 3, but instead of the permission store, remember it for the current session only, meaning once you log in again next time, you'd be queried.

@grulja
Copy link
Contributor Author

grulja commented Nov 21, 2024

Might make more sense to put something more predictable there. I see 4 (or 5) options:
......

I'm in favor of Option 3, however, in such case it might make more sense to completely skip asking for permissions for host apps. Option 4, being nagged every time, is not going to be very well received by users. Option 2 is also going to be annoying, because people will be wondering why running apps in a different ways result into different behavior.

@A6GibKm
Copy link
Contributor

A6GibKm commented Nov 21, 2024

in such case it might make more sense to completely skip asking for permissions for host apps.

I am not sure this is the best, Yes, a host app could force its way to do whatever, but going through the permission system is a courtesy they can also choose to provide to the users.

@grulja
Copy link
Contributor Author

grulja commented Nov 21, 2024

in such case it might make more sense to completely skip asking for permissions for host apps.

I am not sure this is the best, Yes, a host app could force its way to do whatever, but going through the permission system is a courtesy they can also choose to provide to the users.

My point is that if we are going to ask just once for whatever host app that uses it first and have the others with granted access, then there is probably no point asking even the first time. This only in case we are going to treat all host apps as "global" and not using app ids, because it's not reliable.

@swick
Copy link
Collaborator

swick commented Nov 21, 2024

What's inconsistent about option 1?

Either way, I feel like trying to make things consistent by implementing any of those policies in all portals is not going to work out well. We need to enforce the policy at a single point in the code.

@Mikenux
Copy link

Mikenux commented Nov 24, 2024

Displaying a permission prompt means (1) that the permission is stored for the app requesting it, and (2) that only the right app can access the camera. If these conditions are not met, it is not a good idea to display a prompt.

Also, what is supposed to be displayed in this prompt? If it results in the wrong app name being displayed, it is not a good idea to display a prompt. There is (was?) this bug when launching an app from GNOME Software (e.g. launching Flameshot to get the screenshot permission prompt).

@grulja grulja force-pushed the only-resolved-app-id branch from 754d413 to 85b9e9f Compare November 26, 2024 12:41
@grulja
Copy link
Contributor Author

grulja commented Nov 26, 2024

Do we merge this change as is or do we make a decision how to do things differently? I would really like to get this sorted as soon as possible to fix Firefox and other apps.

@jadahl
Copy link
Collaborator

jadahl commented Nov 27, 2024

I think the reasonable thing is to land this as is, as we ideally should have a working Firefox using the xdg-desktop-portal 1.18 stable branch. To get host apps get more reliable identifiable is complicated, and unlikely something we can fix in 1.18, and whether to always use "" for all portals globally probably needs further discussion and looking at each portal individually if it makes sense. Having Firefox working during that time would be good.

@jadahl
Copy link
Collaborator

jadahl commented Nov 27, 2024

I think the reasonable thing is to land this as is

Or rather, I mean option 3 here. I read the current code wrong, the "is host app" condition is always TRUE in the branch it's called in, and the current version makes firefox not getting access to the camera if it happens to be opened within the same cgroup as some other application.

@grulja grulja force-pushed the only-resolved-app-id branch from 85b9e9f to f2aa1cf Compare November 27, 2024 11:11
@grulja grulja changed the title Camera: use an empty app id in access dialog in case of empty app info Camera: use an empty app id for host apps Nov 27, 2024
@grulja
Copy link
Contributor Author

grulja commented Nov 27, 2024

Changed to Option 3 suggested by @jadahl.

Sending an app id that doesn't resolve to valid app info (e.g. a desktop
file is not found) will automatically reject camera request, because the
backend is not able to verify whether the app (based on app id) runs in
the background. Same will happen if the app id resolves to an app where
our app was started from. This happens for example when you start apps
in GNOME using Alt + F2, where we get invalid app id from cgroups and
since it doesn't find opened application window for this app, it will
automatically reject the request. Using an empty id fixes this problem.
@jadahl jadahl force-pushed the only-resolved-app-id branch from 8ad2422 to 0be2462 Compare December 3, 2024 13:47
@jadahl jadahl merged commit 6cd99b0 into flatpak:main Dec 3, 2024
5 checks passed
@jadahl
Copy link
Collaborator

jadahl commented Dec 3, 2024

Merging as a stop gap solution until the host app identification situation has improved.

@swick
Copy link
Collaborator

swick commented Dec 3, 2024

The code could have used some comments tbh...

@Mikenux
Copy link

Mikenux commented Dec 3, 2024

Option 3 means having a different permission model. Currently, permissions are tied to sandboxed apps and per app. With option 3, permissions are now tied to host apps and also asked generally. It is possible to have, but it will results in three kind of apps instead of two: host (unsandboxed) apps without portals, host apps with portals, and sandboxed apps (with or without portals). If granting access for all host apps one time, one might not know that some host apps are not using any permission.

@mcatanzaro
Copy link
Contributor

@grulja
Copy link
Contributor Author

grulja commented Jan 15, 2025

This introduced a regression: Camera permissions not set when snapshot launched from overview rather than from terminal.

You are absolutely right in your findings. We missed that the permission is also being queried in OpenPipeWireRemote.

@grulja
Copy link
Contributor Author

grulja commented Jan 15, 2025

This is my fault. Even though I have been testing this with Firefox, we have a fallback in case of a Camera portal failure and we fallback to V4L2 instead so that's why I missed this.

@mcatanzaro
Copy link
Contributor

Fix: #1572

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Triaged
Development

Successfully merging this pull request may close these issues.

7 participants