View previous topic :: View next topic |
Author |
Message |
minkanjin n00b

Joined: 29 Jan 2017 Posts: 49
|
Posted: Thu Feb 27, 2025 12:03 pm Post subject: Partially sandboxing apps with permission intersections |
|
|
So this is a bit more of a thought experiment to see if I understand the permission system correctly. I had the idea that it might be possible to get better security by “sandboxing” apps by using permission intersections. i.e. Both the current user and the app’s owner is used to determine access.
The idea is that both the user and the executable must have permissions to access to a file. This would of course require that the app has its own user account. Then the user adds the app to the ACL of a file the user owns. This way the app can only access files that is owned by the current user, and was given explicit permissions to the app by the user.
Since root has access to almost everything (except sometimes things mounted through fuse), any executable owned by root would have access to everything the current user has access to.
If such apps each have their own user accounts, it makes it possible to control which users have access to which apps by adding users to the app’s group. So that is also added security.
As far as I know, the sticky bit is not used for executables. So maybe the sticky bit can be repurposed to enable the old behaviour for executables that have not yet been ported to the new way of doing things. This would of course require us to trust whoever installed the executable, but that is also a problem with the current system anyway.
I think this might give part of the sandboxing that flatpak has. I suspect this is already implemented in one of the extended permission systems, but most people don’t know how to use those. This seems like a fairly simple way to bring this feature to everyone. |
|
Back to top |
|
 |
szatox Advocate

Joined: 27 Aug 2013 Posts: 3527
|
Posted: Thu Feb 27, 2025 12:38 pm Post subject: |
|
|
Congratulations, you have just invented suid. It is actually what su and sudo use to upgrade privileges from regular user to root (before possibly dropping them to a different user). Hell, it even uses sticky bit
I think the only point you're trying to do differently is intersecting permissions.
Linux grants "user" access when application's user own the file, "group" access when user doesn't own the file but does belong to the group owning the file, and "other" access when neither condition is met.
ACL does the same thing, except you can have multiple alternative entries. Alternative = additive permissions. Not: intersecting = multiplicative.
You can apply additional restrictions (-x) on the parent directory though. Ugly workaround and not very convenient, but it does result in intersecting permissions. _________________ Make Computing Fun Again |
|
Back to top |
|
 |
pingtoo Veteran


Joined: 10 Sep 2021 Posts: 1515 Location: Richmond Hill, Canada
|
Posted: Thu Feb 27, 2025 12:43 pm Post subject: |
|
|
It sound like that "sandboxing" tool need to have a way to configure to know how to add/remove additional user into ACL.
I think current flatpak (a sandboxing tool) does not have this capability. Are you suggestion double sandboxing and expect the outter box somehow influence the inner sandbox? |
|
Back to top |
|
 |
minkanjin n00b

Joined: 29 Jan 2017 Posts: 49
|
Posted: Thu Feb 27, 2025 12:49 pm Post subject: |
|
|
@szatox, maybe I don't understand correctly. I understood suid as changing the user. My idea is keep the user the same, but restrict the app. Very much a reduction in privileges, which is very different from suid as I understand it. |
|
Back to top |
|
 |
minkanjin n00b

Joined: 29 Jan 2017 Posts: 49
|
Posted: Thu Feb 27, 2025 12:54 pm Post subject: |
|
|
"It sound like that "sandboxing" tool need to have a way to configure to know how to add/remove additional user into ACL."
Yes, someone would have to develop user friendly interfaces for this. At the moment there is only the old fashioned way to do it.
As I understand flatpak from the GUI, apps are only given access to files that they need. With a tool like flatseal, you can give it access to more files that you own. I want to give more or less the same thing for apps outside flatpak.
This is not to extend flatpak, it is for the system in general. Flatpak is just the example of where I've seen this before. |
|
Back to top |
|
 |
NeddySeagoon Administrator


Joined: 05 Jul 2003 Posts: 54929 Location: 56N 3W
|
Posted: Thu Feb 27, 2025 2:24 pm Post subject: |
|
|
minkanjin,
Maybe you want SELinux? _________________ Regards,
NeddySeagoon
Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail. |
|
Back to top |
|
 |
pingtoo Veteran


Joined: 10 Sep 2021 Posts: 1515 Location: Richmond Hill, Canada
|
Posted: Thu Feb 27, 2025 2:34 pm Post subject: |
|
|
minkanjin,
In linux there is unshare(1) which is sandbox command line tool. may be you can look it up to see if that fit your idea.
In gentoo it is possible to use /usr/bin/sandbox to do something you described.
Then there is bubblewrap which is tool used by flatpak it also could be something you want to investigate.
All in all they are using namespaces(7) concept in linux kernel so you can also check on that. |
|
Back to top |
|
 |
minkanjin n00b

