From e6b06e24fd67b70c860d72a80b594255cbaa0b0d Mon Sep 17 00:00:00 2001 From: Ameya Gawde Date: Mon, 24 Jul 2023 10:21:32 -0700 Subject: [PATCH 1/2] Fix for creation of windows source directory in case it didn't exist Signed-off-by: Ameya Gawde --- volume/mounts/lcow_parser_test.go | 2 +- volume/mounts/windows_parser.go | 15 +++++++++++++++ volume/mounts/windows_parser_test.go | 2 +- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/volume/mounts/lcow_parser_test.go b/volume/mounts/lcow_parser_test.go index c62309b143..f2cf5fae10 100644 --- a/volume/mounts/lcow_parser_test.go +++ b/volume/mounts/lcow_parser_test.go @@ -15,6 +15,7 @@ func TestLCOWParseMountRaw(t *testing.T) { `/foo/`, `/foo bar`, `c:\:/foo`, + `c:\notexist:/foo`, `c:\windows\:/foo`, `c:\windows:/s p a c e`, `c:\windows:/s p a c e:RW`, @@ -40,7 +41,6 @@ func TestLCOWParseMountRaw(t *testing.T) { `c:\:/foo:xyzzy`: "invalid volume specification: ", `/`: "destination can't be '/'", `/..`: "destination can't be '/'", - `c:\notexist:/foo`: `source path does not exist: c:\notexist`, `c:\windows\system32\ntdll.dll:/foo`: `source path must be a directory`, `name<:/foo`: `invalid volume specification`, `name>:/foo`: `invalid volume specification`, diff --git a/volume/mounts/windows_parser.go b/volume/mounts/windows_parser.go index f9f0f08f44..5f09baffca 100644 --- a/volume/mounts/windows_parser.go +++ b/volume/mounts/windows_parser.go @@ -10,6 +10,7 @@ import ( "github.com/docker/docker/api/types/mount" "github.com/docker/docker/pkg/stringid" + "github.com/docker/docker/pkg/system" ) // NewWindowsParser creates a parser with Windows semantics. @@ -246,6 +247,11 @@ func (p *windowsParser) validateMountConfigReg(mnt *mount.Mount, additionalValid if err != nil { return &errMountConfig{mnt, err} } + + if windowsDetectMountType(mnt.Target) == mount.TypeNamedPipe { + return &errMountConfig{mnt, fmt.Errorf("'%s' is not a valid bind path", mnt.Target)} + } + if !exists { return &errMountConfig{mnt, errBindSourceDoesNotExist(mnt.Source)} } @@ -336,6 +342,15 @@ func (p *windowsParser) parseMount(arr []string, raw, volumeDriver string, conve spec.Type = windowsDetectMountType(spec.Source) spec.ReadOnly = !p.ReadWrite(mode) + // We need to create source directory if it didn't exist for short hand bind mounts. + if spec.Type == mount.TypeBind { + if _, err := os.Stat(spec.Source); os.IsNotExist(err) { + if err := system.MkdirAllWithACL(spec.Source, 0, system.SddlAdministratorsLocalSystem); err != nil { + return nil, fmt.Errorf("failed to mkdir bind source path: %s", spec.Source) + } + } + } + // cannot assume that if a volume driver is passed in that we should set it if volumeDriver != "" && spec.Type == mount.TypeVolume { spec.VolumeOptions = &mount.VolumeOptions{ diff --git a/volume/mounts/windows_parser_test.go b/volume/mounts/windows_parser_test.go index cd63be11b2..c2baed96fd 100644 --- a/volume/mounts/windows_parser_test.go +++ b/volume/mounts/windows_parser_test.go @@ -16,6 +16,7 @@ func TestWindowsParseMountRaw(t *testing.T) { `d:\path`, `d:\path with space`, `c:\:d:\`, + `c:\notexist:d:`, `c:\windows\:d:`, `c:\windows:d:\s p a c e`, `c:\windows:d:\s p a c e:RW`, @@ -45,7 +46,6 @@ func TestWindowsParseMountRaw(t *testing.T) { `c:\:d:\:xyzzy`: "invalid volume specification: ", `c:`: "cannot be `c:`", `c:\`: "cannot be `c:`", - `c:\notexist:d:`: `source path does not exist: c:\notexist`, `c:\windows\system32\ntdll.dll:d:`: `source path must be a directory`, `name<:d:`: `invalid volume specification`, `name>:d:`: `invalid volume specification`, From 3f2620f5b1d3f43c00acf31571067384d77772ef Mon Sep 17 00:00:00 2001 From: Ameya Gawde Date: Tue, 25 Jul 2023 09:54:09 -0700 Subject: [PATCH 2/2] Move SddlAdministratorsLocalSystem to non-platform specific file Signed-off-by: Ameya Gawde --- pkg/system/filesys.go | 4 ++++ pkg/system/filesys_windows.go | 3 --- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/system/filesys.go b/pkg/system/filesys.go index ce5990c914..2f6841ee30 100644 --- a/pkg/system/filesys.go +++ b/pkg/system/filesys.go @@ -6,6 +6,10 @@ import ( "strings" ) +// SddlAdministratorsLocalSystem is local administrators plus NT AUTHORITY\System. +// For non-Windows machine, it holds no meaning. +const SddlAdministratorsLocalSystem = "D:P(A;OICI;GA;;;BA)(A;OICI;GA;;;SY)" + // IsAbs is a platform-agnostic wrapper for filepath.IsAbs. // // On Windows, golang filepath.IsAbs does not consider a path \windows\system32 diff --git a/pkg/system/filesys_windows.go b/pkg/system/filesys_windows.go index 92e972ea2e..4285d94f55 100644 --- a/pkg/system/filesys_windows.go +++ b/pkg/system/filesys_windows.go @@ -9,9 +9,6 @@ import ( "golang.org/x/sys/windows" ) -// SddlAdministratorsLocalSystem is local administrators plus NT AUTHORITY\System. -const SddlAdministratorsLocalSystem = "D:P(A;OICI;GA;;;BA)(A;OICI;GA;;;SY)" - // volumePath is a regular expression to check if a path is a Windows // volume path (e.g., "\\?\Volume{4c1b02c1-d990-11dc-99ae-806e6f6e6963}" // or "\\?\Volume{4c1b02c1-d990-11dc-99ae-806e6f6e6963}\").