mirror of
https://github.com/netblue30/firejail.git
synced 2026-05-15 14:16:14 -06:00
[GH-ISSUE #2042] more gradual control over supplementary groups #1380
Labels
No labels
LTS merge
LTS merge
bug
bug
converted-to-discussion
doc-todo
documentation
duplicate
enhancement
file-transfer
firecfg
firejail-in-firejail
firetools
graphics
help wanted
information_old
installation
invalid
modif
moved
needinfo
networking
notabug
notourbug
old-version
overlayfs
packaging
profile-request
pull-request
question
question_old
removal
runtime-permissions
sandbox-ipc
security
stale
wiki
wiki
wontfix
wordpress
workaround
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/firejail#1380
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @dkavlakov on GitHub (Jul 16, 2018).
Original GitHub issue: https://github.com/netblue30/firejail/issues/2042
The set of global Firefox-specific settings imported in the latest palemoon.profile includes a "nogroups" line, that prevents group-based device permissions from working and leaves Palemoon without access to sound when ALSA is used. Unlike Firefox there is no forced Pulse Audio dependency in Palemoon (including the future 29 series) and it's profile should allow ALSA sound to be used.
@chiraag-nataraj commented on GitHub (Jul 16, 2018):
So I think the problem is that in the most common usecase,
nogroupsprovides some additional security. Removing it by default when it works for most people (and provides additional security) doesn't make much sense imo. At the same time, I recognize that it screws over people who are currently using ALSA (and will continue to do so). The problem is thatnogroupsdoesn't just allow ALSA to be used, right. It could enable other things which are far more nefarious. If you can document which specific groups are needed (by default, anyway), we might be able to bring in an--enable-alsaflag (and correspondingenable-alsaprofile option) so that you can get ALSA sound back without having to disablenogroups.@netblue30 commented on GitHub (Jul 17, 2018):
@dkavlakov: can you run groups in a terminal, something like this:
It could give us an idea what we need to add by default.
@dkavlakov commented on GitHub (Jul 20, 2018):
lp cdrom floppy tape audio dip video plugdev users netdev lpadmin scanner kvm sambashare wireshark vboxusers bluetooth
This is a pretty typical example of the pre-systemd-takeover Debian group permissions model.
Is it security risk? It may become in case of serious misuse of the filesystem group permissions. Is it less secure than your current settings? No! Right now to have sound in Palemoon and Chromium one is supposed to install huge amount of bloatware that includes even an additional, self-sufficient privilege elevation system, managed by huge set of policies, written by multiple third parties . Getting rid of this realy does provide additional security.
[edit] Ok, looking at the "sudo" group membership in the upper example i am forced to agree that with sufficient amount of Ubuntu in the mind one can easily turn group permissions into a threat. This however also proves that having more installed packages with the word "security" in their description (like sudo in the example) does not necessary give you more security.
@chiraag-nataraj commented on GitHub (Jul 21, 2018):
@dkavlakov
I hope you realize that pulseaudio is separate from systemd, was adopted well before systemd, and is a completely separate project. The fact that Lennart was a huge force behind both is the only thing that connects the two.
That being said, yes, pulseaudio (like most programs on the "modern" desktop) is not designed with security in mind. dbus is a huge security issue. But this is nowhere near an issue unique to pulseaudio or dbus. Most programs don't sandbox themselves. Many system daemons run as root or install SUID executables. Indeed, I would posit that systemd (love it or hate it) has made some of these issues better in that it's exposed some of the same technologies that firejail uses (such as namespaces) in a way such that some distributions and projects have adopted stricter defaults than they were doing under sysvinit. Socket activation means that systemd can set up the sockets and pass them to the program (which means the program no longer needs to run as root just to set up sockets). The same is true for things like temporary directories. So even if many programs aren't taking advantage of it right now, these features mean that they can take advantage of it in the future. Further, the drop-in system ensures I can add stricter defaults to my system (as I have done with several daemons) without having to futz around with the files installed by the system (ensuring I don't need to do manual merging of changes on upgrade).
If you're going to shit on systemd and pulseaudio, at least stick to the facts. I'm neutral on systemd (I like some aspects, but dislike others) and pulseaudio, but I can't stand this mindless hatred when some of these features are objectively a good thing in that they lead to more secure defaults and fewer programs running as root. That is unquestionably a good thing.
[Edit] Also, I literally have most of the same groups in my user, and I'm running a pure systemd system:
@chiraag-nataraj commented on GitHub (Jul 25, 2018):
@netblue30 I think this is doable, but I'm not quite sure exactly how to go about adding this. I think having a
--groups=predicate on the command-line and agroupspredicate in profiles would be useful. It could retain only those groups while cleaning everything else and would provide a setting other than the binary on/off that we have right now.@chiraag-nataraj commented on GitHub (Jul 28, 2018):
--groups=noneorgroups nonecould function equivalently to the current--nogroupsandnogroupsoptions we have right now.@ghost commented on GitHub (Jan 25, 2020):
@rusty-snake Did you mean 'gradual' control?
@rusty-snake commented on GitHub (Jan 25, 2020):
sure, thk
@Leebre commented on GitHub (Mar 12, 2020):
Hi, I am a new user to firejail. I like it a lot and was going to make a suggestion related to this, but saw this existing issue. Another example from my own use is Skype - it needs access to both the audio and video groups in order to make video calls. So, it won't work correctly with the
--nogroupsoption enabled.Is it possible for a future release that the groups you want to be available in the sandbox could be specified?
--nogroupsseems a bit 'all-or-nothing'.I guess a workaround would be to create another user with more restrictive group permissions and
suto them first. But that might lead to difficulties if you need to access anything in the first user's $home directory.@jonleivent commented on GitHub (Mar 12, 2020):
@Leebre
I use the "workaround" you describe for other reasons, but I think it is very much worth the effort to do this for the extra security it brings. The "separate users from each other" security model is built into Linux and very well tested and adhered to, so, if you have the Linux know-how to use it, why abandon it just because we have sandboxing these days? Firejail sandboxing without user separation is convenient and easy to set up - and this is firejail's chief benefit over other techniques - but if you can combine multiple techniques to get additive security, go for it.
To deal with access to the first user's home dir, I have the first user be a member in each auxiliary user's group. That way I can selectively enable access, and keep track of who can access what very easily.
As for the audio (and video) issues vs. security, I would love to see firejail implement bridges for these - much the same as it has the ability to bridge network and X11.
@Leebre commented on GitHub (Mar 14, 2020):
@jonleivent thanks for your advice on this. I agree, it does make sense to use the existing Linux user/group privileges as well as firejail, so I will give that a try. Still, more granular control of group permissions within firejail might be something worth considering for future development.
@jonleivent commented on GitHub (Mar 14, 2020):
@Leebre I agree with having detailed control over group permissions. There are popular apps, for instance virtualbox, that require certain group permission, and it would be nice to drop all unnecessary group permission while whitelisting the necessary ones.
@topimiettinen commented on GitHub (Mar 18, 2020):
udevd has
uaccessrules, which are used by systemd-logind (maybe also elogind) to change ACLs of the devices (audio, video or cdrom). When a user logs in, the ACLs give access to the devices and the ACLs are removed on logout. This is safer than the older method of using special groups to give access, because once the group rights are given, the user could keep them forever by making a setgid executable. Also, a remote user could use the groups to mess remotely with locally logged in user.But the group method is still used for other purposes, so the selective groups would be nice. One (a bit theoretical) catch is that the group membership could be used to limit access (g=rx vs o=rwx), but since we allow dropping all groups it's already broken.
@yardenac commented on GitHub (Oct 20, 2020):
Agreed, granular group settings should be a no-brainer. The overlap between nogroup and noroot are confusing and unnecessary, and this would solve both problems.
@crocket commented on GitHub (Sep 11, 2021):
I had to debug ALSA sound issue for a few hours until I figured out the issue by searching issues and pull requests.
Neglecting ALSA users isn't cool.
@kmk3 commented on GitHub (Oct 26, 2021):
From:
@kmk3 on Oct 26:
@rusty-snake on Oct 26:
I think that the following would be a rather self-descriptive way to use it:
It would enable granularity both for keeping individual users (and their
respective user groups) and for keeping system groups.
Though for new whitelisting commands, I'd suggest splitting the "add to
whitelist" command from the "enforce/enable whitelist" command, so that the
former (i.e.: the
something.keepcommands) could be safely used on includeprofiles. Example commands:
The first two commands would be a noop without the later ones (so it would have
the same effect of trying to whitelist a non-existent file, for example).
This is probably a topic worth its own discussion, but since new commands are
being suggested, might as well put a remark in here.
Misc: Originally (on a WIP proposal), I thought of using "enforce" for
whitelist.enforce,seccomp.enforceand others (with the same goal of addingnew subcommands to split the functionality of each command), so I used the same
name above for consistency.
@rusty-snake commented on GitHub (Oct 26, 2021):
IMHO we talk about improving two similar but different commands:
norootsets up a new user ns with only the current user and a few supplementary groupsnogroupsremoves supplementary groups from the current userIs your proposal regarding keeping additional uids/gids in a private user ns (which I assume) or selectively keeping supplementary groups?
In all that, keep the following question in mind: What is the function of
nogroupsif you keep additional uids withnoroot? Only for the current user or for all users?@kmk3 commented on GitHub (Oct 26, 2021):
@rusty-snake commented on Oct 26:
I'm not sure I understand the question (maybe because I'm not familiar with
everything that a user ns entails), but I assume that you mean non-system
users/groups (e.g.: "rusty") vs system groups (e.g.: "audio"). I thought about
using the same command (
groups.keep) to whitelist any group in /etc/groups(so that only the whitelisted groups would exist in the sandbox).
If you mean implementation-wise, as in hiding groups from /etc/groups inside
the sandbox vs making the user not be part of any system groups inside the
sandbox (through whatever means this is currently achieved with), I hadn't
thought about the distinction. I meant mostly the former, but I think both
could be done at once for the same command. Would that make it too
complicated?
In my mind, this is what each command is (primarily) supposed to do (from
having previously looked at some of the code and the man pages):
noroot: Hide all other non-system users/groups (including root) -> hideother dirs in /home (and hide /root) and hide other non-system UIDs and GIDs.
nogroups: Hide all (non-whitelisted / non-hardcoded) system groups.I know that it's probably not exactly how they work, but assuming that the
above was the case, I guess that they would be the equivalent of
users.enforceandgroups.enforcefrom my previous comment. So they wouldstill do the above, but without dropping the users in
users.keepand thegroups in
groups.keep.Misc: Now I see that one might want to keep certain groups for user1, but not
for user2. I hadn't thought about this scenario, just about dropping groups
for all users in the sandbox (so it would be "system-wide" inside the sandbox).
Maybe we could also have something like git does for subkeys (e.g.:
branch.<name>.remote):Though this is more unwieldy, so it's probably better to leave this part for
later.
@crocket commented on GitHub (Oct 27, 2021):
I think
norootshould not touch groups for simplicity. Ifnoroottouches groups, we lose separation of concern, and it becomes more difficult to reason about profiles.nogroupsshould touch groups, ornogroupsshould account fornoroot.@JCallicoat commented on GitHub (Jan 7, 2022):
I just spent a while going down rabbit holes trying to figure out why webrender was broken in firefox. It ended up being that /dev/nvidia* files were owned by the
vglusersgroup (gid 1000 on my system) because of using virtualgl. The virtualgl server creates udev rules to set that group on the devices.Since vglusers is not in the supplementary groups that are kept with
noroot, the /dev/nvidia* files were getting thenobodygroup and firefox couldn't access them. When I changed the group ownership of the files torenderorvideo(or setignore noroot) then everything worked.It would nice to be able to control what additional groups
norootwill keep for cases like this. It looks like there was some discussion about it that at https://github.com/netblue30/firejail/issues/4603 but I guess it was decided against?@kmk3 commented on GitHub (Jan 7, 2022):
@JCallicoat commented on Jan 7:
Interesting, I never heard of this group.
On what distro/version?
I did not find such udev rules on Artix:
Where are they defined? Can you post them here?
We could treat the "vglusers" group the same as the "render" group: Keep by
default and only drop when
no3dis used.Given the current implementation, adding more hardcoded groups is the easiest
way to fix group-related issues (see #4725/#4732).
But if it does not work well enough, maybe
groups.keepcould be addedeventually.
Do you know of any other group that firejail misses?
Or of any other tools that override the default groups for device files?
@JCallicoat commented on GitHub (Jan 7, 2022):
I suspect it's may be somewhat niche for people to be using virtualgl. I mainly use it for passing through to a real X server from a nested server like Xypher / Xpra or from containers with X socket passed through.
I don't use it much anymore and forgot about the group ownership and udev rules and different configs it generates. The setup script actually does a whole bunch of stuff
6f0b90be02/server/vglserver_config (L393).I honestly don't know how big the virtualgl user base is to say if it's worthwhile to special case it, I just thought it would be another data point when considering the
groups.keepidea.I couldn't think of any offhand but looking in /dev on this box I do see /dev/vboxusb owner by
root:vboxusers.@kmk3 commented on GitHub (Jan 9, 2022):
@JCallicoat commented on Jan 7:
vglserver_config
Well, that's quite the party going on in /dev.
Is this done only on the guest? Does it do that on the host with xephyr/xpra?
Do you have to reboot to restore the original group ownership?
I see, that makes sense.
Not sure if/when
groups.keepwould be implemented though, so treating"vglusers" the same as the "render" group could be a workaround until then,
especially if both target the same devices.
Do you know if the group is ever applied to anything other than render devices?
That's one good argument for
groups.keep, as it's an application-specificgroup and that device indeed should probably only be accessible by virtualbox.
@JCallicoat commented on GitHub (Jan 11, 2022):
I know right haha? It's done on the host X server which renders the GL there for the "remote" client by launching programs with vglrun inside the client. The config script also has an uninstall option but it sets the ownership on all the device files to root:root instead of root:video for /dev/nvidia* and root:render for /dev/dri/* heh. If I were to remove it I would manually reset the ownership and remove the files it drops in /etc and reboot.
I totally forgot about it changing the groups. and reading your comment here https://github.com/netblue30/firejail/issues/3644#issuecomment-988523518 when I was trying to figure out why webrender was throwing errors in firefox made me remember.
That would definitely work for my use case. These are the files with the groups changed by the virtualgl config script and the udev rules it creates:
@kmk3 commented on GitHub (Jan 12, 2022):
@JCallicoat commented on Jan 11:
I see; thanks for the details.
Glad it helped!
Rambling
Good to know. Default ownership on Artix (with AMD):
So as you said, the default ownership for nvidia devices on your system is
"root:video", which also seems to be the default on Gentoo:
@hlein commented on Oct 2, 2020:
This seems to be set by udev. From /usr/lib/udev/rules.d/50-udev-default.rules
(udev 250-2 on Artix):
I'm not sure if this means that these nvidia devices allow both rendering and
video capture. In which case maybe "vglusers" should only be kept only if
there is neither
no3dnornovideo.But it may also just be a workaround required by the nvidia drivers. And on
firejail they are treated as
DEV_3Ddevices (which are controlled byno3dand are usually owned by the "render" group):
https://github.com/netblue30/firejail/blob/121749f0ca167eb3705ed2d5170ec6bd308c3ea5/src/firejail/fs_dev.c#L53
Conclusion
So considering the way firejail currently deals with these devices, I think it
would make sense to just treat "vglusers" the same as the "render" group
indeed. Though let me know if I missed anything.
Anyway, I'll open a PR later.
@crocket commented on GitHub (Mar 10, 2022):
https://git.sr.ht/~kennylevinsen/pam_uaccess substitutes for logind's uaccess functionality.
@jonleivent commented on GitHub (Jun 24, 2022):
Is any progress being made on this topic (the "more gradual control over supplementary groups" part)?
I would really like to be able to use
norootmore often, and then also selectively restrict supplementary groups.@kmk3 commented on GitHub (Jun 25, 2022):
@jonleivent commented on Jun 24:
What is the issue specifically?
I have some been working on some group-related fixes that I intend to submit
after the ongoing build improvements, which may or may not relate to your
issue.
I haven't worked on this, but I would also like to see something like
groups.keepeventually.@jonleivent commented on GitHub (Jun 25, 2022):
@kmk3:
Are you asking why I would want to use
norootmore often? I thought it was generally understood thatnorootcontainers are safer. I guess my whole premise is mistaken ifnorootcontainers are not safer.A specific instance: I discovered that KVM can be run in a
norootfirejail provided one chmods or chowns the/dev/kvmsocket so that the KVM user does not need to be in the kvm group to use it. Then anorootandnogroupsfirejail can be wrapped around KVM and it works. However, it shouldn't be necessary to alter the external-to-firejail environment of KVM by chmoding/dev/kvm(which also needs to be redone at startup every time) just to get the safest firejail environment for KVM.KVM is an instance of an app that uses groups in a very normal linux way: to enable sysadms to provide permission on a user-by-user basis through groups. It would be nice if firejail accommodated this usage in an expandable way, in other words, not by building into firejail support only for particular predefined groups.
Suppose, for instance, firejail had a
noroot-with-group-fileoption that took a file parameter in the format of/etc/group, checked that its contents are a permissible subset of the existing/etc/group(no new membership is added: only users are removed from groups and/or whole groups are removed), and used it within the container (along with removing the root user).@rusty-snake commented on GitHub (Jun 25, 2022):
OT: udev-rules
norootshould not mess with groups at all IMHO.@jonleivent commented on GitHub (Jun 25, 2022):
@rusty-snake
True enough. The point being that it takes a modification to something (be that /etc/rc.local, or /usr/lib/udev/rules.d) that modifies the environment external to firejail to accomplish the task of giving KVM a safer environment within firejail.
I agree. But it currently does. If you want backward-compatibility, it might be best to add a new option, keeping
norootwith its current, albeit mistaken, functionality. Because if you modifynorootto not alter groups at all, then even if you simultaneously modify all profiles to reflect that, some people who have their own profiles that usenorootwill experience a lowering of protections possibly without realizing it.@kmk3
I'd be OK with that instead of
noroot-with-group-file. It's probably easier to accomplish, less prone to error, and easier to use within the provided /etc/firejail profiles framework. It has less functionality thannoroot-with-group-file, as the latter can drop users from groups without dropping those groups. But maybe that added functionality isn't worth it.@kmk3 commented on GitHub (Jun 27, 2022):
@jonleivent commented on Jun 25:
Sorry, I meant what was the specific issue that
norootwas causing.I see, so the problem is that
norootcauses the kvm group to be dropped,which results in permission issues.
That indeed seems like a reasonable use use of groups and I agree that it
should be supported.
@rusty-snake commented on Jun 25:
@jonleivent commented on Jun 25:
The reason that
norootdrops groups is that it sets up a user namespace wherethe root user/group do not exist (see "User and group ID mappings" in
user_namespaces(7)). Whereasnogroupsjust usessetgroups(2)to dropgroups.
The last time I looked into this IIRC, the code seemed a bit tricky and
dropping all groups with
norootis likely the least annoying way to do it,considering how it's currently written and the format of
gid_map. Butnorootdoesn't really have to drop all (non-whitelisted) groups and I thinkthat it could be made to drop only the root user/group.
Misc: I now noticed that
gid_maphas a limit of 340 lines (seeuser_namespaces(7)), which would likely mean up to 340 groups in a simpleimplementation; not sure if this would ever be a problem. Unless maybe if
running in an Android-style system, where each program has its own user/group.
IIRC one way to do it would be to refactor
noroot/nogroupsto use thesame mechanism(s) to drop groups and then split the processing of
norootfromnogroups. That is, first drop the root user/group (ifnorootis enabled),then do another pass to deal with the other groups.
Anyway, this would be the result:
noroot: drops root user/groupnogroups: keeps whitelisted groups, keeps/drops supplementary groups basedon the relevant options (such as
nosound-> drops audio group), drops allother groups
Misc: If
norootis changed as per above, I think justgroup-file filewouldbe a more appropriate name.
That command does seem more powerful, but I don't understand what would be the
use case, so I'm not sure if it would warrant the extra complexity. That is,
inside of the sandbox, why/when would it matter in which supplementary groups
other users are?
On a side note, if
group.keepaccumulates, the following should be possible:@rusty-snake commented on GitHub (Jun 27, 2022):
And ... ?
You can unshare the userns w/o dropping unmapped groups.