Joined: 29 Jan 2017 Posts: 49
|
Posted: Thu Feb 27, 2025 4:07 pm Post subject: |
|
|
I expected that SELinux would get mentioned. From what I understand it is quite dense. It has a whole bunch of features that most people won't use, and the learning curve is steep. Correct me if I'm wrong.
The only thing I (and most users) need, is a way to prevent closed source apps from harvesting my data. I think SELinux is too much for that.
From what I've heard, AppArmor was invented to simplify SELinux into what someone like me needs. But for some reason it hasn't really gained much popularity (Why is that?).
I think the best option is probably some combination of bubblewrap/firejail/apparmor. I'm just exploring the idea of doing it in a more basic linux without extensions. |
|
Back to top |
|
 |
minkanjin n00b

Joined: 29 Jan 2017 Posts: 49
|
Posted: Thu Feb 27, 2025 4:12 pm Post subject: |
|
|
The only problems I foresee at the moment, is that maintaining file permissions might become a lot of work. There would need to be tools to help clean up permissions when app is no longer wanted, etc.
The other problem is if I install an app under my own ownership, it would have access to all my files. So I would have to be mindful of how I install games from GOG, etc. |
|
Back to top |
|
 |
minkanjin n00b

Joined: 29 Jan 2017 Posts: 49
|
Posted: Thu Feb 27, 2025 4:20 pm Post subject: |
|
|
I also have a related question: The Gentoo repo has a few closed source binaries that are currently not sandboxed. That bothers me a bit. Which system would be easiest to implement into portage? |
|
Back to top |
|
 |
szatox Advocate

