Skip to content

Commit 52f702a

Browse files
committed
libct: earlier Rootless vs AdditionalGroups check
Since the UID/GID/AdditonalGroups fields are now numeric, we can address the following TODO item in the code (added by commit d2f4969 back in 2016): > TODO: We currently can't do > this check earlier, but if libcontainer.Process.User was typesafe > this might work. Move the check to much earlier phase, when we're preparing to start a process in a container. Signed-off-by: Kir Kolyshkin <[email protected]>
1 parent 7dc2486 commit 52f702a

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

libcontainer/container_linux.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,13 @@ func (c *Container) start(process *Process) (retErr error) {
302302
if c.config.Cgroups.Resources.SkipDevices {
303303
return errors.New("can't start container with SkipDevices set")
304304
}
305+
306+
if c.config.RootlessEUID && len(process.AdditionalGroups) > 0 {
307+
// We cannot set any additional groups in a rootless container
308+
// and thus we bail if the user asked us to do so.
309+
return errors.New("cannot set any additional groups in a rootless container")
310+
}
311+
305312
if process.Init {
306313
if c.initProcessStartTime != 0 {
307314
return errors.New("container already has init process")

libcontainer/init_linux.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -438,14 +438,6 @@ func syncParentSeccomp(pipe *syncSocket, seccompFd int) error {
438438

439439
// setupUser changes the groups, gid, and uid for the user inside the container.
440440
func setupUser(config *initConfig) error {
441-
if config.RootlessEUID && len(config.AdditionalGroups) > 0 {
442-
// We cannot set any additional groups in a rootless container and thus
443-
// we bail if the user asked us to do so. TODO: We currently can't do
444-
// this check earlier, but if libcontainer.Process.User was typesafe
445-
// this might work.
446-
return errors.New("cannot set any additional groups in a rootless container")
447-
}
448-
449441
// Before we change to the container's user make sure that the processes
450442
// STDIO is correctly owned by the user that we are switching to.
451443
if err := fixStdioPermissions(config.UID); err != nil {

0 commit comments

Comments
 (0)