2018-02-05 16:05:59 -05:00
|
|
|
package container // import "github.com/docker/docker/daemon/cluster/executor/container"
|
2016-08-01 17:00:13 -04:00
|
|
|
|
|
|
|
import (
|
2016-12-25 01:37:31 -05:00
|
|
|
"errors"
|
2016-08-01 17:00:13 -04:00
|
|
|
"fmt"
|
|
|
|
"path/filepath"
|
|
|
|
|
|
|
|
"github.com/docker/swarmkit/api"
|
|
|
|
)
|
|
|
|
|
|
|
|
func validateMounts(mounts []api.Mount) error {
|
|
|
|
for _, mount := range mounts {
|
|
|
|
// Target must always be absolute
|
2018-07-05 17:18:49 -04:00
|
|
|
// except if target is Windows named pipe
|
|
|
|
if !filepath.IsAbs(mount.Target) && mount.Type != api.MountTypeNamedPipe {
|
2016-08-01 17:00:13 -04:00
|
|
|
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
|
2016-10-29 03:03:26 -04:00
|
|
|
// TODO: This is probably not necessary once #22373 is merged
|
2016-08-01 17:00:13 -04:00
|
|
|
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 != "" {
|
2016-12-25 01:37:31 -05:00
|
|
|
return errors.New("invalid tmpfs source, source must be empty")
|
2016-08-01 17:00:13 -04:00
|
|
|
}
|
2018-07-05 17:18:49 -04:00
|
|
|
case api.MountTypeNamedPipe:
|
|
|
|
if mount.Source == "" {
|
|
|
|
return errors.New("invalid npipe source, source must not be empty")
|
|
|
|
}
|
2016-08-01 17:00:13 -04:00
|
|
|
default:
|
|
|
|
return fmt.Errorf("invalid mount type: %s", mount.Type)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|