From 4cab1781f6ac9e634c8a2d0d749a8ebbde5eafd4 Mon Sep 17 00:00:00 2001 From: Alex Dadgar Date: Tue, 5 Sep 2017 16:32:40 -0700 Subject: [PATCH] Fix repo name passed to docker credential helpers This PR fixes the server url passed to docker credential helpers and fixes stderr capture. Fixes https://github.com/hashicorp/nomad/issues/2957 --- CHANGELOG.md | 2 ++ client/driver/docker.go | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 443091f3f4e8..c49c4fccc864 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -19,6 +19,8 @@ BUG FIXES: * driver/docker: Fix issue in which mounts could parse incorrectly [GH-3163] * driver/docker: Fix issue where potentially incorrect syslog server address is used [GH-3135] + * driver/docker: Fix server url passed to credential helpers and properly + capture error output [GH-3165] * jobspec: Allow distinct_host constraint to have L/RTarget set [GH-3136] ## 0.6.2 (August 28, 2017) diff --git a/client/driver/docker.go b/client/driver/docker.go index dab056d5f102..da23ee4de66e 100644 --- a/client/driver/docker.go +++ b/client/driver/docker.go @@ -1795,15 +1795,21 @@ func authFromHelper(helperName string) authBackend { } helper := dockerAuthHelperPrefix + helperName cmd := exec.Command(helper, "get") + + // Ensure that the HTTPs prefix exists + if !strings.HasPrefix(repo, "https://") { + repo = fmt.Sprintf("https://%s", repo) + } + cmd.Stdin = strings.NewReader(repo) output, err := cmd.Output() if err != nil { - switch e := err.(type) { + switch err.(type) { default: return nil, err case *exec.ExitError: - return nil, fmt.Errorf("%s failed with stderr: %s", helper, string(e.Stderr)) + return nil, fmt.Errorf("%s with input %q failed with stderr: %s", helper, repo, output) } }