From 47778f8b77dd0de503ac53d425d087c941e47590 Mon Sep 17 00:00:00 2001 From: Nicolas De Loof Date: Tue, 18 Jul 2023 10:00:32 +0200 Subject: [PATCH] check secret target is an absolute windows path Signed-off-by: Nicolas De Loof --- pkg/compose/create.go | 18 ++++++++++++++++-- pkg/compose/secrets.go | 2 +- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/pkg/compose/create.go b/pkg/compose/create.go index ffc9f178cf..f82f8f23ff 100644 --- a/pkg/compose/create.go +++ b/pkg/compose/create.go @@ -863,7 +863,7 @@ func buildContainerConfigMounts(p types.Project, s types.ServiceConfig) ([]mount target := config.Target if config.Target == "" { target = configsBaseDir + config.Source - } else if !isUnixAbs(config.Target) { + } else if !isAbsTarget(config.Target) { target = configsBaseDir + config.Target } @@ -898,7 +898,7 @@ func buildContainerSecretMounts(p types.Project, s types.ServiceConfig) ([]mount target := secret.Target if secret.Target == "" { target = secretsDir + secret.Source - } else if !isUnixAbs(secret.Target) { + } else if !isAbsTarget(secret.Target) { target = secretsDir + secret.Target } @@ -929,10 +929,24 @@ func buildContainerSecretMounts(p types.Project, s types.ServiceConfig) ([]mount return values, nil } +func isAbsTarget(p string) bool { + return isUnixAbs(p) || isWindowsAbs(p) +} + func isUnixAbs(p string) bool { return strings.HasPrefix(p, "/") } +func isWindowsAbs(p string) bool { + if strings.HasPrefix(p, "\\\\") { + return true + } + if len(p) > 2 && p[1] == ':' { + return p[2] == '\\' + } + return false +} + func buildMount(project types.Project, volume types.ServiceVolumeConfig) (mount.Mount, error) { source := volume.Source // on windows, filepath.IsAbs(source) is false for unix style abs path like /var/run/docker.sock. diff --git a/pkg/compose/secrets.go b/pkg/compose/secrets.go index 4d96f5c9c3..26573fbd01 100644 --- a/pkg/compose/secrets.go +++ b/pkg/compose/secrets.go @@ -66,7 +66,7 @@ func createTar(env string, config types.ServiceSecretConfig) (bytes.Buffer, erro target := config.Target if config.Target == "" { target = "/run/secrets/" + config.Source - } else if !isUnixAbs(config.Target) { + } else if !isAbsTarget(config.Target) { target = "/run/secrets/" + config.Target }