From b5209dba643343538924d1603958c24b8887a3db Mon Sep 17 00:00:00 2001 From: Claudiu Dragalina-Paraipan Date: Wed, 16 Oct 2024 18:03:06 +0300 Subject: [PATCH] Update pkg/services/authn/grpcutils/grpc_authenticator.go Co-authored-by: Gabriel MABILLE --- pkg/services/authn/grpcutils/grpc_authenticator.go | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/pkg/services/authn/grpcutils/grpc_authenticator.go b/pkg/services/authn/grpcutils/grpc_authenticator.go index b5b56ac27c6..db5b47e8b2b 100644 --- a/pkg/services/authn/grpcutils/grpc_authenticator.go +++ b/pkg/services/authn/grpcutils/grpc_authenticator.go @@ -93,18 +93,14 @@ func NewGrpcAuthenticatorWithFallback(cfg *setting.Cfg, reg prometheus.Registere } func (f *AuthenticatorWithFallback) Authenticate(ctx context.Context) (context.Context, error) { - origCtx := ctx // Try to authenticate with the new authenticator first - ctx, err := f.authenticator.Authenticate(ctx) - if err == nil { - // If successful, return the context - return ctx, nil - } else if f.fallbackEnabled { - // If the new authenticator failed and the fallback is enabled, try the legacy authenticator - ctx, err = f.legacyAuthenticator.Authenticate(origCtx) + newCtx, err := f.authenticator.Authenticate(ctx) + // If allowed fallback to the legacy authenticator + if err != nil && f.fallbackEnabled { + newCtx, err = f.legacyAuthenticator.Authenticate(ctx) f.metrics.fallbackCounter.WithLabelValues(fmt.Sprintf("%t", err == nil)).Inc() } - return ctx, err + return newCtx, err } const (