validate.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. package container
  2. import (
  3. "fmt"
  4. "path/filepath"
  5. "github.com/docker/swarmkit/api"
  6. )
  7. func validateMounts(mounts []api.Mount) error {
  8. for _, mount := range mounts {
  9. // Target must always be absolute
  10. if !filepath.IsAbs(mount.Target) {
  11. return fmt.Errorf("invalid mount target, must be an absolute path: %s", mount.Target)
  12. }
  13. switch mount.Type {
  14. // The checks on abs paths are required due to the container API confusing
  15. // volume mounts as bind mounts when the source is absolute (and vice-versa)
  16. // See #25253
  17. // TODO: This is probably not neccessary once #22373 is merged
  18. case api.MountTypeBind:
  19. if !filepath.IsAbs(mount.Source) {
  20. return fmt.Errorf("invalid bind mount source, must be an absolute path: %s", mount.Source)
  21. }
  22. case api.MountTypeVolume:
  23. if filepath.IsAbs(mount.Source) {
  24. return fmt.Errorf("invalid volume mount source, must not be an absolute path: %s", mount.Source)
  25. }
  26. case api.MountTypeTmpfs:
  27. if mount.Source != "" {
  28. return fmt.Errorf("invalid tmpfs source, source must be empty")
  29. }
  30. default:
  31. return fmt.Errorf("invalid mount type: %s", mount.Type)
  32. }
  33. }
  34. return nil
  35. }