Skip to content

Commit

Permalink
fix: make docker hostname detection more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
ZauberNerd authored Nov 18, 2021
1 parent 088cc90 commit e74c857
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions pkg/container/docker_auth.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package container

import (
"net/url"
"regexp"
"strings"

"github.com/docker/cli/cli/config"
"github.com/docker/cli/cli/config/credentials"
Expand All @@ -21,17 +20,13 @@ func LoadDockerAuthConfig(image string) (types.AuthConfig, error) {
config.CredentialsStore = credentials.DetectDefaultStore(config.CredentialsStore)
}

if matches, _ := regexp.MatchString("^[^.:]+\\/", image); matches {
image = "index.docker.io/v1/" + image
hostName := "index.docker.io"
index := strings.IndexRune(image, '/')
if index > -1 && (strings.ContainsAny(image[:index], ".:") || image[:index] == "localhost") {
hostName = image[:index]
}

parsed, err := url.Parse("http://" + image)
if err != nil {
log.Warnf("Could not parse image url: %v", err)
return types.AuthConfig{}, err
}

authConfig, err := config.GetAuthConfig(parsed.Hostname())
authConfig, err := config.GetAuthConfig(hostName)
if err != nil {
log.Warnf("Could not get auth config from docker config: %v", err)
return types.AuthConfig{}, err
Expand Down

0 comments on commit e74c857

Please sign in to comment.