Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docker_auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"fmt"
"net/url"
"os"
"strings"
"sync"

"github.com/cpuguy83/dockercfg"
Expand Down Expand Up @@ -42,6 +43,11 @@ func dockerImageAuth(ctx context.Context, image string, configs map[string]regis
defaultRegistry := defaultRegistryFn(ctx)
reg := core.ExtractRegistry(image, defaultRegistry)

// Make comparison case-insensitive and handle both aliases
if strings.EqualFold(reg, "docker.io") || strings.EqualFold(reg, "registry.hub.docker.com") {
reg = defaultRegistry
}

Comment on lines +46 to +50
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: should this be handled by core.ExtractRegistry?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could. Up to y'all

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should live there, @mdelapenya thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, let's move it there, and once we use the go-sdk, it will be resolved and easier to replace

if cfg, ok := getRegistryAuth(reg, configs); ok {
return reg, cfg, nil
}
Expand Down
14 changes: 14 additions & 0 deletions docker_auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,20 @@ func TestDockerImageAuth(t *testing.T) {
require.Equal(t, base64, cfg.Auth)
})

t.Run("match the default registry authentication by host", func(t *testing.T) {
imageReg := "docker.io"
imagePath := "/my/image:latest"
reg := defaultRegistry(context.Background())
base64 := setAuthConfig(t, reg, "gopher", "secret")

registry, cfg, err := DockerImageAuth(context.Background(), imageReg+imagePath)
require.NoError(t, err)
require.Equal(t, reg, registry)
require.Equal(t, "gopher", cfg.Username)
require.Equal(t, "secret", cfg.Password)
require.Equal(t, base64, cfg.Auth)
})

t.Run("fail to match registry authentication due to invalid host", func(t *testing.T) {
imageReg := "example-auth.com"
imagePath := "/my/image:latest"
Expand Down
Loading