Skip to content

Commit

Permalink
Merge pull request #10819 from ndeloof/windows_abs
Browse files Browse the repository at this point in the history
check secret target is an absolute windows path
  • Loading branch information
glours authored Jul 19, 2023
2 parents 7d88eda + 47778f8 commit 3b2f3cd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
18 changes: 16 additions & 2 deletions pkg/compose/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pkg/compose/secrets.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit 3b2f3cd

Please sign in to comment.