Skip to content

Fix support for RegistryToken #3209

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed

Conversation

sztwiorok
Copy link

This Fix is related to issue #2749
I have tested this change and confirmed it resolves the issue

Signed-off-by: Rafal Sztwiorok <rafal.sztwiorok@gmail.com>
@crazy-max
Copy link
Member

That looks fine to support a statically configured bearer token. I was wondering how this relates to #2749 but we are using the imagetools package to merge manifests during build:

buildx/build/build.go

Lines 631 to 690 in e3c6618

if len(descs) > 0 {
var imageopt imagetools.Opt
for _, dp := range dps {
imageopt = dp.Node().ImageOpt
break
}
names := strings.Split(pushNames, ",")
if insecurePush {
insecureTrue := true
httpTrue := true
nn, err := reference.ParseNormalizedNamed(names[0])
if err != nil {
return err
}
imageopt.RegistryConfig = map[string]resolver.RegistryConfig{
reference.Domain(nn): {
Insecure: &insecureTrue,
PlainHTTP: &httpTrue,
},
}
}
itpull := imagetools.New(imageopt)
ref, err := reference.ParseNormalizedNamed(names[0])
if err != nil {
return err
}
ref = reference.TagNameOnly(ref)
srcs := make([]*imagetools.Source, len(descs))
for i, desc := range descs {
srcs[i] = &imagetools.Source{
Desc: desc,
Ref: ref,
}
}
indexAnnotations, err := extractIndexAnnotations(opt.Exports)
if err != nil {
return err
}
dt, desc, err := itpull.Combine(ctx, srcs, indexAnnotations, false)
if err != nil {
return err
}
itpush := imagetools.New(imageopt)
for _, n := range names {
nn, err := reference.ParseNormalizedNamed(n)
if err != nil {
return err
}
if err := itpush.Push(ctx, nn, desc, dt); err != nil {
return err
}
}

I just don't see in repro from #2749 this happening during merge manifests. Can you show logs from your repro if possible?

Copy link
Member

@tonistiigi tonistiigi left a comment

Choose a reason for hiding this comment

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

I don't think this is correct. iiuc RegistryToken means the token sent directly to registry, so if it would be supported then it would be used in the implementation of FetchToken. As these tokens would already be specific to repository and scope (for oauth) then it is unlikely that they would be very useful for build as builder pulls lots of images and would need separate tokens for different images and separate tokens for pull and push. If the current PR works for you then you should be defining your token as IdentityToken instead of RegistryToken.

@tonistiigi
Copy link
Member

Looking at it more, we do seem to support RegistryToken in buildkit side https://github.com/moby/buildkit/blob/master/session/auth/authprovider/authprovider.go#L109-L112 inside FetchToken as I suggested. But in here (imagetools) we use containerd authorizer directly and that doesn't seem to have support for it afaics. https://github.com/moby/buildkit/blob/master/session/auth/authprovider/authprovider.go#L109-L112 . If you do need RegistryToken and not IdentityToken then looks like https://github.com/containerd/containerd/blob/main/core/remotes/docker/authorizer.go#L277 needs to have a way to return that token directly without trying to fetch it.

@tonistiigi
Copy link
Member

Look at this wrapper implementation https://github.com/moby/moby/blob/master/daemon/containerd/resolver.go#L62 . We can do smth similar for imagetools.

Copy link
Member

@tonistiigi tonistiigi left a comment

Choose a reason for hiding this comment

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

^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants