hako = chroot + Linux namespace.
It is created out of a need for a simple tool like chroot but with extra isolation.
- It generally works like
chrootwith the added benefit of isolation using Linux namespace. - It can run on a read-only filesystem.
- Some rudimentary form of privilege dropping through setuid, setgid and
PR_SET_NO_NEW_PRIVS.
- Networking: use docker/runc instead or setup something with iproute2 and veth.
With the
--networkswitch, a sandbox can use the host's or another sandbox's network. Alternatively, Unix socket works for sandboxes in the same host too. - Seccomp: I might start a new project for this if needed.
Something like
seccomp-exec <rule-file> <command> [args]would be nice.
- A C99 compiler (gcc/clang)
- Recent Linux headers
- make
mkdir sandbox
mkdir sandbox/.hako
touch sandbox/.hako/init
chmod +x sandbox/.hako/init
mkdir sandbox/bin
touch sandbox/bin/busybox
ln -s busybox sandbox/bin/shContent of .hako/init:
#!/bin/sh -e
mount -o ro,bind $(which busybox) ./bin/busyboxRun it with:
hako-run sandbox /bin/shGeneral syntax is: hako-run [options] <target> [command] [args].
If command is not given, it will default to /bin/sh.
The file .hako/init must be present and will be executed to initialize the sandbox.
It can do things like bind mounting files from the host into the sandbox.
Run hako-run --help for more info.
Given:
hako-run --pid-file sandbox.pid sandboxOne can enter the sandbox with:
hako-enter --fork $(cat sandbox.pid) /bin/shGeneral syntax is: hako-enter [options] <pid> [command] [args].
If command is not given, it will default to /bin/sh.
Run hako-enter --help for more info.
Docker does too many things. It also requires a daemon running. While it's possible to use it without building image, it's just annoying in general.
runc looks good but I only need something a little more than chroot that runs only on Linux.
I rather like the idea of simple Unix tools and Bernstein chaining.
If I need features like seccomp, I'd probably write a separate chain wrapper for it.
- It requires glibc, according to buildroot.
hakocan be built with musl. - While I'm sure it can be used standalone, it comes with a bunch of dependencies from the systemd project.
- It's systemd (jk).
pivot_root requires it.
It also provides access to the old root filesystem while creating the sandbox.
runc relies on an undocumented trick but I'd rather not.
CC='musl-gcc -static' make
Put this in .hako/init: mount -t tmpfs tmpfs ./tmpfs.
Put this in .hako/init: mount -t tmpfs -o ro tmpfs .hako.
Use environment variable (e.g: SOME_INIT_ARGS="some-args" hako-enter sandbox).
hako-run --network sandbox
hako-run --network=/proc/$(cat other-sandbox.pid)/net/ns sandbox