Skip to content

Commit c4a9c39

Browse files
committed
authprovider: add OTEL spans for loading credentials
Credential loading could take long depending on credentials storage. Signed-off-by: Tonis Tiigi <[email protected]>
1 parent a6e85c7 commit c4a9c39

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

session/auth/authprovider/authprovider.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (ap *authProvider) Register(server *grpc.Server) {
7474
}
7575

7676
func (ap *authProvider) FetchToken(ctx context.Context, req *auth.FetchTokenRequest) (rr *auth.FetchTokenResponse, err error) {
77-
ac, err := ap.getAuthConfig(req.Host)
77+
ac, err := ap.getAuthConfig(ctx, req.Host)
7878
if err != nil {
7979
return nil, err
8080
}
@@ -84,7 +84,7 @@ func (ap *authProvider) FetchToken(ctx context.Context, req *auth.FetchTokenRequ
8484
return toTokenResponse(ac.RegistryToken, time.Time{}, 0), nil
8585
}
8686

87-
creds, err := ap.credentials(req.Host)
87+
creds, err := ap.credentials(ctx, req.Host)
8888
if err != nil {
8989
return nil, err
9090
}
@@ -187,8 +187,8 @@ func (ap *authProvider) tlsConfig(host string) (*tls.Config, error) {
187187
return tc, nil
188188
}
189189

190-
func (ap *authProvider) credentials(host string) (*auth.CredentialsResponse, error) {
191-
ac, err := ap.getAuthConfig(host)
190+
func (ap *authProvider) credentials(ctx context.Context, host string) (*auth.CredentialsResponse, error) {
191+
ac, err := ap.getAuthConfig(ctx, host)
192192
if err != nil {
193193
return nil, err
194194
}
@@ -203,7 +203,7 @@ func (ap *authProvider) credentials(host string) (*auth.CredentialsResponse, err
203203
}
204204

205205
func (ap *authProvider) Credentials(ctx context.Context, req *auth.CredentialsRequest) (*auth.CredentialsResponse, error) {
206-
resp, err := ap.credentials(req.Host)
206+
resp, err := ap.credentials(ctx, req.Host)
207207
if err != nil || resp.Secret != "" {
208208
ap.mu.Lock()
209209
defer ap.mu.Unlock()
@@ -219,7 +219,7 @@ func (ap *authProvider) Credentials(ctx context.Context, req *auth.CredentialsRe
219219
}
220220

221221
func (ap *authProvider) GetTokenAuthority(ctx context.Context, req *auth.GetTokenAuthorityRequest) (*auth.GetTokenAuthorityResponse, error) {
222-
key, err := ap.getAuthorityKey(req.Host, req.Salt)
222+
key, err := ap.getAuthorityKey(ctx, req.Host, req.Salt)
223223
if err != nil {
224224
return nil, err
225225
}
@@ -228,7 +228,7 @@ func (ap *authProvider) GetTokenAuthority(ctx context.Context, req *auth.GetToke
228228
}
229229

230230
func (ap *authProvider) VerifyTokenAuthority(ctx context.Context, req *auth.VerifyTokenAuthorityRequest) (*auth.VerifyTokenAuthorityResponse, error) {
231-
key, err := ap.getAuthorityKey(req.Host, req.Salt)
231+
key, err := ap.getAuthorityKey(ctx, req.Host, req.Salt)
232232
if err != nil {
233233
return nil, err
234234
}
@@ -239,7 +239,7 @@ func (ap *authProvider) VerifyTokenAuthority(ctx context.Context, req *auth.Veri
239239
return &auth.VerifyTokenAuthorityResponse{Signed: sign.Sign(nil, req.Payload, priv)}, nil
240240
}
241241

242-
func (ap *authProvider) getAuthConfig(host string) (*types.AuthConfig, error) {
242+
func (ap *authProvider) getAuthConfig(ctx context.Context, host string) (*types.AuthConfig, error) {
243243
ap.mu.Lock()
244244
defer ap.mu.Unlock()
245245

@@ -248,7 +248,9 @@ func (ap *authProvider) getAuthConfig(host string) (*types.AuthConfig, error) {
248248
}
249249

250250
if _, exists := ap.authConfigCache[host]; !exists {
251+
span, _ := tracing.StartSpan(ctx, fmt.Sprintf("load credentials for %s", host))
251252
ac, err := ap.config.GetAuthConfig(host)
253+
tracing.FinishWithError(span, err)
252254
if err != nil {
253255
return nil, err
254256
}
@@ -258,12 +260,12 @@ func (ap *authProvider) getAuthConfig(host string) (*types.AuthConfig, error) {
258260
return ap.authConfigCache[host], nil
259261
}
260262

261-
func (ap *authProvider) getAuthorityKey(host string, salt []byte) (ed25519.PrivateKey, error) {
263+
func (ap *authProvider) getAuthorityKey(ctx context.Context, host string, salt []byte) (ed25519.PrivateKey, error) {
262264
if v, err := strconv.ParseBool(os.Getenv("BUILDKIT_NO_CLIENT_TOKEN")); err == nil && v {
263265
return nil, status.Errorf(codes.Unavailable, "client side tokens disabled")
264266
}
265267

266-
creds, err := ap.credentials(host)
268+
creds, err := ap.credentials(ctx, host)
267269
if err != nil {
268270
return nil, err
269271
}

0 commit comments

Comments
 (0)