snipe-it icon indicating copy to clipboard operation
snipe-it copied to clipboard

Locations LDAP Search OU

Open mikem011 opened this issue 7 years ago • 10 comments

Expected Behavior (or desired behavior if a feature request)

I am setting the LDAP Search OU field for the location to the distinguished name of the Active Directory OU I want to sync to the location (ex. OU=Staff, OU=Location1, OU=Users, OU=Accounts, DC=domain, DC=com). The base dn for the LDAP/AD Settings is set to OU=Users, OU=Accounts, DC=domain, DC=com. I expect that based on the base dn and the search OU only the users located in the search OU will be synced to the location.


Actual Behavior

I receive a "Whoops, looks like something went wrong" error with the following debug information.

(1/1) ErrorExceptionldap_search(): Search: Operations error

in Ldap.php line 265 at HandleExceptions->handleError(2, 'ldap_search(): Search: Operations error', '/var/www/html/app/Models/Ldap.php', 265, array('base_dn' => 'ou=Staff', 'ldapconn' => resource, 'ldap_bind' => null, 'filter' => '&(samaccounttype=805306368)(!(useraccountcontrol:1.2.840.113556.1.4.803:=2))(department=)', 'page_size' => 500, 'cookie' => '', 'result_set' => array(), 'global_count' => 0, 'ldap_paging' => true)) at ldap_search(resource, 'ou=Staff', '(&(samaccounttype=805306368)(!(useraccountcontrol:1.2.840.113556.1.4.803:=2))(department=))')in Ldap.php line 265 at Ldap::findLdapUsers('ou=Staff')in LdapSync.php line 128 at LdapSync->handle() at call_user_func_array(array(object(LdapSync), 'handle'), array())in BoundMethod.php line 29 at BoundMethod::Illuminate\Container{closure}()in BoundMethod.php line 87 at BoundMethod::callBoundMethod(object(Application), array(object(LdapSync), 'handle'), object(Closure))in BoundMethod.php line 31 at BoundMethod::call(object(Application), array(object(LdapSync), 'handle'), array(), null)in Container.php line 539 at Container->call(array(object(LdapSync), 'handle'))in Command.php line 182 at Command->execute(object(ArrayInput), object(OutputStyle))in Command.php line 255 at Command->run(object(ArrayInput), object(OutputStyle))in Command.php line 167 at Command->run(object(ArrayInput), object(BufferedOutput))in Application.php line 960 at Application->doRunCommand(object(LdapSync), object(ArrayInput), object(BufferedOutput))in Application.php line 255 at Application->doRun(object(ArrayInput), object(BufferedOutput))in Application.php line 148 at Application->run(object(ArrayInput), object(BufferedOutput))in Application.php line 141 at Application->call('snipeit:ldap-sync', object(Collection), null)in Kernel.php line 220 at Kernel->call('snipeit:ldap-sync', array('--location_id' => '3', '--json_summary' => true))in Facade.php line 221 at Facade::__callStatic('call', array('snipeit:ldap-sync', array('--location_id' => '3', '--json_summary' => true)))in UsersController.php line 874 at UsersController->postLDAP(object(Request)) at call_user_func_array(array(object(UsersController), 'postLDAP'), array(object(Request)))in Controller.php line 55 at Controller->callAction('postLDAP', array(object(Request)))in ControllerDispatcher.php line 44 at ControllerDispatcher->dispatch(object(Route), object(UsersController), 'postLDAP')in Route.php line 203 at Route->runController()in Route.php line 160 at Route->run()in Router.php line 572 at Router->Illuminate\Routing{closure}(object(Request))in Pipeline.php line 30 at Pipeline->Illuminate\Routing{closure}(object(Request))in Authenticate.php line 43 at Authenticate->handle(object(Request), object(Closure))in Pipeline.php line 148 at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53 at Pipeline->Illuminate\Routing{closure}(object(Request))in CreateFreshApiToken.php line 49 at CreateFreshApiToken->handle(object(Request), object(Closure))in Pipeline.php line 148 at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53 at Pipeline->Illuminate\Routing{closure}(object(Request))in CheckForTwoFactor.php line 49 at CheckForTwoFactor->handle(object(Request), object(Closure))in Pipeline.php line 148 at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53 at Pipeline->Illuminate\Routing{closure}(object(Request))in CheckLocale.php line 42 at CheckLocale->handle(object(Request), object(Closure))in Pipeline.php line 148 at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53 at Pipeline->Illuminate\Routing{closure}(object(Request))in VerifyCsrfToken.php line 65 at VerifyCsrfToken->handle(object(Request), object(Closure))in Pipeline.php line 148 at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53 at Pipeline->Illuminate\Routing{closure}(object(Request))in AddQueuedCookiesToResponse.php line 37 at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))in Pipeline.php line 148 at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53 at Pipeline->Illuminate\Routing{closure}(object(Request))in EncryptCookies.php line 59 at EncryptCookies->handle(object(Request), object(Closure))in Pipeline.php line 148 at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53 at Pipeline->Illuminate\Routing{closure}(object(Request))in Pipeline.php line 102 at Pipeline->then(object(Closure))in Router.php line 574 at Router->runRouteWithinStack(object(Route), object(Request))in Router.php line 533 at Router->dispatchToRoute(object(Request))in Router.php line 511 at Router->dispatch(object(Request))in Kernel.php line 176 at Kernel->Illuminate\Foundation\Http{closure}(object(Request))in Pipeline.php line 30 at Pipeline->Illuminate\Routing{closure}(object(Request))in Debugbar.php line 51 at Debugbar->handle(object(Request), object(Closure))in Pipeline.php line 148 at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53 at Pipeline->Illuminate\Routing{closure}(object(Request))in TransformsRequest.php line 30 at TransformsRequest->handle(object(Request), object(Closure))in Pipeline.php line 148 at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53 at Pipeline->Illuminate\Routing{closure}(object(Request))in CheckForDebug.php line 25 at CheckForDebug->handle(object(Request), object(Closure))in Pipeline.php line 148 at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53 at Pipeline->Illuminate\Routing{closure}(object(Request))in CheckForSetup.php line 27 at CheckForSetup->handle(object(Request), object(Closure))in Pipeline.php line 148 at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53 at Pipeline->Illuminate\Routing{closure}(object(Request))in TrustProxies.php line 56 at TrustProxies->handle(object(Request), object(Closure))in Pipeline.php line 148 at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53 at Pipeline->Illuminate\Routing{closure}(object(Request))in NosniffGuard.php line 17 at NosniffGuard->handle(object(Request), object(Closure))in Pipeline.php line 148 at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53 at Pipeline->Illuminate\Routing{closure}(object(Request))in ContentSecurityPolicyHeader.php line 18 at ContentSecurityPolicyHeader->handle(object(Request), object(Closure))in Pipeline.php line 148 at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53 at Pipeline->Illuminate\Routing{closure}(object(Request))in ReferrerPolicyHeader.php line 17 at ReferrerPolicyHeader->handle(object(Request), object(Closure))in Pipeline.php line 148 at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53 at Pipeline->Illuminate\Routing{closure}(object(Request))in XssProtectHeader.php line 18 at XssProtectHeader->handle(object(Request), object(Closure))in Pipeline.php line 148 at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53 at Pipeline->Illuminate\Routing{closure}(object(Request))in FrameGuard.php line 17 at FrameGuard->handle(object(Request), object(Closure))in Pipeline.php line 148 at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53 at Pipeline->Illuminate\Routing{closure}(object(Request))in ShareErrorsFromSession.php line 49 at ShareErrorsFromSession->handle(object(Request), object(Closure))in Pipeline.php line 148 at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53 at Pipeline->Illuminate\Routing{closure}(object(Request))in StartSession.php line 64 at StartSession->handle(object(Request), object(Closure))in Pipeline.php line 148 at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53 at Pipeline->Illuminate\Routing{closure}(object(Request))in CheckForMaintenanceMode.php line 46 at CheckForMaintenanceMode->handle(object(Request), object(Closure))in Pipeline.php line 148 at Pipeline->Illuminate\Pipeline{closure}(object(Request))in Pipeline.php line 53 at Pipeline->Illuminate\Routing{closure}(object(Request))in Pipeline.php line 102 at Pipeline->then(object(Closure))in Kernel.php line 151 at Kernel->sendRequestThroughRouter(object(Request))in Kernel.php line 116 at Kernel->handle(object(Request))in index.php line 58

