summaryrefslogtreecommitdiff
path: root/pkg/auth/auth.go
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2021-09-11 21:56:40 +0200
committerMiloslav Trmač <mitr@redhat.com>2021-12-10 18:16:17 +0100
commit491951d66e1829ad8e847f3049a557dd9d55db68 (patch)
tree5d73ddfc76c05306cd0fbc0570f48392b4e14720 /pkg/auth/auth.go
parent1b6bf971306af753e72db9d10f7594ecd0c89785 (diff)
downloadpodman-491951d66e1829ad8e847f3049a557dd9d55db68.tar.gz
podman-491951d66e1829ad8e847f3049a557dd9d55db68.tar.bz2
podman-491951d66e1829ad8e847f3049a557dd9d55db68.zip
Fix normalizeAuthFileKey to use the correct semantics
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
Diffstat (limited to 'pkg/auth/auth.go')
-rw-r--r--pkg/auth/auth.go18
1 files changed, 11 insertions, 7 deletions
diff --git a/pkg/auth/auth.go b/pkg/auth/auth.go
index 8c6436883..7cde6ef5e 100644
--- a/pkg/auth/auth.go
+++ b/pkg/auth/auth.go
@@ -272,20 +272,24 @@ func authConfigsToAuthFile(authConfigs map[string]types.DockerAuthConfig) (strin
return authFilePath, nil
}
-// normalizeAuthFileKey takes an auth file key and removes the leading "http[s]://" prefix as well
-// as removes path suffixes from docker registries.
+// normalizeAuthFileKey takes an auth file key and converts it into a new-style credential key
+// in the canonical format, as interpreted by c/image/pkg/docker/config.
func normalizeAuthFileKey(authFileKey string) string {
stripped := strings.TrimPrefix(authFileKey, "http://")
stripped = strings.TrimPrefix(stripped, "https://")
- /// Normalize docker registries
- if strings.HasPrefix(stripped, "index.docker.io/") ||
- strings.HasPrefix(stripped, "registry-1.docker.io/") ||
- strings.HasPrefix(stripped, "docker.io/") {
+ if stripped != authFileKey { // URLs are interpreted to mean complete registries
stripped = strings.SplitN(stripped, "/", 2)[0]
}
- return stripped
+ // Only non-namespaced registry names (or URLs) need to be normalized; repo namespaces
+ // always use the simple format.
+ switch stripped {
+ case "registry-1.docker.io", "index.docker.io":
+ return "docker.io"
+ default:
+ return stripped
+ }
}
// dockerAuthToImageAuth converts a docker auth config to one we're using