From 2ad6012ea1943cb045ebc1a7071c9a9a61538d11 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Tue, 9 Oct 2018 09:45:21 +0200 Subject: volume: write the correct ID of the container in error messages Signed-off-by: Giuseppe Scrivano --- libpod/container_internal.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'libpod') diff --git a/libpod/container_internal.go b/libpod/container_internal.go index ab79aa790..0a17996d6 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -1212,28 +1212,28 @@ func (c *Container) addLocalVolumes(ctx context.Context, g *generate.Generator) if _, err := os.Stat(srcPath); os.IsNotExist(err) { logrus.Infof("Volume image mount point %s does not exist in root FS, need to create it", k) if err = os.MkdirAll(srcPath, 0755); err != nil { - return errors.Wrapf(err, "error creating directory %q for volume %q in container %q", volumePath, k, c.ID) + return errors.Wrapf(err, "error creating directory %q for volume %q in container %q", volumePath, k, c.ID()) } if err = os.Chown(srcPath, int(uid), int(gid)); err != nil { - return errors.Wrapf(err, "error chowning directory %q for volume %q in container %q", srcPath, k, c.ID) + return errors.Wrapf(err, "error chowning directory %q for volume %q in container %q", srcPath, k, c.ID()) } } if _, err := os.Stat(volumePath); os.IsNotExist(err) { if err = os.MkdirAll(volumePath, 0755); err != nil { - return errors.Wrapf(err, "error creating directory %q for volume %q in container %q", volumePath, k, c.ID) + return errors.Wrapf(err, "error creating directory %q for volume %q in container %q", volumePath, k, c.ID()) } if err = os.Chown(volumePath, int(uid), int(gid)); err != nil { - return errors.Wrapf(err, "error chowning directory %q for volume %q in container %q", volumePath, k, c.ID) + return errors.Wrapf(err, "error chowning directory %q for volume %q in container %q", volumePath, k, c.ID()) } if err = label.Relabel(volumePath, c.config.MountLabel, false); err != nil { - return errors.Wrapf(err, "error relabeling directory %q for volume %q in container %q", volumePath, k, c.ID) + return errors.Wrapf(err, "error relabeling directory %q for volume %q in container %q", volumePath, k, c.ID()) } if err = chrootarchive.NewArchiver(nil).CopyWithTar(srcPath, volumePath); err != nil && !os.IsNotExist(err) { - return errors.Wrapf(err, "error populating directory %q for volume %q in container %q using contents of %q", volumePath, k, c.ID, srcPath) + return errors.Wrapf(err, "error populating directory %q for volume %q in container %q using contents of %q", volumePath, k, c.ID(), srcPath) } // Set the volume path with the same owner and permission of source path -- cgit v1.2.3-54-g00ecf From 6dd6ce1ebcdb17023f09fad93698d09408227385 Mon Sep 17 00:00:00 2001 From: Giuseppe Scrivano Date: Tue, 9 Oct 2018 10:48:28 +0200 Subject: volume: resolve symlinks in paths ensure the volume paths are resolved in the mountpoint scope. Otherwise we might end up using host paths. Closes: https://github.com/containers/libpod/issues/1608 Signed-off-by: Giuseppe Scrivano --- libpod/container_internal.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'libpod') diff --git a/libpod/container_internal.go b/libpod/container_internal.go index 0a17996d6..9291d72c1 100644 --- a/libpod/container_internal.go +++ b/libpod/container_internal.go @@ -13,6 +13,7 @@ import ( "strings" "syscall" + "github.com/containers/buildah/imagebuildah" "github.com/containers/libpod/pkg/chrootuser" "github.com/containers/libpod/pkg/hooks" "github.com/containers/libpod/pkg/hooks/exec" @@ -1193,8 +1194,6 @@ func (c *Container) addLocalVolumes(ctx context.Context, g *generate.Generator) continue } volumePath := filepath.Join(c.config.StaticDir, "volumes", k) - srcPath := filepath.Join(mountPoint, k) - var ( uid uint32 gid uint32 @@ -1209,6 +1208,18 @@ func (c *Container) addLocalVolumes(ctx context.Context, g *generate.Generator) } } + // Ensure the symlinks are resolved + resolvedSymlink, err := imagebuildah.ResolveSymLink(mountPoint, k) + if err != nil { + return errors.Wrapf(ErrCtrStateInvalid, "cannot resolve %s in %s for container %s", k, mountPoint, c.ID()) + } + var srcPath string + if resolvedSymlink != "" { + srcPath = filepath.Join(mountPoint, resolvedSymlink) + } else { + srcPath = filepath.Join(mountPoint, k) + } + if _, err := os.Stat(srcPath); os.IsNotExist(err) { logrus.Infof("Volume image mount point %s does not exist in root FS, need to create it", k) if err = os.MkdirAll(srcPath, 0755); err != nil { -- cgit v1.2.3-54-g00ecf