-
Notifications
You must be signed in to change notification settings - Fork 584
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
[enhancement] Allow whitelisting arbitrary directories #2041
Comments
Yes, that could be cool! |
Is there any reason we restrict which directories we can whitelist under? |
No, I just didn't know what directories are needed there, so I went for /usr/share only. We can handle the way we did for all the other directories (/dev, /etc, /media, /mnt, /opt, /srv, /var, /tmp) and remove the handling of /usr/share. The only reason is we have no idea what is |
So I guess I'm a bit unclear on why exactly there are restrictions on which directories can be used in |
Reference #2059 it shows a big problem with the whitelisting restrictions. Whitelisting the roots home directory (/root) as root user is not even possible |
@t4777sd This is working for me:
If whitelisting the entire home directory like |
My real goal is to whitelist /home/[user]. Basically, I am running software as root that I want to sandbox. The software modifies /home/[user]. Is there any way to do this? I even tried changing the $HOME environment variable to make the current roots home the same as that user and it did not work. |
I see. If Firejail doesn't read the $HOME environment variable, it instead extracts the home directory from /etc/passwd. |
Is there a way to make the writes the software does persitent? I believe that tmpfs option will make a temporary file system at /home/user and therefore no writes done to the directory will be persistent. Correct me if I am wrong |
@t4777sd Ok, now I understand what you want to do. You are right, all changes will be lost when the sandbox is closed. In the moment I don't see a solution with the current feature set. |
@chiraag-nataraj @netblue30 Did someone start working on this (whitelisting arbitrary top level directories)? Else I could give it a try, but it will take some time. |
@smitsohu Go for it by all means :) |
@smitsohu Did you ever get a chance to work on this? |
@chiraag-nataraj yes and no :) I regarded it more as a mid-term goal.... for example the fs_tmpfs() function was written with whitelisting in mind, and I think supporting arbitrary home directories everywhere in Firejail would be another significant step into this direction. But I see that progress is very slow currently, which is mainly due to time constraints. If someone wants to take this over feel free. |
There is now a new branch with rewritten whitelist code, to support arbitrary top level directories (except /proc and /sys) and whitelist globbing. Also it fixes most of the still existing whitelist related issues. In my experience it works quite well, but note that it breaks backwards compatibility: there is currently no support for mounting a tmpfs on a subdirectory, such as /sys/module or /usr/share or /run/user/$UID. This for example means that currently whitelist-usr-share-common.inc is broken as-is... as ad-hoc fix consider adding something like:
Fully restoring the previous behavior probably still requires larger changes, but for the meantime there is something at least. |
Guess it would be good to whitelist only in subdirectories in /usr, so the entrance barrier to develop sandbox configurations for /usr does not become too high. |
There was a bug when there were no whitelist commands at all (now fixed). |
One idea was to approach symbolic link creation more conservatively and then do away with current symlink restrictions (in the moment they are completely absent in the branch). There are two end goals: 1) Firejail should never create a symbolic that does not exist in the real file system, 2) Firejail should try to rebuild symlink chains completely. In practice, there is a requirement to always identify the top level directory, as we should not create symbolic links outside of a tmpfs, in the real file system. That's easy for the first symlink in a path, because the top level directory is just the top level directory. It is complicated for symlink chains, with links pointing to relative paths. The question now is if it would be ok to always replicate only the first symbolic link in a path. And leave it to the user to fix broken symlink chains (the missing components would need to be explicitly whitelisted. There could be a detailed information or a warning). Opinions? |
Just to summarize how things are handled currently: The symlink check is now run on the last path element, and resolved and unresolved path must live in the same top level directory (there are exceptions). Now that I'm writing this down, I realize the differences are actually not that a big. The current design has its limitations, too:
I want to leave the original question about the best way forward open, but for the meantime I'm thinking to
|
Where is the difference between this issue and #1130? |
Any update on this?
|
Whitelisting can not help you here, whitelisting is used to add restrictions not to remove restrictions. You need |
I thought whitelisting was to allow items explicitly set in a list -- in this case, to allow access to a certain path, right? Just to clarify, |
It allows any item on that list, that's right. But whitelist also implies no access to anything not on the list. That's why it adds restrictions by requiring an explicit allow.
AFAIK firejail don't care if /home/foo is a home-dir in /etc/passwd or not, because it is not relevant, to remove the other users-homes /home must be a tmpfs where $HOME is bind-mounted. |
Oh, OK. I think I get now.
But this doesn't.
If I'm using an actual application, like qutebrowser, that means I can't use whitelists to restrict disk access, if I want to use this shared directory. |
|
I have a VeraCrypt drive mounted under I get "Error: invalid whitelist path" if I try to whitelist that path. By the way, that message could be more helpful... initially it made me think maybe I mistyped the directory. |
Error messages are still a big part (#2743).
No, however you can use blacklisting:
|
Thanks, that worked. But blacklisting |
Correct so far. There's a second drawback: the blacklist is applied once when you start the sandbox, if you
|
Ok, there is a new experimental branch at https://github.com/smitsohu/firejail/tree/whitelist It exploits the fact that we have full access to a directory as long as we have an open file descriptor - even if other directories or temporary filesystems are mounted on top later. This has the advantage that we don't need to manage mount stash locations. All top level directories are allowed except /proc, /sys and /run. Exceptions are /sys/module and /run/user/$UID, in order to stay backwards compatible. Another special case is /usr, which is not treated as top level directory. Instead the /usr subdirectories (like /usr/share) are top level directories for the purpose of whitelisting. One significant deviation from current whitelisting is that the symlink restrictions are gone. Everything else should be the same. |
What do people think of adding the ability to whitelist files/directories within
/usr
(not just files/directories within/usr/share/
)?The text was updated successfully, but these errors were encountered: