@@ -45,7 +45,8 @@ type repoImage struct {
4545
4646// sourceRegistry will be either Staging Registry or Docker Hub
4747type sourceRegistry struct {
48- ociOpts []ociremote.Option
48+ dockerOpts []ociremote.Option
49+ stagingOpts []ociremote.Option
4950}
5051
5152type primeRegistry struct {
@@ -68,8 +69,8 @@ type tagMap func(name.Reference, ...ociremote.Option) (name.Tag, error)
6869//
6970// There is only one destination:
7071// - Prime Registry
71- func Sync (ctx context.Context , primeUser , primePass , primeURL , dockerUser , dockerPass string ) error {
72- s , err := prepareSync (ctx , primeUser , primePass , dockerUser , dockerPass )
72+ func Sync (ctx context.Context , primeUser , primePass , primeURL , dockerUser , dockerPass , stagingUser , stagingPass string ) error {
73+ s , err := prepareSync (ctx , primeUser , primePass , dockerUser , dockerPass , stagingUser , stagingPass )
7374 if err != nil {
7475 return err
7576 }
@@ -131,7 +132,7 @@ func Sync(ctx context.Context, primeUser, primePass, primeURL, dockerUser, docke
131132
132133// prepareSync checks if the prime credentials are provided and creates the synchronizer
133134// with all the oci,naming and remote options needed.
134- func prepareSync (ctx context.Context , primeUser , primePass , dockerUser , dockerPass string ) (* synchronizer , error ) {
135+ func prepareSync (ctx context.Context , primeUser , primePass , dockerUser , dockerPass , stagingUser , staginPass string ) (* synchronizer , error ) {
135136 // Use strict validation for pulling and pushing
136137 // These options control how image references (e.g., "myregistry/myimage:tag")
137138 // are parsed and validated by go-containerregistry's 'name' package.
@@ -151,29 +152,43 @@ func prepareSync(ctx context.Context, primeUser, primePass, dockerUser, dockerPa
151152
152153 // applied to the puller and subsequently used by cosign's oci/remote
153154 // package when fetching signed entities.
154- clientOpts := []remote.Option {
155+ dockerClientOpts := []remote.Option {
155156 remote .WithContext (ctx ),
156157 remote .WithUserAgent (uaString ),
157158 remote .WithAuth (& authn.Basic {Username : dockerUser , Password : dockerPass }),
158159 remote .WithTransport (tr ),
159160 }
161+ stagingClientOpts := []remote.Option {
162+ remote .WithContext (ctx ),
163+ remote .WithUserAgent (uaString ),
164+ remote .WithAuth (& authn.Basic {Username : stagingUser , Password : staginPass }),
165+ remote .WithTransport (tr ),
166+ }
160167
161168 // reuse new remote puller for efficiency across operations.
162169 // puller interacts only with docker.io and staging registry.
163- puller , err := remote .NewPuller (clientOpts ... )
170+ dockerPuller , err := remote .NewPuller (dockerClientOpts ... )
164171 if err == nil {
165- clientOpts = append (clientOpts , remote .Reuse (puller ))
172+ dockerClientOpts = append (dockerClientOpts , remote .Reuse (dockerPuller ))
173+ }
174+ stagingPuller , err := remote .NewPuller (stagingClientOpts ... )
175+ if err == nil {
176+ stagingClientOpts = append (stagingClientOpts , remote .Reuse (stagingPuller ))
166177 }
167178
168179 // These options are specifically for cosign's 'pkg/oci/remote' functions
169180 // (e.g., ociremote.SignedEntity, ociremote.SignatureTag). They bridge the
170181 // 'go-containerregistry' remote options to cosign's operations.
171- pullerOpts := []ociremote.Option {
182+ dockerPullerOpts := []ociremote.Option {
183+ ociremote .WithNameOptions (nameOpts ... ),
184+ }
185+ stagingPullerOpts := []ociremote.Option {
172186 ociremote .WithNameOptions (nameOpts ... ),
173187 }
174188 // Embed the 'go-containerregistry' remote options
175189 // (context, user agent, keychain auth, insecure transport) into cosign's client setup.
176- pullerOpts = append (pullerOpts , ociremote .WithRemoteOptions (clientOpts ... ))
190+ dockerPullerOpts = append (dockerPullerOpts , ociremote .WithRemoteOptions (dockerClientOpts ... ))
191+ stagingPullerOpts = append (stagingPullerOpts , ociremote .WithRemoteOptions (stagingClientOpts ... ))
177192
178193 // prime (destination) registry. They use explicit basic authentication?
179194 remoteOpts := []remote.Option {
@@ -190,7 +205,8 @@ func prepareSync(ctx context.Context, primeUser, primePass, dockerUser, dockerPa
190205 return & synchronizer {
191206 nameOpts : nameOpts ,
192207 sourceRegistry : & sourceRegistry {
193- ociOpts : pullerOpts ,
208+ dockerOpts : dockerPullerOpts ,
209+ stagingOpts : stagingPullerOpts ,
194210 },
195211 primeRegistry : & primeRegistry {
196212 pusher : pusher ,
@@ -262,7 +278,7 @@ func (s *synchronizer) pullFromDocker(ctx context.Context, imgRepo string) error
262278 // Get the base repository reference for the source image.
263279 srcRepoRef := s .repoImage .srcRef .Context ()
264280
265- root , err := ociremote .SignedEntity (s .repoImage .srcRef , s .sourceRegistry .ociOpts ... )
281+ root , err := ociremote .SignedEntity (s .repoImage .srcRef , s .sourceRegistry .dockerOpts ... )
266282 if err != nil {
267283 logger .Log (ctx , slog .LevelError , "signedEntity failure" , logger .Err (err ))
268284 return err
@@ -318,7 +334,7 @@ func (s *synchronizer) pullFromStaging(ctx context.Context, imgRepo string) erro
318334 dstRepoRef := s .repoImage .dstRef .Context ()
319335
320336 // An oci.SignedEntity represents the image manifest itself AND all its associated
321- root , err := ociremote .SignedEntity (s .repoImage .srcRef , s .sourceRegistry .ociOpts ... )
337+ root , err := ociremote .SignedEntity (s .repoImage .srcRef , s .sourceRegistry .stagingOpts ... )
322338 if err != nil {
323339 logger .Log (ctx , slog .LevelError , "signedEntity failure" , logger .Err (err ))
324340 return err
@@ -337,7 +353,7 @@ func (s *synchronizer) pullFromStaging(ctx context.Context, imgRepo string) erro
337353 copyTag := func (tm tagMap ) error {
338354 // Construct the *expected name* (e.g., "myimage:sha256-digest.sig")
339355 // for the artifact based on its digest. This call does NOT confirm existence yet.
340- src , err := tm (srcDigest , s .sourceRegistry .ociOpts ... )
356+ src , err := tm (srcDigest , s .sourceRegistry .stagingOpts ... )
341357 if err != nil {
342358 return err
343359 }
0 commit comments