[release-12.2.1] Backport 112615 to release 12.2.1 (#112636)
Update validation of non-provisioned users rejection (#112615)
* Update validation of non-provisioned users rejection
* Align tests
(cherry picked from commit 0e4237b775)
This commit is contained in:
@@ -186,6 +186,13 @@ func (s *UserSync) ValidateUserProvisioningHook(ctx context.Context, currentIden
|
||||
return nil
|
||||
}
|
||||
|
||||
effectiveReject := s.shouldRejectNonProvisionedUsers(ctx, currentIdentity)
|
||||
|
||||
if !effectiveReject {
|
||||
log.Debug("Skip provisioning validation, non-provisioned users are allowed")
|
||||
return nil
|
||||
}
|
||||
|
||||
log.Debug("Validating user provisioning")
|
||||
ctx, span := s.tracer.Start(ctx, "user.sync.ValidateUserProvisioningHook")
|
||||
defer span.End()
|
||||
@@ -225,7 +232,7 @@ func (s *UserSync) ValidateUserProvisioningHook(ctx context.Context, currentIden
|
||||
}
|
||||
|
||||
// Reject non-provisioned users if configured to do so
|
||||
if s.shouldRejectNonProvisionedUsers(ctx, currentIdentity) {
|
||||
if effectiveReject {
|
||||
log.Error("Failed to authenticate user, user is not provisioned")
|
||||
return errUserNotProvisioned.Errorf("user is not provisioned")
|
||||
}
|
||||
@@ -500,8 +507,11 @@ func (s *UserSync) updateUserAttributes(ctx context.Context, usr *user.User, id
|
||||
attribute.String("identity.ID", id.ID),
|
||||
attribute.String("identity.ExternalUID", id.ExternalUID),
|
||||
)
|
||||
if usr.IsProvisioned {
|
||||
s.log.Debug("User is provisioned", "id.UID", id.UID)
|
||||
|
||||
ctxLogger := s.log.FromContext(ctx)
|
||||
|
||||
if s.shouldRejectNonProvisionedUsers(ctx, id) && usr.IsProvisioned && id.AuthenticatedBy != login.GrafanaComAuthModule {
|
||||
ctxLogger.Debug("User is provisioned", "id.UID", id.UID)
|
||||
needsConnectionCreation = false
|
||||
authInfo, err := s.authInfoService.GetAuthInfo(ctx, &login.GetAuthInfoQuery{UserId: usr.ID, AuthModule: id.AuthenticatedBy})
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user