Because why not?
Namespaces are, among other things, a sandboxing mechanism. They allow modifying certain settings inside an isolated domain without worrying whether they will affect the rest of the system.
Take mount namespaces as an example. Mounting file systems is normally a privileged operation: if you can mount arbitrary file systems, you can in particular mount a file system containing a set-user-id executable of your choosing and then execute it, thus performing a privilege escalation attack. However, launching a set-user-id executable inside a user namespace can only increase its privileges within that namespace: the root user ID inside the user namespace will be mapped to regular user ID outside the namespace, and process capabilities similarly apply only to resources subordinate to that namespace.
Without user namespaces, creating other kinds of namespaces might be exploited for privilege escalation in a similar way. But when ‘privilege’ is constrained to the user namespace, there is no reason any more not to allow it – and there are, in fact, some use cases for this. User namespaces don’t just constrain privileges, but also create the possibility of defining a privileged-unprivileged boundary within the namespace, preventing rogue processes from both escaping the sandbox entirely and taking over the sandbox itself.
The LWN article Namespaces in operation, part 6: more on user namespaces lists a number of possible applications for unprivileged creation of namespaces:
By isolating the effect of capabilities to namespaces, user namespaces thus deliver on the promise of safely allowing unprivileged users access to functionality that was formerly limited to the root user. This in turn creates interesting possibilities for new kinds of user-space applications. For example, it now becomes possible for unprivileged users to run Linux containers without root privileges, to construct Chrome-style sandboxes without the use of set-user-ID-root helpers, to implement fakeroot-type applications without employing dynamic-linking tricks, and to implement chroot()
-based applications for process isolation. Barring kernel bugs, applications that employ user namespaces to access privileged kernel functionality are more secure than traditional applications based on set-user-ID-root: with a user-namespace-based approach, even if an applications is compromised, it does not have any privileges that can be used to do damage in the wider system.
That said, adding support for user namespaces has in itself introduced a number of security vulnerabilities to Linux (just one example), to the point where some distributions disable unprivileged creation of user namespaces by default.
If you’re looking for resources, the rest of the LWN series on namespaces covers the topic in quite a bit more depth.
unshare -Un
. If I simply type that I get an error messageunshare: unshare failed: Operation not permitted
. So what am I missing. Edit the question to make it clearer.ls /proc/self/ns
. On mine, I have a file calleduser
.user
, in there. The namespaces are enabled in the kernel (I am running docker). Howeverunshare -Un
just fives me the error as stated above. Are you expecting it to be run as root (sudo)?sysctl kernel.unprivileged_userns_clone=1
. See lwn.net/Articles/673597