Joined: 27 Aug 2013 Posts: 3527
|
Posted: Thu Feb 27, 2025 4:54 pm Post subject: |
|
|
Quote: | @szatox, maybe I don't understand correctly. I understood suid as changing the user. My idea is keep the user the same, but restrict the app. Very much a reduction in privileges, which is very different from suid as I understand it. | Su doesn't change user. It changes credentials.
User is the dude sitting in front of the terminal. Credentials is what interacts with access restrictions.
The distinction doesn't make any difference like 99,9% of the time, so we're calling it "user" while we're actually tracking "credentials" and comparing them to "access restrictions" called "permissions" to give people like me something to pick on
Anyway, dropping privileges (by login program, by system services, and by start-stop-daemon in case of services which can't be asked to stop being root) is nothing new on unix-like systems, but those programs do it in runtime, via a system call. This system call requires root privileges, which regular users don't have.
Suid does not require a system call and _can_ elevate privileges, because children are created on behalf of parent by the kernel, which already has all privileges. Kernel is aware of the suid flag and changes its behavior to create a new process with "credentials" derived from "access restrictions" on a flagged "program" rather than inherited from the parent.
So... It'd say it's a classic problem of "categorization is difficult".
Quote: | The Gentoo repo has a few closed source binaries that are currently not sandboxed | What do you mean by that?
Actually, it brings me to a question I think you wanted to ask but didn't know how to word it: Yes, you can restrict an an application by running it as a different user, and yes, you can use suid for that.
Bear in mind that default umask used by Gentoo is not strict enough. By default "others" can enter almost all directories and read almost all files, and I don't think there is any easy way to fix it on an already installed system. Running an application with credentials changed to some other user will prevent changes to most of your files, but it will not stop it from spying on you. _________________ Make Computing Fun Again |
|
Back to top |
|
 |
pingtoo Veteran


Joined: 10 Sep 2021 Posts: 1515 Location: Richmond Hill, Canada
|
Posted: Thu Feb 27, 2025 5:02 pm Post subject: |
|
|
I would do it this way,
write a script that will bind mount everything necessary for the application into do a directory (pretend it is root), use this script to first bind-mount everything necessary for the use. And call command line argument (unshare) to box in the usage.
pseudo logic: | my_bindmount_script \
/usr/bin/unshare --mount --user /path/to/my-app ... |
here the my_bindmount_script will perform all the bind-mounting and call unshare and wait for unshare to finish then unmount all the bind-mounts. So it is possible that in the my_bindmount_script perform permission changes to give the app in a different user namespace so it have right to access those bind-mounted files/directories.
Or you can just use docker do exactly above without write the my_bindmount_script.
Docker already in gentoo. so it is relative easy to do all that. |
|
Back to top |
|
 |
NeddySeagoon Administrator


Joined: 05 Jul 2003 Posts: 54929 Location: 56N 3W
|
Posted: Thu Feb 27, 2025 5:10 pm Post subject: |
|
|
pingtoo,
qubes-os does something similar. It runs each app in its own virtual machine, or used to. _________________ Regards,
NeddySeagoon
Computer users fall into two groups:-
those that do backups
those that have never had a hard drive fail. |
|
Back to top |
|
 |
pingtoo Veteran


Joined: 10 Sep 2021 Posts: 1515 Location: Richmond Hill, Canada
|
Posted: Thu Feb 27, 2025 5:17 pm Post subject: |
|
|
NeddySeagoon wrote: | pingtoo,
qubes-os does something similar. It runs each app in its own virtual machine, or used to. |
Thanks for the information.
I like the concept. I always been thinking how to create a OSE (Operating System Environment) right at kernel mounting rootfs that will isolate everything (including system services). Always want to learn more from others doing it. |
|
Back to top |
|
 |
minkanjin n00b

Joined: 29 Jan 2017 Posts: 49
|
Posted: Thu Feb 27, 2025 11:52 pm Post subject: |
|
|
Either what I want is different from suid, or I don't understand suid. I understand suid like this: if I have access to the GPU and the soundcard, and the app has access to the network and the soundcard, then suid would drop my access to the GPU and give me access to the network. So I would end up with access to the network and the soundcard, just like the app.
That is not what I want. I want to lose access to the GPU, without gaining access to the network. So I end up with only access to the soundcard. The only privilege in the intersection is the soundcard.
Yes, umask would have to change. What makes it worse is that Gnome, for some unknown brilliant reason, overrides the user's setting for the usmask. So that would have to change.
There are closed source apps in the gentoo repo, like Steam and Discord. When I run them, they have access to everything I do. So they are not sandboxed. I don't like that because a lot of companies are very liberal at how they use you data. At the moment I install these apps via flatpak, since that is the only way I can get them in a sandbox. |
|
Back to top |
|
 |
szatox Advocate

Joined: 27 Aug 2013 Posts: 3527
|
Posted: Fri Feb 28, 2025 12:58 am Post subject: |
|
|
Quote: | if I have access to the GPU and the soundcard, and the app has access to the network and the soundcard, then suid would drop my access to the GPU and give me access to the network. So I would end up with access to the network and the soundcard, just like the app.
That is not what I want. I want to lose access to the GPU, without gaining access to the network. | Create a dedicated account for your application, and grant it access to soundcard but not to GPU, and then launch your application as that user, and also create a firewall rule rejecting outgoing traffic that matches application's dedicated user ID (there actually is an iptables extension for that).
And if you want this application to always start on this dedicated account, regardless of who launches it, chown and suid the executable binary so you don't have to remember about sudo every time.
Also, I think you're mixing account privileges with access restrictions on files (ACL).
You can grant more privileges to user account by adding it to multiple groups, but there is no easy way to remove already granted privileges.
You can also allow access to a file by multiple users/groups by creating multiple ACLs, but you can't easily require a user to be in multiple groups to access a single file.
Networking is not really affected by ACL at all, since being unable to configure network doesnt prevent you from talking over network already configured by someone else. (But iptables can fix it if you care)
Or maybe just use actual sandbox, or following pingtoo: namespaces/containers/vms, since they have much more clearly defined boundaries which makes them easier to isolate (but also consuming more resources and effort setting things up - pick your poison) _________________ Make Computing Fun Again |
|
Back to top |
|
 |
pietinger Moderator

Joined: 17 Oct 2006 Posts: 5444 Location: Bavaria
|
Posted: Fri Feb 28, 2025 1:08 am Post subject: |
|
|
minkanjin wrote: | From what I've heard, AppArmor was invented [...]
I think the best option is probably some combination of bubblewrap/firejail/apparmor. [...] |
If you only want to run one program (or a few) in a “sandbox”, I recommend AppArmor ... which in my opinion is even better than bubblewrap or firejail. I use it myself because in my opinion it is better suited for a desktop system than SELinux (which I would recommend for a server). I don't allow all “dangerous” programs (such as Webbrower or VLC) to do everything they want. My two browsers (falkon and konqueror) can't access my whole /home - only in ~/Downloads (+ of course their own config files). They can neither read nor write (or create links). Yes, this means that if I want to upload a file to the Internet, I have to copy the file to ~/Downloads first. I am happy to accept this effort if I know that all the files in my /home cannot be read. With the VLC I do it the other way round: It can read everything ... but have no access to the Internet. Yes, there have already been (several) nasty security bugs in VLC ... all you need is a manipulated video file that you watch.
Yes, you have to find out what a program needs when using AA ... and allow it to do so ... but not everything. Just because a “gwenview” (image viewer) has the ability to operate on the Internet does not mean I have to allow it to do so. Yes, there is a log entry that gwenview tried to establish an Internet connection (and failed) ... and ? ... I don't care - programs that access my data are not allowed on the Internet (but of course kmail is allowed to access the internet and my mail files).
How to proceed: AA (as well as SELinux) has an option to log all access WITHOUT prohibiting it. You look at it and then decide what to allow and what not. (Oh yes, the user must of course have the same authorization; the kernel checks BOTH: AA allows it + the user authorizations allow it).
Yes, it can be quite extensive what you have to allow ... if you want to monitor several programs with AA, it is worth working with hierarchical profiles; e.g. a basic profile that can be allowed for all programs, profiles that can be added as required (USESOUND) and then the program-specific profile. If you are looking for examples, you will find something here:
https://forums.gentoo.org/viewtopic-t-1124308.html
https://forums.gentoo.org/viewtopic-t-1124470.html
(Don't pay attention to the language; just look at the examples). _________________ https://wiki.gentoo.org/wiki/User:Pietinger |
|
Back to top |
|
 |
|