Skip to content

Commit 3dc5b4a

Browse files
authored
Add baseref as additional image build auth (#18510)
1 parent 4e87092 commit 3dc5b4a

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

components/image-builder-mk3/pkg/auth/auth.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ func (a AllowedAuthFor) additionalAuth(domain string) *Authentication {
367367
type ImageBuildAuth map[string]types.AuthConfig
368368

369369
// GetImageBuildAuthFor produces authentication in the format an image builds needs
370-
func (a AllowedAuthFor) GetImageBuildAuthFor(blocklist []string) (res ImageBuildAuth) {
370+
func (a AllowedAuthFor) GetImageBuildAuthFor(ctx context.Context, auth RegistryAuthenticator, additionalRegistries []string, blocklist []string) (res ImageBuildAuth) {
371371
res = make(ImageBuildAuth)
372372
for reg := range a.Additional {
373373
var blocked bool
@@ -383,6 +383,17 @@ func (a AllowedAuthFor) GetImageBuildAuthFor(blocklist []string) (res ImageBuild
383383
ath := a.additionalAuth(reg)
384384
res[reg] = types.AuthConfig(*ath)
385385
}
386+
for _, reg := range additionalRegistries {
387+
ath, err := auth.Authenticate(ctx, reg)
388+
if err != nil {
389+
log.WithError(err).WithField("registry", reg).Warn("cannot get authentication for additioanl registry for image build")
390+
continue
391+
}
392+
if ath.Empty() {
393+
continue
394+
}
395+
res[reg] = types.AuthConfig(*ath)
396+
}
386397

387398
return
388399
}

components/image-builder-mk3/pkg/orchestrator/orchestrator.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ func (o *Orchestrator) Build(req *protocol.BuildRequest, resp protocol.ImageBuil
323323
return false
324324
}
325325

326-
pbaseref, err := reference.Parse(baseref)
326+
pbaseref, err := reference.ParseNormalizedNamed(baseref)
327327
if err != nil {
328328
return xerrors.Errorf("cannot parse baseref: %v", err)
329329
}
@@ -336,9 +336,10 @@ func (o *Orchestrator) Build(req *protocol.BuildRequest, resp protocol.ImageBuil
336336
wsref, err := reference.ParseNamed(wsrefstr)
337337
var additionalAuth []byte
338338
if err == nil {
339-
additionalAuth, err = json.Marshal(reqauth.GetImageBuildAuthFor([]string{
339+
ath := reqauth.GetImageBuildAuthFor(ctx, o.Auth, []string{reference.Domain(pbaseref)}, []string{
340340
reference.Domain(wsref),
341-
}))
341+
})
342+
additionalAuth, err = json.Marshal(ath)
342343
if err != nil {
343344
return xerrors.Errorf("cannot marshal additional auth: %w", err)
344345
}

0 commit comments

Comments
 (0)