-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Open
Description
Here is a list of things that nsexec does today, and a description of possible ideas and challenges to moving them to Go:
- Basic namespace creation can be done with
syscall.SysProcAttrtoday. There is code innsexec.cthat fixes very old kernel bugs (such as userns ownership being broken on old RHEL 6 kernels) which I'm sure Go stdlib doesn't care about (and maybe we shouldn't either). However there are some things that I suspect are not ideal:- For rootless containers, are
newuidmapfallbacks supported by Go stdlib? I suspect not. Though obviously we could write PRs to add them to stdlib... - We currently do
CLONE_NEWCGROUPfar later during setup than the other namespaces, but this is actually a vestigial implementation detail of the original cgroupns code (which incorrectly added a synchronisation step to "ensure"runc initwas in the correct cgroup). The logic probably should've been removed in 5110bd2.
- For rootless containers, are
- We might want to use
CLONE_INTO_CGROUP(SysProcAttr.CgroupFD, which should make all container nsenter-related operations faster because it avoids taking a bunch of locks in cgroup-core), but with nsexec: cloned_binary: remove bindfd logic entirely #3931 we need thememfd_create()and/proc/self/execopy to be executed outside of the container cgroup. This is easy to fix by just doing the clone in Go code (we could even make it part of therunc initfork+exec -- to remove one extra exec). - Bind mount sources (Open bind mount sources from the host userns #2576) are currently handled in a way that requires C code because we need to temporarily join the container mount namespace to open the mount sources (the kernel blocks bind-mount sources from a different mount namespace). However,
open_tree(OPEN_TREE_CLONE)allows us to get around this, meaning that if we bump the minimum kernel version for this optional runc feature, we can doOPEN_TREE_CLONEon the host runc side and just pass the detached-mountfds to the rootfs setup code without any C code.-
IDMAP_SOURCES_ATTRis implemented in an analogous way to the bind-mount sources code, but because it requiresmount_setattr(2), theOPEN_TREE_CLONEsuggestion above is actually even more applicable. We can even implement Support for ID map mounts without userns #3943 entirely in Go and apply the mount attribute in the host side of runc.
-
- The session handling by
SysProcAttris probably fine to just use "normally", but I wonder if we need to take anything in particular into account. - As far as I can see, there is no way to join existing namespaces with
SysProcAttr-- and sincesetns(CLONE_NEWUSER)requires us to be single-threaded this would mean we would need to keepnsexec.c. This would require a patch to stdlib, but there is an additional issue to consider:-
setns()supports joining a subset of namespaces of a given pidfd since Linux 5.8. This is something we probably want to use, but if we use stdlib there isn't a nice way to handle the fallback (join each namespace separately). It is trivial to detect whether it is supported (pass a pidfd tosetns) but due to the API ofSysProcAttr, I suspect we would need to detect the support from Go (we can do this safely withCLONE_NEWUSERbecause it will always fail but this will fail with-EINVALso we can't use it to detect anything -- maybe we will need to doCLONE_NEWPIDin a os-thread-locked goroutine and switch back because that doesn't affect the running process...) and then tune what we pass toSysProcAttrseparately.
-
Agree with @cyphar -- if we can do it in Go, we should do it in Go.
Overall I very much hope we'll eventually be able to do all of it in Go. For example, with cgroupfd support in the kernel (since v5.7) and golang stdlib (since 1.20), we can enter cgroups way easier.
Originally posted by @kolyshkin in #3943 (comment)
fuweid, lifubang, kolyshkin, avagin and yoonhyunwoo
Metadata
Metadata
Assignees
Labels
No labels