Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check secret target is an absolute windows path #10819

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
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 @@
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
}

Check warning on line 943 in pkg/compose/create.go

View check run for this annotation

Codecov / codecov/patch

pkg/compose/create.go#L942-L943

Added lines #L942 - L943 were not covered by tests
if len(p) > 2 && p[1] == ':' {
return p[2] == '\\'
}

Check warning on line 946 in pkg/compose/create.go

View check run for this annotation

Codecov / codecov/patch

pkg/compose/create.go#L945-L946

Added lines #L945 - L946 were not covered by tests
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
Loading