r/linuxquestions • u/RadianceTower • 9d ago
How to properly isolate linux users?
So I am using different Linux users as a way of sandboxing, common things to look out for, include disabling su and sudo for those users which I do.
But even so, I find there are ways to run privileged via for example pkexec, or even just flatpak install commands (I think? Even global installations of flatpak never prompted me for additional root password), and I am not sure what to do about them.
Having a long secure root password and making sure it's never entered when using that user helps, with the first one, but it's a pain, as I don't like having to type long stuff each time I run sudo otherwise. And it wouldn't help with the second flatpak issue for example.
Then, I run them on separate KDE sessions (switch user or logout), but I am not sure how much the X11 server for example would be shared still (especially on switch user).
7
u/Regrave 9d ago
pkexec and flatpak both go through polkit, and polkit treats anyone in the wheel or sudo group as an admin. flatpak even ships a rule that lets that group install system wide with no password. so instead of blocking sudo for those users take them out of wheel/sudo completely, then all of it asks for your main account's password
8
u/muffinstatewide32 9d ago
Firstly. Stop treating them like they belong in a windows network. Nailing everything down is silly in a unix like environment.
Learn linux’s security tools.
Pkexec (polkit), sudo, su, run0, doas all require someone to be in the wheel or sudo groups, with the exception of the su binary.
Removing them from both of those groups does most of what it seems you are trying to do.
In terms of user isolation. Cgroups and systemd’s slices do this by default but this isnt what you mean.
If you have to restrict binaries. Do it with acls
If you are restricting shared files, use root or nobody as a user and set the appropriate group. Set the sgid on the folder. Use acls and default acls to make inherited permissions (you only need the default on the top folder or where a permission change happens on a branching folder)
Also look at configuring sudo
5
u/sudo_bryan 9d ago
Honestly, I wouldn't rely on separate Linux users as a sandbox if you're running anything you don't trust. That's really not what Unix permissions were designed for.
Disabling sudo and su is a start, but polkit is another thing to look at. Both pkexec and Flatpak system installs can go through polkit, so I'd check what rules are actually allowing those actions. If something is getting elevated without a password, figure out why before assuming it's a security hole.
Also, separate KDE sessions don't necessarily give you the isolation you're looking for. X11 is especially problematic because clients sharing the same display can potentially snoop on input or interact with other windows. Wayland improves that, but it still isn't a full security boundary.
If you're trying to run genuinely untrusted software, I'd go with a VM. If that's overkill, look into bubblewrap, namespaces, seccomp, and AppArmor. Those actually give you more control over what a process can access.
Biggest thing is figuring out what you're trying to protect against. Keeping two users' files separate is one thing. Running potentially malicious code safely is a completely different problem.
2
u/sidusnare Senior Systems Engineer 8d ago
When you switch users, the desktops are completely isolated.
What exactly are you isolating? If it's adversarial code, you want it on an independent isolated machine. I like Raspberry Pis for this because they're easy to nuke and reimage, and they're not x86, and a lot of exploits are working on the machine code level, and Raspberry Pis are Arm, so when they exploit, say, a TCP RCE and shove an op cod in to JMP the execution pointer into the packet buffer, the op code is invalid.
Anyway, if you've got actual users or user like processes (A.I.) you're isolating, taking them out of wheel, root, and admin groups should be enough for basic isolation. It's how I deal with A.I., it has it's own user account and it's own ssh key, and it can file a PR against the repo we're working on.
4
u/TomDuhamel 9d ago
I'm really not sure what your question really is.
Flatpaks are only installed for the current user, which is why a password isn't required.
I haven't had a root password in 20 years, at least. You should never log on as root. 'sudo' uses your user password, not root's.
I hope this helps.
1
u/The_Hamster_Shagger 9d ago
a bit hardcore solution would be to mount the /home partition without the rights to run executables from it.
sadly, an unpatched kernel, doesn't allow to disable running execs from non-root directories
1
u/Jeremy_Instructor 9d ago
Separate users are a good start, but I'd check your polkit rules, switch to Wayland if possible, and use a VM for anything untrusted since separate accounts alone don't provide full isolation.
1
u/AnymooseProphet 9d ago
Shouldn't need to disable users for sudo as sudo should by default be limited to members of the admin/wheel group.
Many distros by default when creating a user will put that user in its own group (with same name/ID as the user) and not add that user to any other groups, so by default unless that user owns a file, it will not have read/write permission to anything that isn't world read/write. However that user does still have local access so if there is a code vulnerability that allows it to escalate privilege that can still happen if the user account is compromised or runs a trojan executable.
0
u/gainan 9d ago
See if replacing the default shell in /etc/password by firejail helps:
x:1001::1001::/home/x:/usr/bin/bash-firejail
in Debian at least, pkexec and other commands are included in the list of blocked binaries (/etc/firejail/disable-common.inc)