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

Block access to user namespaces #368

Closed
gerout7 opened this issue Apr 20, 2020 · 2 comments
Closed

Block access to user namespaces #368

gerout7 opened this issue Apr 20, 2020 · 2 comments

Comments

@gerout7
Copy link

gerout7 commented Apr 20, 2020

When running bubblewrap on systems with unprivileged user namespaces available, currently the runtime environment inside the bwrap sandbox does not block access to user namespaces, therefore allowing the sandboxed process to spawn new user namespaces. While this is useful in some cases like chrome-sandbox, which makes use of user namespaces for its own internal sandboxing features, most application have no use for it.

Since unprivileged user namspaces have a huge attack surface, shouldn't this feature generally be blocked by a sandbox?
While there could be an option to allow the use of unprivileged user namspaces within bubblewrap, I think it would be a good idea to block this feature by default for any process inside a bubblewrap jail.

While this could be archived by the end user by adding a seccomp filter for clone, unshare and setns in combination with the flags for user namespaces, I think this should be the default in bubblewrap.

@smcv
Copy link
Collaborator

smcv commented Apr 20, 2020

unprivileged user namspaces have a huge attack surface

They do have a rather smaller attack surface inside bubblewrap, because NO_NEW_PRIVS should prevent any attack that relies on (ab)using a setuid executable.

While this could be archived by the end user by adding a seccomp filter for clone, unshare and setns in combination with the flags for user namespaces

bubblewrap isn't really designed to be used directly by end users. It provides enough namespace manipulation to be able to use namespace-based sandboxing on systems that otherwise don't allow it, like Debian 10 and RHEL/CentOS 7; it provides all the tools to make a sandbox, but doesn't directly implement any particular security model, and doesn't provide much in the way of convenience code to make things easier.

For user-friendly sandboxing with a ready-made security model, you'd be better off with Flatpak (which uses bubblewrap, and does use seccomp to prevent apps from entering further user namespaces) or something else that builds sandboxing around bubblewrap.

Because bubblewrap is setuid root on some systems, the bwrap executable needs to distrust its caller on those systems, and adding convenience code to it would expand bubblewrap's attack surface - for example, that's why it takes a precompiled seccomp eBPF program as an argument, rather than using libseccomp to compile user-specified rules or having shortcuts for commonly-used seccomp filters.

@smcv
Copy link
Collaborator

smcv commented May 4, 2023

When running bubblewrap on systems with unprivileged user namespaces available, currently the runtime environment inside the bwrap sandbox does not block access to user namespaces, therefore allowing the sandboxed process to spawn new user namespaces.

#488 added a --disable-userns option to prevent access to user namespaces (without being syntactic sugar for seccomp - it sets limits instead). It also added an --assert-userns-disabled option, which tries to create a nested user namespace, and asserts that it can't - this can be used to ensure that a pre-existing user-specified userns passed to --userns or --userns2 was created with --disable-userns or similar.

While there could be an option to allow the use of unprivileged user namspaces within bubblewrap, I think it would be a good idea to block this feature by default for any process inside a bubblewrap jail.

That would be an incompatible change that breaks existing users of bubblewrap. As a concrete example, NixOS uses bubblewrap to enter a FHS-like environment for compatibility with third-party binaries like Steam, and relies on the ability to run bubblewrap (again) inside that environment, to implement the Steam container runtime. Making --disable-userns the default would break that overall system.

We take backwards-compatibility seriously, so disabling user namespace creation will not become the default. However, if we add a way to opt-in to groups of changes to defaults (#455), then it could become the default after opting in to compat level >= 1, or similar.

@smcv smcv closed this as completed May 4, 2023
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

No branches or pull requests

3 participants
@smcv @gerout7 and others