Please confirm you have done the following before posting your bug report:


Provide answers to these questions:

  • Is this a fresh install or an upgrade?
    Fresh Install
  • Version of Snipe-IT you're running v4.6.15 build 4011
  • Version of PHP you're running v7.0.33
  • Version of MySQL/MariaDB you're running v5.0.12
  • What OS and web server you're running Snipe-IT on Ubuntu 16.0.4, Apache
  • What method you used to install Snipe-IT (install.sh, manual installation, docker, etc) Docker
  • WITH DEBUG TURNED ON, if you're getting an error in your browser, include that error See above for error
  • What specific Snipe-IT page you're on, and what specific element you're interacting with to trigger the error LDAP User Sync page, when clicking the Synchronize button
  • If a stacktrace is provided in the error, include that too. See above
  • Any errors that appear in your browser's error console. See Above
  • Confirm whether the error is reproducible on the demo: https://snipeitapp.com/demo. I could not test on the demo site. I do not have a public facing LDAP server to use
  • Include any additional information you can find in storage/logs and your webserver's logs. [2019-06-03 11:42:50] production.ERROR: ErrorException: ldap_search(): Search: Operations error in /var/www/html/app/Models/Ldap.php:265 [2019-06-03 11:42:50] production.ERROR: ErrorException: ldap_search(): Search: Operations error in /var/www/html/app/Models/Ldap.php:265
  • Include what you've done so far in the installation, and if you got any error messages along the way. No errors turning installation. I tried changing the case of the LDAP attributes based on previous issues.
  • Indicate whether or not you've manually edited any data directly in the database No data has been directly edited.

Please do not post an issue without answering the related questions above. If you have opened a different issue and already answered these questions, answer them again, once for every ticket. It will be next to impossible for us to help you.

