github.com/buildpacks/pack@v0.33.3-0.20240516162812-884dd1837311/pkg/client/process_volumes_darwin.go (about) 1 package client 2 3 import ( 4 "fmt" 5 "strings" 6 7 "github.com/docker/cli/cli/compose/loader" 8 "github.com/docker/cli/cli/compose/types" 9 "github.com/pkg/errors" 10 11 "github.com/buildpacks/pack/internal/style" 12 ) 13 14 func processVolumes(imgOS string, volumes []string) (processed []string, warnings []string, err error) { 15 for _, v := range volumes { 16 volume, err := parseVolume(v) 17 if err != nil { 18 return nil, nil, err 19 } 20 sensitiveDirs := []string{"/cnb", "/layers"} 21 if imgOS == "windows" { 22 sensitiveDirs = []string{`c:/cnb`, `c:\cnb`, `c:/layers`, `c:\layers`} 23 } 24 for _, p := range sensitiveDirs { 25 if strings.HasPrefix(strings.ToLower(volume.Target), p) { 26 warnings = append(warnings, fmt.Sprintf("Mounting to a sensitive directory %s", style.Symbol(volume.Target))) 27 } 28 } 29 mode := "ro" 30 if strings.HasSuffix(v, ":rw") && !volume.ReadOnly { 31 mode = "rw" 32 } 33 processed = append(processed, fmt.Sprintf("%s:%s:%s", volume.Source, volume.Target, mode)) 34 } 35 return processed, warnings, nil 36 } 37 38 func parseVolume(volume string) (types.ServiceVolumeConfig, error) { 39 // volume format: '<host path>:<target path>[:<options>]' 40 split := strings.Split(volume, ":") 41 if len(split) == 3 { 42 if split[2] != "ro" && split[2] != "rw" && !strings.Contains(split[2], "volume-opt") { 43 return types.ServiceVolumeConfig{}, errors.New(fmt.Sprintf("platform volume %q has invalid format: invalid mode: %s", volume, split[2])) 44 } 45 } 46 config, err := loader.ParseVolume(volume) 47 if err != nil { 48 return config, errors.Wrapf(err, "platform volume %q has invalid format", volume) 49 } 50 return config, nil 51 }