jailbash 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #!/usr/bin/env bash
  2. # Use bubblewrap to run /bin/bash reusing the host OS binaries (/usr), but with
  3. # separate /tmp, /home, /var, /run, and /etc. For /etc we just inherit the
  4. # host's resolv.conf, and set up "stub" passwd/group files.
  5. set -euo pipefail
  6. (exec -a jailbash bwrap --ro-bind /usr /usr \
  7. --ro-bind /lib /lib \
  8. --ro-bind-try /lib64 /lib64 \
  9. --tmpfs /usr/lib/modules \
  10. --tmpfs /usr/lib/systemd \
  11. --tmpfs /usr/local/hestia \
  12. --tmpfs /usr/share \
  13. --ro-bind /bin /bin \
  14. --ro-bind /sbin /sbin \
  15. --dir /var \
  16. --dir /tmp \
  17. --symlink ../tmp var/tmp \
  18. --proc /proc \
  19. --dev /dev \
  20. --bind ${HOME} ${HOME} \
  21. --ro-bind-try /etc/profile /etc/profile \
  22. --ro-bind-try /etc/alternatives /etc/alternatives \
  23. --ro-bind-try /etc/localtime /etc/localtime \
  24. --ro-bind-try /etc/ld.so.cache /etc/ld.so.cache \
  25. --ro-bind-try /etc/resolv.conf /etc/resolv.conf \
  26. --ro-bind-try /etc/hosts /etc/hosts \
  27. --ro-bind-try /etc/nsswitch.conf /etc/nsswitch.conf \
  28. --ro-bind-try /etc/ssl /etc/ssl \
  29. --ro-bind-try /etc/pki /etc/pki \
  30. --ro-bind-try /etc/manpath.config /etc/manpath.config \
  31. --bind-try /run/mysqld/mysqld.sock /run/mysqld/mysqld.sock \
  32. --chdir ${HOME} \
  33. --unshare-all \
  34. --share-net \
  35. --die-with-parent \
  36. --dir /run/user/$(id -u) \
  37. --setenv XDG_RUNTIME_DIR "/run/user/$(id -u)" \
  38. --setenv PS1 "$(id -nu)$ " \
  39. --file 11 /etc/passwd \
  40. --file 12 /etc/group \
  41. /bin/bash -l "$@") \
  42. 11< <(getent passwd $UID 65534) \
  43. 12< <(getent group $(id -g) 65534)