Skip to content

Commit 8082e76

Browse files
committed
[image-builder-mk3] log errors for auth
This will help us troubleshoot: * credential reload via watch * potential ECR authN issues * potential additionalAuth issues
1 parent 5791909 commit 8082e76

File tree

1 file changed

+8
-0
lines changed
  • components/image-builder-mk3/pkg/auth

1 file changed

+8
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,13 @@ func (a *DockerConfigFileAuth) loadFromFile(fn string) (err error) {
6464
defer func() {
6565
if err != nil {
6666
err = fmt.Errorf("error loading Docker config from %s: %w", fn, err)
67+
log.WithError(err).Errorf("Failed loading from file: %s", fn)
6768
}
6869
}()
6970

7071
cntnt, err := os.ReadFile(fn)
7172
if err != nil {
73+
log.WithError(err).Errorf("Failed reading file: %s", fn)
7274
return err
7375
}
7476
hash := sha256.New()
@@ -83,6 +85,7 @@ func (a *DockerConfigFileAuth) loadFromFile(fn string) (err error) {
8385
cfg := configfile.New(fn)
8486
err = cfg.LoadFromReader(bytes.NewReader(cntnt))
8587
if err != nil {
88+
log.WithError(err).Errorf("Read file failed: %s", fn)
8689
return err
8790
}
8891

@@ -159,6 +162,7 @@ func (ath *ECRAuthenticator) Authenticate(ctx context.Context, registry string)
159162
if time.Since(ath.ecrAuthLastRefreshTime) > ecrTokenRefreshTime {
160163
tknout, err := ath.ecrc.GetAuthorizationToken(ctx, &ecr.GetAuthorizationTokenInput{})
161164
if err != nil {
165+
log.WithError(err).Errorf("Failed getting auth token")
162166
return nil, err
163167
}
164168
if len(tknout.AuthorizationData) == 0 {
@@ -167,6 +171,7 @@ func (ath *ECRAuthenticator) Authenticate(ctx context.Context, registry string)
167171

168172
pwd, err := base64.StdEncoding.DecodeString(aws.ToString(tknout.AuthorizationData[0].AuthorizationToken))
169173
if err != nil {
174+
log.WithError(err).Errorf("Failed decoding token")
170175
return nil, err
171176
}
172177

@@ -299,6 +304,7 @@ func (a AllowedAuthFor) GetAuthFor(ctx context.Context, auth RegistryAuthenticat
299304

300305
ref, err := reference.ParseNormalizedNamed(refstr)
301306
if err != nil {
307+
log.WithError(err).Errorf("Failed parsing normalized name")
302308
return nil, xerrors.Errorf("cannot parse image ref: %v", err)
303309
}
304310
reg := reference.Domain(ref)
@@ -359,6 +365,8 @@ func (a AllowedAuthFor) additionalAuth(domain string) *Authentication {
359365
res.Username = segs[0]
360366
res.Password = strings.Join(segs[1:], ":")
361367
}
368+
} else {
369+
log.WithError(err).Errorf("Failed getting additional auth")
362370
}
363371
return res
364372
}

0 commit comments

Comments
 (0)