go-containerregistry icon indicating copy to clipboard operation
go-containerregistry copied to clipboard

ggcr: unable to reuse authenticated transport with v1/remote

Open benmoss opened this issue 2 years ago • 6 comments

Describe the bug

I'd like to initialize an http.RoundTripper after doing an auth handshake and then use it to perform several requests to a repository. Right now the v1/remote functions all create a new http.RoundTripper via transport.NewWithContext, even if you pass one to the method via the option.WithTransport call.

To Reproduce

I made this sample app to demonstrate the problem: https://gist.github.com/benmoss/620ec0b372be90c2471fdff3d80564fb

With the debug logs enabled you can see several calls to GET https://gcr.io/v2/, which should be unnecessary since we already know it allows anonymous access.

Expected behavior

It should skip the extraneous /v2 pings

Additional context

I was thinking maybe it would make sense for registry to do some type check on the transport, similar to how we do a check for a transport.Wrapper right now to skip some wrapping, but in this case for authentication. Maybe the user can just pass a transport.Wrapper and that will be used? I'm not sure why not other than its a change in the contract.

Support for using the same transport to talk to multiple registries would also get more complicated, but this is similar to remote.MultiWrite

benmoss avatar Apr 08 '22 16:04 benmoss