Skip to content

Commit f035d60

Browse files
committed
server: make paths to chown also accessible
Signed-off-by: Giuseppe Scrivano <[email protected]>
1 parent d9d3789 commit f035d60

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

server/container_create_linux.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,6 @@ func (s *Server) createContainerPlatform(container *oci.Container, cgroupParent
168168
rootPair := s.defaultIDMappings.RootPair()
169169

170170
for _, path := range []string{container.BundlePath(), container.MountPoint()} {
171-
if err := os.Chown(path, rootPair.UID, rootPair.GID); err != nil {
172-
return errors.Wrapf(err, "cannot chown %s to %d:%d", path, rootPair.UID, rootPair.GID)
173-
}
174171
if err := makeAccessible(path, rootPair.UID, rootPair.GID); err != nil {
175172
return errors.Wrapf(err, "cannot make %s accessible to %d:%d", path, rootPair.UID, rootPair.GID)
176173
}
@@ -181,6 +178,9 @@ func (s *Server) createContainerPlatform(container *oci.Container, cgroupParent
181178

182179
// makeAccessible changes the path permission and each parent directory to have --x--x--x
183180
func makeAccessible(path string, uid, gid int) error {
181+
if err := os.Chown(path, uid, gid); err != nil {
182+
return errors.Wrapf(err, "cannot chown %s to %d:%d", path, uid, gid)
183+
}
184184
for ; path != "/"; path = filepath.Dir(path) {
185185
st, err := os.Stat(path)
186186
if err != nil {

server/sandbox_run_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,7 @@ func (s *Server) runPodSandbox(ctx context.Context, req *pb.RunPodSandboxRequest
610610
if s.defaultIDMappings != nil && !s.defaultIDMappings.Empty() {
611611
rootPair := s.defaultIDMappings.RootPair()
612612
for _, path := range pathsToChown {
613-
if err := os.Chown(path, rootPair.UID, rootPair.GID); err != nil {
613+
if err := makeAccessible(path, rootPair.UID, rootPair.GID); err != nil {
614614
return nil, errors.Wrapf(err, "cannot chown %s to %d:%d", path, rootPair.UID, rootPair.GID)
615615
}
616616
}

0 commit comments

Comments
 (0)