Skip to content

Commit 7cfb107

Browse files
committed
factory: use e{u,g}id as the owner of /run/runc/$id
It appears as though these semantics were not fully thought out when implementing them for rootless containers. It is not necessary (and could be potentially dangerous) to set the owner of /run/ctr/$id to be the root inside the container (if user namespaces are being used). Instead, just use the e{g,u}id of runc to determine the owner. Signed-off-by: Aleksa Sarai <[email protected]>
1 parent 21a005d commit 7cfb107

File tree

1 file changed

+1
-9
lines changed

1 file changed

+1
-9
lines changed

libcontainer/factory_linux.go

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,6 @@ func (l *LinuxFactory) Create(id string, config *configs.Config) (Container, err
162162
if err := l.Validator.Validate(config); err != nil {
163163
return nil, newGenericError(err, ConfigInvalid)
164164
}
165-
uid, err := config.HostRootUID()
166-
if err != nil {
167-
return nil, newGenericError(err, SystemError)
168-
}
169-
gid, err := config.HostRootGID()
170-
if err != nil {
171-
return nil, newGenericError(err, SystemError)
172-
}
173165
containerRoot := filepath.Join(l.Root, id)
174166
if _, err := os.Stat(containerRoot); err == nil {
175167
return nil, newGenericError(fmt.Errorf("container with id exists: %v", id), IdInUse)
@@ -179,7 +171,7 @@ func (l *LinuxFactory) Create(id string, config *configs.Config) (Container, err
179171
if err := os.MkdirAll(containerRoot, 0711); err != nil {
180172
return nil, newGenericError(err, SystemError)
181173
}
182-
if err := os.Chown(containerRoot, uid, gid); err != nil {
174+
if err := os.Chown(containerRoot, unix.Geteuid(), unix.Getegid()); err != nil {
183175
return nil, newGenericError(err, SystemError)
184176
}
185177
if config.Rootless {

0 commit comments

Comments
 (0)