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

Add fakeroot - combined mount and chroot to create a docker-like view on the filesystem #36

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

MarkusBauer
Copy link

@MarkusBauer MarkusBauer commented Mar 1, 2025

While this project already has support for chroot and pivot_root, these features are hardly useful if you want to start anything else than a static linked binary. Thus I added a more powerful feature: fakeroots.

A fakeroot is an initially empty root, where directories from the host can be selectively shared. Shares can be read-only if necessary, providing additional isolation. For example, this code allows read-only access to installed programs but not user data and no write access at all:

cmd.fakeroot_enable("/dev/shm/sandbox_root");
cmd.fakeroot_mount("/bin", "/bin", true);
cmd.fakeroot_mount("/etc", "/etc", true);
cmd.fakeroot_mount("/lib", "/lib", true);
cmd.fakeroot_mount("/lib64", "/lib64", true);
cmd.fakeroot_filesystem("proc", "/proc");
cmd.fakeroot_filesystem("tmpfs", "/tmp");
cmd.fakeroot_mount("/usr", "/usr", true);

The implementation is mostly inspired by nsjail which uses the same syscall sequence.
The featureset is very basic - only host directories can be shared (read-only or readwrite), and a /proc and /tmp are available on demand. Follow-up features could include sharing files/devices or mounting to subdirectories.


Availability: If anyone wants to use this and other features before it's merged, check out my temporary fork. It includes #23 #27 #29 #33 #34 #35 and #36 with all conflicts resolved.
Add to your Cargo.toml: unshare = { git = "https://github.com/MarkusBauer/unshare.git" }

Markus Bauer added 2 commits March 1, 2025 14:57
(cherry picked from commit 07b42cf)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant