Add more edge cases
Don't map users when running as root
Add more explanation to the readme
This utility uses the userns feature of the kernel in combination with overlayfs to run commands in a temporary container with your current filesystem as the starting contents. After running the commands in this container you get the choice to apply or throw away the changes made.
An example session showing the contents of the starting directory. Removing the codebase stored in this directory
and adding a new file. After exiting the shell spawned by transact the changes are shown and in this example
ignored.
~/P/P/transact ❯❯❯ ls
transact transact.egg-info README.md setup.py
~/P/P/transact ❯❯❯ transact
(transact) ~/P/P/transact # ❯❯❯ ls
transact transact.egg-info README.md setup.py
(transact) ~/P/P/transact # ❯❯❯ rm -rf transact
(transact) ~/P/P/transact # ❯❯❯ touch example
(transact) ~/P/P/transact # ❯❯❯ ls
transact.egg-info README.md example setup.py
(transact) ~/P/P/transact # ❯❯❯ exit
M /home/martijn/.zhistory
D /home/martijn/Projects/Python/transact/transact
A /home/martijn/Projects/Python/transact/example
Do you want to commit these changes? [y/N] n
~/P/P/transact ❯❯❯ ls
transact transact.egg-info README.md setup.py
This project is inspired by https://github.com/binpash/try
The major differences are that this is written in Python and this allocates a PTY for the shell. This also launches a shell instead of running only one command.
I used the way try works as my starting point, the steps this tool goes through are roughly:
unshare to create a sandbox namespace that isolates the mounts, uid/gid and pids from the main systemunshare that contrains the system to this fake rootfsNow you're in a fake shell with root permissions that looks like your normal system but any modifications
to the filesystem are written to the upper layer of the overlayfs instead. After exiting the shell
both the unshare instances will be torn down and the contents of the scratch space is analyzed.
The diff is generated by comparing the files from the upper directory with the actual root filesystem with the option to commit those changes.
Just like try this is far from a security sandbox. Don't use this to run untrusted binaries. Only mountpoints
and basic filesystem sandboxing is done here and it assumes whatever is run inside the sandbox isn't actively
trying to break the sandbox. Some of examples of the holes are:
Beside the security considerations there's also more limitations to this sandbox:
(transact) to the prompt. This is not supported on any other shell at the moment