1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00
moby--moby/daemon/cluster/executor/container/validate.go
Brian Goff 38f8b0eb10 Validate mount paths on task create
This is intended as a minor fix for 1.12.1 so that task creation doesn't
do unexpected things when the user supplies erroneous paths.

In particular, because we're currently using hostConfig.Binds to setup
mounts, if a user uses an absolute path for a volume mount source, or a
non-absolute path for a bind mount source, the engine will do the
opposite of what the user requested since all absolute paths are
treated as binds and all non-absolute paths are treated as named
volumes.

Fixes #25253

Signed-off-by: Brian Goff <cpuguy83@gmail.com>
2016-08-01 23:35:46 -04:00

39 lines
1.1 KiB
Go

package container
import (
"fmt"
"path/filepath"
"github.com/docker/swarmkit/api"
)
func validateMounts(mounts []api.Mount) error {
for _, mount := range mounts {
// Target must always be absolute
if !filepath.IsAbs(mount.Target) {
return fmt.Errorf("invalid mount target, must be an absolute path: %s", mount.Target)
}
switch mount.Type {
// The checks on abs paths are required due to the container API confusing
// volume mounts as bind mounts when the source is absolute (and vice-versa)
// See #25253
// TODO: This is probably not neccessary once #22373 is merged
case api.MountTypeBind:
if !filepath.IsAbs(mount.Source) {
return fmt.Errorf("invalid bind mount source, must be an absolute path: %s", mount.Source)
}
case api.MountTypeVolume:
if filepath.IsAbs(mount.Source) {
return fmt.Errorf("invalid volume mount source, must not be an absolute path: %s", mount.Source)
}
case api.MountTypeTmpfs:
if mount.Source != "" {
return fmt.Errorf("invalid tmpfs source, source must be empty")
}
default:
return fmt.Errorf("invalid mount type: %s", mount.Type)
}
}
return nil
}