-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Rootless containers without uid mapping to root #1800
Comments
At the moment this is not supported, though this is something that I agree would be useful. I haven't yet taken a look at how much work it would take (and whether LXC does anything special in this case which we would have to replicate). I can talk to @brauner out-of-band and see how he solved the "you need root in the namespace in order to set up the container" problem (maybe it was done using capabilities -- I'm not sure). |
Thanks a lot for the reply @cyphar! |
This would also be useful to me. I'd like to move some existing processes into (rootless) containers, and would like for them to think they run as the same unprivileged user as before. I'll experiment a bit, but this will likely take me out of my depth and I may need some guidance. Do we already have a general idea of how to get this to work? |
Basically the core idea is that you need to just change the current restrictions and see what breaks. Likely the main breakages will be that Aside from that most of it ought to mostly work (there isn't anything particularly special about mapping |
I think I have something minimally functional, but one snag I've hit is that the RHEL 7.5 kernel 3.10 doesn't allow unprivileged devpts mounts (it returns EINVAL on mount). A likely relevant conversation is apptainer/singularity#1186. As a workaround, I currently have to set |
As far as I am aware, this is something that we should have already fixed a long time ago by dropping But the discussion you linked appears to argue that there is a kernel-side check for |
Yeah, saw some of the commits related to that. My config does not have a
After re-reading that thread and peeking at the kernel source, I don't think this is RHEL-specific, it's just that the 3.10 kernel it comes with is fairly old and requires that uid=0 and gid=0 be valid in the user namespace. See the relevant 3.10 source at Is it possible for an unprivileged user to map host root to container root in the user namespace? I'm guessing not, for security reasons? |
No, that's not possible (as an unprivileged user) because inside a user namespace you can change to any user (if you created the user namespace). As an unprivileged user, you can only map yourself into either |
Right, yeah, thats what I thought. We may just have to accept that devpts wont work with nonzero uid/gid in older kernels. We can output a hint message in the logs when the devpts mount returns EINVAL and uid/gid are nonzero. I'll put together a PR at some point. |
Hi, almost created a new issue for the same thing, luckily found this one. I think the basic solution is trivial and would cover lot's of use-cases (I will link soon the way I solved it for me). It involves three (the fourths is already present) additional steps (semi-pseudo-code):
1000 is the original user's id, that was mapped in the previous step to 0. I think if that would make it into the runc with additional flag, would be great. |
Just another note: probably bunch of exploits could have been and could be avoided (like https://seclists.org/oss-sec/2019/q1/119), if better tooling would be provided for unprivileged containers without reinventing the wheel... And related more about the technical solution I proposed in my previous post:
|
Found the solution. In order to implement it one needs an additional step (sub-command) like "init", let's call in "unsremap"
Am happy to provide a patch if this description is accepted |
I'm not sure it's necessary to have a separate re-exec stage, you should just be able to add an extra Also changes to the configuration format of |
In nsexec may be too early as you cannot do any mounting and other init as non root, which I believe you are doing in the init subcommand.
My containers do not work for the opposite reason: some executable are assuming that they are not uid 0. |
You cannot configure namespaces unless you own them (more specifically, have the correct capabilities in the user namespace which owns the namespace you're trying to configure), and since the configuration is done much later during setup you would need to do the unshare at the very end of setup which would make the logic much more complicated.
There are some ghetto solutions for this problem which I helped develop some time ago -- https://github.com/rootless-containers/subuidless is the latest iteration of this idea. |
Not sure if you understood my initial proposal. The idea is that with some magic configuration, once everything is configured by runc (namespaces, mounts etc), instead of calling the process.args from config.json you would call
the unsremap subcommand
|
Hello,
would it be possible to use
runc
to create a rootless container with the following characteristics:In other words, I would like to know if the use case described here for LXC is supported by
runc
as well.I tried setting up the
config.json
with the following details:However
runc run
returns the following message:User namespaces enabled, but no user mapping found.
Thanks for any help provided.
The text was updated successfully, but these errors were encountered: