From 08a8429459fdeddec73ffb8e5efe339f6312dba1 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Tue, 18 Jun 2024 23:09:55 +0200 Subject: [PATCH] libpod: avoid chowning the rundir to root in the userns so it is possible to remove the code to make the entire directory world accessible. Signed-off-by: Giuseppe Scrivano --- libpod/container_internal.go | 10 ---------- libpod/container_internal_common.go | 4 ---- libpod/oci_conmon_common.go | 5 ----- 3 files changed, 19 deletions(-) diff --git a/libpod/container_internal.go b/libpod/container_internal.go index d1eeb7f851..29a32a1c3c 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -544,16 +544,6 @@ func (c *Container) setupStorage(ctx context.Context) error { c.config.StaticDir = containerInfo.Dir c.state.RunDir = containerInfo.RunDir - if len(c.config.IDMappings.UIDMap) != 0 || len(c.config.IDMappings.GIDMap) != 0 { - if err := idtools.SafeChown(containerInfo.RunDir, c.RootUID(), c.RootGID()); err != nil { - return err - } - - if err := idtools.SafeChown(containerInfo.Dir, c.RootUID(), c.RootGID()); err != nil { - return err - } - } - // Set the default Entrypoint and Command if containerInfo.Config != nil { // Set CMD in the container to the default configuration only if ENTRYPOINT is not set by the user. diff --git a/libpod/container_internal_common.go b/libpod/container_internal_common.go index 65afbf0274..216074e130 100644 --- a/libpod/container_internal_common.go +++ b/libpod/container_internal_common.go @@ -1834,10 +1834,6 @@ func (c *Container) mountIntoRootDirs(mountName string, mountPath string) error // Make standard bind mounts to include in the container func (c *Container) makeBindMounts() error { - if err := idtools.SafeChown(c.state.RunDir, c.RootUID(), c.RootGID()); err != nil { - return fmt.Errorf("cannot chown run directory: %w", err) - } - if c.state.BindMounts == nil { c.state.BindMounts = make(map[string]string) } diff --git a/libpod/oci_conmon_common.go b/libpod/oci_conmon_common.go index d72f7eb14c..ff0e790860 100644 --- a/libpod/oci_conmon_common.go +++ b/libpod/oci_conmon_common.go @@ -183,11 +183,6 @@ func hasCurrentUserMapped(ctr *Container) bool { // CreateContainer creates a container. func (r *ConmonOCIRuntime) CreateContainer(ctr *Container, restoreOptions *ContainerCheckpointOptions) (int64, error) { - // always make the container directory accessible to the current user so that the PID files can be read without - // being in the rootless user namespace. - if err := makeAccessible(ctr.state.RunDir, 0, 0); err != nil { - return 0, err - } if !hasCurrentUserMapped(ctr) { if err := makeAccessible(ctr.state.Mountpoint, ctr.RootUID(), ctr.RootGID()); err != nil { return 0, err