From 3c22540321589ffec6d25cf537a9cb675813b1cd Mon Sep 17 00:00:00 2001 From: Alexander Niebuhr Date: Thu, 16 Jun 2022 19:47:17 +0200 Subject: [PATCH] fix: correct authentication for ghcr.io registry(#349) Co-authored-by: Martin --- internal/provider/data_source_docker_registry_image.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/internal/provider/data_source_docker_registry_image.go b/internal/provider/data_source_docker_registry_image.go index debe5989..7cf27953 100644 --- a/internal/provider/data_source_docker_registry_image.go +++ b/internal/provider/data_source_docker_registry_image.go @@ -4,6 +4,7 @@ import ( "context" "crypto/sha256" "crypto/tls" + b64 "encoding/base64" "encoding/json" "fmt" "io/ioutil" @@ -101,7 +102,11 @@ func getImageDigest(registry, image, tag, username, password string, insecureSki } if username != "" { - req.SetBasicAuth(username, password) + if registry != "ghcr.io" { + req.SetBasicAuth(username, password) + } else { + req.Header.Add("Authorization", "Bearer "+b64.StdEncoding.EncodeToString([]byte(password))) + } } // We accept schema v2 manifests and manifest lists, and also OCI types