bwrap-userns-restrict 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # This profile allows almost everything and only exists to allow bwrap
  2. # to work on a system with user namespace restrictions being enforced.
  3. # bwrap is allowed access to user namespaces and capabilities within
  4. # the user namespace, but its children do not have capabilities,
  5. # blocking bwrap from being able to be used to arbitrarily by-pass the
  6. # user namespace restrictions.
  7. # Note: the bwrap child is stacked against the bwrap profile due to
  8. # bwraps use of no-new-privs.
  9. abi <abi/4.0>,
  10. include <tunables/global>
  11. profile bwrap /usr/bin/bwrap flags=(attach_disconnected,mediate_deleted) {
  12. allow capability,
  13. # not allow all, to allow for pix stack on systems that don't support
  14. # rule priority.
  15. #
  16. # sadly we have to allow 'm' every where to allow children to work under
  17. # profile stacking atm.
  18. allow file rwlkm /{**,},
  19. allow network,
  20. allow unix,
  21. allow ptrace,
  22. allow signal,
  23. allow mqueue,
  24. allow io_uring,
  25. allow userns,
  26. allow mount,
  27. allow umount,
  28. allow pivot_root,
  29. allow dbus,
  30. # stacked like this due to no-new-privs restriction
  31. # this will stack a target profile against bwrap and unpriv_bwrap
  32. # Ideally
  33. # - there would be a transition at userns creation first. This would allow
  34. # for the bwrap profile to be tighter, and looser within the user
  35. # ns. bwrap will still have to fairly loose until a transition at
  36. # namespacing in general (not just user ns) is available.
  37. # - there would be an independent second target as fallback
  38. # This would allow for select target profiles to be used, and not
  39. # necessarily stack the unpriv_bwrap in cases where this is desired
  40. #
  41. # the ix works here because stack will apply to ix fallback
  42. # Ideally we would sanitize the environment across a privilege boundry
  43. # (leaving bwarp into application) but flatpak etc use environment glibc
  44. # sanitized environment variables as part of the sandbox setup.
  45. allow pix /** -> &bwrap//&unpriv_bwrap,
  46. # the local include should not be used without understanding the userns
  47. # restriction.
  48. # Site-specific additions and overrides. See local/README for details.
  49. include if exists <local/bwrap-userns-restrict>
  50. }
  51. # The unpriv_bwrap profile is used to strip capabilities within the userns
  52. profile unpriv_bwrap flags=(attach_disconnected,mediate_deleted) {
  53. # not allow all, to allow for pix stack
  54. allow file rwlkm /{**,},
  55. allow network,
  56. allow unix,
  57. allow ptrace,
  58. allow signal,
  59. allow mqueue,
  60. allow io_uring,
  61. allow userns,
  62. allow mount,
  63. allow umount,
  64. allow pivot_root,
  65. allow dbus,
  66. # bwrap profile does stacking against itself this will keep the target
  67. # profile from having elevated privileges in the container.
  68. # If done recursively the stack will remove any duplicate
  69. allow pix /** -> &unpriv_bwrap,
  70. audit deny capability,
  71. # the local include should not be used without understanding the userns
  72. # restriction.
  73. # Site-specific additions and overrides. See local/README for details.
  74. include if exists <local/unpriv_bwrap>
  75. }