https://snipe-it.readme.io/docs/getting-help

mikem011 avatar Jun 03 '19 15:06 mikem011

Try removing the spaces after the comma OU=Staff,OU=Location1,OU=Users,OU=Accounts,DC=domain,DC=com

ThomasDE91 avatar Jun 03 '19 20:06 ThomasDE91

Sorry, there are no spaces in the actual config. That was my fault for typing up the issue with spaces in the distinguish name.

mikem011 avatar Jun 04 '19 01:06 mikem011

How is your OU structured? Seems you trying to Query many OU's. 1st Try Base DN to "OU=Staff,OU=Location1,OU=Users,OU=Accounts,DC=domain,DC=com" and then try moving out OU one by one.

thameerakn avatar Jun 04 '19 02:06 thameerakn

The OU I am attempting to query is 2 levels below our base DN. Is there a limitation of only querying 1 level below the base DN? The structure of our OUs is below.

  • domain.com
    • Accounts
      • Users
        • Location1
          • Staff
          • Students
        • Location2
          • Staff
          • Students

mikem011 avatar Jun 04 '19 11:06 mikem011

I was not able to find the cause of the error so I setup a clean install of the server and started over again. I have LDAP syncing working with the base DN. Next I created a location and set the search OU for that location to one level deeper in the structure. The sync succeeds, but it syncs all users in the base DN to that location, not just the users specified in the search OU. Its like the search OU field for the location is being ignored.

mikem011 avatar Jun 10 '19 17:06 mikem011

The only way I believe you can currently assign users to locations using the internal LDAP sync utility is to manually change the base DN in LDAP section of the admin page to point to the location's OU (or use the LDAP filter and filter for an AD attribute unique to that location's users), then navigate back to the LDAP sync page, select the location from the drop down menu, and sync. Rinsing and repeating for each location.

This of course can be a time consuming and tedious process and would be a nightmare to maintain as new users are added to AD, I wouldn't recommend.

We do the following:

  • Set the base DN and Filter to cover all users.
  • Run the LDAP sync as part of the checklist for creating a new user to ensure it is always up to date.
  • Have a scheduled task to run a PowerShell script that populates all the user fields in Snipe from AD.

Powershell module for Snipe-IT: https://github.com/snazy2000/SnipeitPS

The sanitised script we use, you just need to add a switch statement to cover your locations and set $user.location_id appropriately in each case:


Import-Module SnipeitPS

$users = Get-ADUser -Filter * -SearchBase "OU=Domain Users,DC=foo,DC=bar" -Properties *
 
$apikey = "YOUR-KEY"
$url = "SNIPE-URL"
 
foreach ($user in $users)
{

    $firstString = "CN="
    $secondString = ","
    $pattern = "$firstString(.*?)$secondString"
    $manager = $user.Manager
    $result = [regex]::Match($manager,$pattern).Groups[1].Value

    $searchQuery = $user.GivenName + " " + $user.sn

    $snipeUser = Get-User -search $searchQuery -url $url -apiKey $apikey
    $userManager = Get-User -search $result -url $url -apiKey $apikey

        if(([string]::IsNullOrEmpty($snipeUser))) {
            New-User -firstName $user.GivenName -lastName $user.Surname -userName $user.UserPrincipalName -password $password -password_confirmation $password -jobTitle $user.Description -phone $user.telephoneNumber -email $user.UserPrincipalName -url $url -apiKey $apikey
        }
        Else {
            Set-User -id $snipeUser[0].id -jobtitle $user.title -phone $user.ipPhone -url $url -apiKey $apikey
            if(!([string]::IsNullOrEmpty($userManager))) {
               Set-User -id $snipeUser[0].id -manager_id $userManager[0].id -url $url -apiKey $apikey
            }
        }
    
    $snipeUser = ""
    $userManager = ""
    $manager = ""
    $result = ""
}

This is something you'd probably want to do even if you weren't having this issue as LDAP sync does not pull the majority of the user attributes from AD and I find having them all populated in Snipe increases the platforms utility, negating the need to search AD most of the time I need to get a users info.

GitHub
Powershell API Wrapper for Snipe-it. Contribute to snazy2000/SnipeitPS development by creating an account on GitHub.

Scintillator avatar Jun 12 '19 13:06 Scintillator

Thanks!

mikem011 avatar Jun 12 '19 16:06 mikem011

No worries. If you don't care about user logon using AD credentials and just want them added to the database so you can track asset assignments then you don't even need to use the internal LDAP sync at all, the script will create new users from AD not found in Snipe-IT and assign them the $password value you specify.

Scintillator avatar Jun 13 '19 10:06 Scintillator

Is this still relevant? We haven't heard from anyone in a bit. If so, please comment with any updates or additional detail. This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Don't take it personally, we just need to keep a handle on things. Thank you for your contributions!

stale[bot] avatar Aug 12 '19 10:08 stale[bot]

This issue has been automatically closed because it has not had recent activity. If you believe this is still an issue, please confirm that this issue is still happening in the most recent version of Snipe-IT and reply to this thread to re-open it.

stale[bot] avatar Aug 19 '19 11:08 stale[bot]