From 2f710b0ce4fa34a502fda4e7aa4ab2cb2e0fd698 Mon Sep 17 00:00:00 2001 From: Tom Chauveau Date: Thu, 1 Jul 2021 14:08:49 +0200 Subject: [PATCH] Fix login miss behavior and update op Signed-off-by: Tom Chauveau --- solver/registryauth.go | 24 ++++++++---------------- stdlib/dagger/op/op.cue | 2 +- tests/ops/push-container/main.cue | 1 + 3 files changed, 10 insertions(+), 17 deletions(-) diff --git a/solver/registryauth.go b/solver/registryauth.go index 20a4608f..cf2684fa 100644 --- a/solver/registryauth.go +++ b/solver/registryauth.go @@ -2,7 +2,6 @@ package solver import ( "context" - "net/url" "strings" "sync" @@ -41,9 +40,9 @@ func (a *RegistryAuthProvider) Register(server *grpc.Server) { } func (a *RegistryAuthProvider) Credentials(ctx context.Context, req *bkauth.CredentialsRequest) (*bkauth.CredentialsResponse, error) { - reqURL, err := parseAuthHost(req.Host) - if err != nil { - return nil, err + host := req.Host + if host == "registry-1.docker.io" { + host = "docker.io" } a.m.RLock() @@ -55,7 +54,7 @@ func (a *RegistryAuthProvider) Credentials(ctx context.Context, req *bkauth.Cred return nil, err } - if u.Host == reqURL.Host { + if u == host { return auth, nil } } @@ -63,23 +62,16 @@ func (a *RegistryAuthProvider) Credentials(ctx context.Context, req *bkauth.Cred return &bkauth.CredentialsResponse{}, nil } -func parseAuthHost(host string) (*url.URL, error) { +func parseAuthHost(host string) (string, error) { host = strings.TrimPrefix(host, "http://") host = strings.TrimPrefix(host, "https://") - // Retrieve only the registry - host = strings.SplitN(host, "/", 2)[0] - ref, err := reference.ParseNormalizedNamed(host) - if err != nil { - return nil, err - } - host = ref.String() - if !strings.HasPrefix(host, "http://") && !strings.HasPrefix(host, "https://") { - host = "https://" + host + if err != nil { + return "", err } - return url.Parse(host) + return reference.Domain(ref), nil } func (a *RegistryAuthProvider) FetchToken(ctx context.Context, req *bkauth.FetchTokenRequest) (rr *bkauth.FetchTokenResponse, err error) { diff --git a/stdlib/dagger/op/op.cue b/stdlib/dagger/op/op.cue index 8fff9c31..123e48f4 100644 --- a/stdlib/dagger/op/op.cue +++ b/stdlib/dagger/op/op.cue @@ -59,7 +59,7 @@ package op #DockerLogin: { do: "docker-login" - target: string | *"https://index.docker.io/v1/" + target: string username: string // FIXME: should be a #Secret (circular import) secret: string | bytes diff --git a/tests/ops/push-container/main.cue b/tests/ops/push-container/main.cue index 7761c0a7..2b84729b 100644 --- a/tests/ops/push-container/main.cue +++ b/tests/ops/push-container/main.cue @@ -21,6 +21,7 @@ TestPushContainer: { ref: "daggerio/ci-test:\(tag.out)" #up: [ op.#DockerLogin & { + target: ref registry }, op.#WriteFile & {