goharbor/harbor · error

failed to search user in ldap

Error message

failed to search user in ldap

What it means

SearchUser discards the underlying cause and returns this fixed error when s.SearchUser(username) fails against the LDAP directory — a generic mask for any LDAP search failure (timeout, bad filter, connection drop).

Solutions

  1. Check LDAP server logs and connectivity for the real cause
  2. Verify the search filter/base DN configuration
  3. Retry the search once LDAP is responsive
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at src/core/auth/ldap/ldap.go:252 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of goharbor/harbor@7b2fd08cc5 (2026-08-16). Data as JSON: /api/errors/804352ba7b4b230c. Report an issue: GitHub.

Appendix: source

Thrown at src/core/auth/ldap/ldap.go:252

	u.Comment = "from LDAP."   // Source is from LDAP

	return l.userMgr.Onboard(ctx, u)
}

// SearchUser -- Search user in ldap
func (l *Auth) SearchUser(ctx context.Context, username string) (*models.User, error) {
	var user models.User
	s, err := ldapCtl.Ctl.Session(ctx)
	if err != nil {
		return nil, err
	}
	if err = s.Open(); err != nil {
		return nil, fmt.Errorf("failed to load system ldap config, %v", err)
	}
	defer s.Close()
	lUsers, err := s.SearchUser(username)
	if err != nil {
		return nil, fmt.Errorf("failed to search user in ldap")
	}

	if len(lUsers) > 1 {
		log.Warningf("There are more than one user found, return the first user")
	}
	if len(lUsers) > 0 {
		user.Username = strings.TrimSpace(lUsers[0].Username)
		user.Realname = strings.TrimSpace(lUsers[0].Realname)
		user.Email = strings.TrimSpace(lUsers[0].Email)

		log.Debugf("Found ldap user %v", user)
	} else {
		return nil, errors.NotFoundError(nil).WithMessagef("no user found: %v", username)
	}

	return &user, nil
}

View on GitHub (pinned to 7b2fd08cc5)