mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Make host directory mounts use idtools.MkdirAllNewAs
This makes sure that: 1. Already existing directories are left untouched 2. Newly created directories are chowned to the correct root UID/GID in case of user namespaces 3. All parent directories still get created with host root UID/GID Fix #21738 Signed-off-by: Antonis Kalipetis <akalipetis@gmail.com>
This commit is contained in:
parent
01fe5639bc
commit
72d8a77d52
2 changed files with 7 additions and 5 deletions
|
@ -28,7 +28,8 @@ func (daemon *Daemon) setupMounts(c *container.Container) ([]container.Mount, er
|
||||||
if err := daemon.lazyInitializeVolume(c.ID, m); err != nil {
|
if err := daemon.lazyInitializeVolume(c.ID, m); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
path, err := m.Setup(c.MountLabel)
|
rootUID, rootGID := daemon.GetRemappedUIDGID()
|
||||||
|
path, err := m.Setup(c.MountLabel, rootUID, rootGID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,8 +6,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
|
"github.com/docker/docker/pkg/idtools"
|
||||||
"github.com/docker/docker/pkg/stringid"
|
"github.com/docker/docker/pkg/stringid"
|
||||||
"github.com/docker/docker/pkg/system"
|
|
||||||
mounttypes "github.com/docker/engine-api/types/mount"
|
mounttypes "github.com/docker/engine-api/types/mount"
|
||||||
"github.com/opencontainers/runc/libcontainer/label"
|
"github.com/opencontainers/runc/libcontainer/label"
|
||||||
)
|
)
|
||||||
|
@ -107,7 +107,7 @@ type MountPoint struct {
|
||||||
|
|
||||||
// Setup sets up a mount point by either mounting the volume if it is
|
// Setup sets up a mount point by either mounting the volume if it is
|
||||||
// configured, or creating the source directory if supplied.
|
// configured, or creating the source directory if supplied.
|
||||||
func (m *MountPoint) Setup(mountLabel string) (string, error) {
|
func (m *MountPoint) Setup(mountLabel string, rootUID, rootGID int) (string, error) {
|
||||||
if m.Volume != nil {
|
if m.Volume != nil {
|
||||||
if m.ID == "" {
|
if m.ID == "" {
|
||||||
m.ID = stringid.GenerateNonCryptoID()
|
m.ID = stringid.GenerateNonCryptoID()
|
||||||
|
@ -117,8 +117,9 @@ func (m *MountPoint) Setup(mountLabel string) (string, error) {
|
||||||
if len(m.Source) == 0 {
|
if len(m.Source) == 0 {
|
||||||
return "", fmt.Errorf("Unable to setup mount point, neither source nor volume defined")
|
return "", fmt.Errorf("Unable to setup mount point, neither source nor volume defined")
|
||||||
}
|
}
|
||||||
// system.MkdirAll() produces an error if m.Source exists and is a file (not a directory),
|
// idtools.MkdirAllNewAs() produces an error if m.Source exists and is a file (not a directory)
|
||||||
if err := system.MkdirAll(m.Source, 0755); err != nil {
|
// also, makes sure that if the directory is created, the correct remapped rootUID/rootGID will own it
|
||||||
|
if err := idtools.MkdirAllNewAs(m.Source, 0755, rootUID, rootGID); err != nil {
|
||||||
if perr, ok := err.(*os.PathError); ok {
|
if perr, ok := err.(*os.PathError); ok {
|
||||||
if perr.Err != syscall.ENOTDIR {
|
if perr.Err != syscall.ENOTDIR {
|
||||||
return "", err
|
return "", err
|
||||||
|
|
Loading…
Add table
Reference in a new issue