Skip to content

Commit

Permalink
Merge pull request moby#46779 from dmcgowan/c8d-default-auth-domain
Browse files Browse the repository at this point in the history
Default the auth config domain to the target image domain
  • Loading branch information
thaJeztah authored Nov 7, 2023
2 parents 49cea49 + 755f008 commit c14694a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion daemon/containerd/image_pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (i *ImageService) pullTag(ctx context.Context, ref reference.NamedTagged, p
opts = append(opts, containerd.WithPlatform(platforms.Format(*platform)))
}

resolver, _ := i.newResolverFromAuthConfig(ctx, authConfig)
resolver, _ := i.newResolverFromAuthConfig(ctx, authConfig, ref)
opts = append(opts, containerd.WithResolver(resolver))

old, err := i.resolveDescriptor(ctx, ref.String())
Expand Down
2 changes: 1 addition & 1 deletion daemon/containerd/image_push.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func (i *ImageService) pushRef(ctx context.Context, targetRef reference.Named, m
target := img.Target
store := i.client.ContentStore()

resolver, tracker := i.newResolverFromAuthConfig(ctx, authConfig)
resolver, tracker := i.newResolverFromAuthConfig(ctx, authConfig, targetRef)
pp := pushProgress{Tracker: tracker}
jobsQueue := newJobs()
finishProgress := jobsQueue.showProgress(ctx, out, combinedProgress([]progressUpdater{
Expand Down
16 changes: 10 additions & 6 deletions daemon/containerd/resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,17 @@ import (
"github.com/containerd/containerd/remotes/docker"
"github.com/containerd/containerd/version"
"github.com/containerd/log"
"github.com/distribution/reference"
registrytypes "github.com/docker/docker/api/types/registry"
"github.com/docker/docker/dockerversion"
"github.com/docker/docker/pkg/useragent"
"github.com/docker/docker/registry"
)

func (i *ImageService) newResolverFromAuthConfig(ctx context.Context, authConfig *registrytypes.AuthConfig) (remotes.Resolver, docker.StatusTracker) {
func (i *ImageService) newResolverFromAuthConfig(ctx context.Context, authConfig *registrytypes.AuthConfig, ref reference.Named) (remotes.Resolver, docker.StatusTracker) {
tracker := docker.NewInMemoryTracker()

hosts := hostsWrapper(i.registryHosts, authConfig, i.registryService)
hosts := hostsWrapper(i.registryHosts, authConfig, ref, i.registryService)
headers := http.Header{}
headers.Set("User-Agent", dockerversion.DockerUserAgent(ctx, useragent.VersionInfo{Name: "containerd-client", Version: version.Version}, useragent.VersionInfo{Name: "storage-driver", Version: i.snapshotter}))

Expand All @@ -31,10 +32,10 @@ func (i *ImageService) newResolverFromAuthConfig(ctx context.Context, authConfig
}), tracker
}

func hostsWrapper(hostsFn docker.RegistryHosts, optAuthConfig *registrytypes.AuthConfig, regService registryResolver) docker.RegistryHosts {
func hostsWrapper(hostsFn docker.RegistryHosts, optAuthConfig *registrytypes.AuthConfig, ref reference.Named, regService registryResolver) docker.RegistryHosts {
var authorizer docker.Authorizer
if optAuthConfig != nil {
authorizer = authorizerFromAuthConfig(*optAuthConfig)
authorizer = authorizerFromAuthConfig(*optAuthConfig, ref)
}

return func(n string) ([]docker.RegistryHost, error) {
Expand All @@ -56,9 +57,12 @@ func hostsWrapper(hostsFn docker.RegistryHosts, optAuthConfig *registrytypes.Aut
}
}

func authorizerFromAuthConfig(authConfig registrytypes.AuthConfig) docker.Authorizer {
func authorizerFromAuthConfig(authConfig registrytypes.AuthConfig, ref reference.Named) docker.Authorizer {
cfgHost := registry.ConvertToHostname(authConfig.ServerAddress)
if cfgHost == "" || cfgHost == registry.IndexHostname {
if cfgHost == "" {
cfgHost = reference.Domain(ref)
}
if cfgHost == registry.IndexHostname || cfgHost == registry.IndexName {
cfgHost = registry.DefaultRegistryHost
}

Expand Down

0 comments on commit c14694a

Please sign in to comment.