server icon indicating copy to clipboard operation
server copied to clipboard

Setting up LDAP using starttls does not work

Open maxnoe opened this issue 8 years ago • 29 comments

Steps to reproduce

  1. Setup LDAP server using StartTLS
  2. Setup a nextcloud instance and enable the LDAP plugin
  3. Add server certificate in /etc/ldap/ldap.con
  4. Start setting up the server in the LDAP setup
  5. Enter Server, Port and BaseDN in the Server Tab → Connection works, number of entries is correctly reported
  6. Go on to the user tab

Expected behaviour

Connection to LDAP server is still possible in the user tab

Actual behaviour

Could not connect to LDAP on switch to Users tab. When going back to Server tab, connection still works

Server configuration

Current Nextcloud 13.0 Docker image

maxnoe avatar Mar 08 '18 15:03 maxnoe

can you please provide the LDAP config, also?

blizzz avatar Mar 14 '18 09:03 blizzz

I am experiencing pretty much the same behavior. Basically, I get everything setup on the "Server" tab and get "Configuration Okay" which I take to mean that Nextcloud can tell that there is an LDAP server to talk to at the address/port I have provided. Then, when I continue to the "Users" tab, a message pops up saying "Could not connect to LDAP". What I believe is happening is that Nextcloud finally tried to authenticate with my bind creds and that failed.

I am trying to connect to an LDAP server that forces STARTTLS upgrades for every connection.

My (obfuscated) settings:

  • Host: ldap.example.com (no ldaps://)
  • Port: 386
  • User DN: uid=myUID,ou=People,dc=example,dc=com
  • Base DN: ou=People,dc=example,dc=com

From the VM that is hosting my Nextcloud instance, I can run the following command successfully, which leads me to think that my LDAP server is accessible and my bind creds are good:

ldapwhoami -vvv -h ldap.example.com -p 389 -D uid=myUID,ou=People,dc=example,dc=com -x -W -Z

  • Result: Success (0)

I am not seeing anything showing up in the main Nextcloud logs (got the level turned all the way up to Debug). Is there other log files I could check?

Any thoughts or suggestions would be much appreciated! I feel like I am just missing something easy here, but I have been fiddling with things for a couple of days now and cannot seem to make it work. Thank you!

jkuester avatar May 02 '18 23:05 jkuester

php occ ldap:show-config please to verify starttls was correctly detected.

blizzz avatar May 07 '18 12:05 blizzz

No mention of starttils, just

ldapTLS | 1

maxnoe avatar May 07 '18 12:05 maxnoe

@MaxNoe that's exactly it. Please excuse the poor naming…

Can you please set the log level to DEBUG, visit the Users page and provide the nextcloud log? and perhaps LDAP log.

blizzz avatar May 07 '18 13:05 blizzz

I think these lines are the relevant ones:

{"reqId":"9FayNvXqWAFmKpcwRi9T","level":2,"time":"2018-05-07T15:30:17+00:00","remoteAddr":"10.42.178.230","user":"cloudadmin","app":"user_ldap","method":"POST","url":"\/index.php\/apps\/user_ldap\/ajax\/wizard.php","message":"Configuration Error (prefix ): No LDAP Login Filter given!","userAgent":"Mozilla\/5.0 (X11; Ubuntu; Linux x86_64; rv:59.0) Gecko\/20100101 Firefox\/59.0","version":"13.0.0.14"}
{"reqId":"9FayNvXqWAFmKpcwRi9T","level":2,"time":"2018-05-07T15:30:17+00:00","remoteAddr":"10.42.178.230","user":"cloudadmin","app":"user_ldap","method":"POST","url":"\/index.php\/apps\/user_ldap\/ajax\/wizard.php","message":"Configuration Error (prefix ): login filter does not contain %uid place holder.","userAgent":"Mozilla\/5.0 (X11; Ubuntu; Linux x86_64; rv:59.0) Gecko\/20100101 Firefox\/59.0","version":"13.0.0.14"}
{"reqId":"9FayNvXqWAFmKpcwRi9T","level":0,"time":"2018-05-07T15:30:17+00:00","remoteAddr":"10.42.178.230","user":"cloudadmin","app":"user_ldap","method":"POST","url":"\/index.php\/apps\/user_ldap\/ajax\/wizard.php","message":"LDAP error Confidentiality required (13) after calling ldap_bind","userAgent":"Mozilla\/5.0 (X11; Ubuntu; Linux x86_64; rv:59.0) Gecko\/20100101 Firefox\/59.0","version":"13.0.0.14"}

maxnoe avatar May 07 '18 15:05 maxnoe

Ok, I think I got the configuration working now by entering the two ldap filters by hand. Somehow they weren't created automatically like before and were empty.

However, ldap seems to be painfully slow. I always get gateway timeouts trying to log in and the users tab was running for ours and nothing showed up. The test configuration however correctly found my 92 users.

maxnoe avatar May 08 '18 08:05 maxnoe

Using ldapsearch on the commandline inside the container works fine.

maxnoe avatar May 08 '18 08:05 maxnoe

However, ldap seems to be painfully slow. I always get gateway timeouts trying to log in and the users tab was running for ours and nothing showed up.

This obviously should not be. Does the »LDAP error Confidentiality required« message still occur?

blizzz avatar May 09 '18 00:05 blizzz

No, there appears one line every few seconds with the requested user data

maxnoe avatar May 09 '18 08:05 maxnoe

@MaxNoe, could you provide some examples of the ldap filters you set to get things working?

@blizzz could you point me to where I would find the LDAP log for Nextcloud? (I am not seeing anything relevant in the main Nextcloud logs even with them turned up to DEBUG).

jkuester avatar May 10 '18 17:05 jkuester

@MaxNoe

Using ldapsearch on the commandline inside the container works fine.

And you require starttls there as well? And same user and password, too? Can you post your command? Esssentially the message means that the session is not TLS protected. Which server do you use?

@jkuester on nextcloud side in data/nextcloud.log, on the LDAP server it depends on the server.

blizzz avatar May 11 '18 12:05 blizzz

And you require starttls there as well?

Yes, ldapsearch -ZZ -D <binddn> -W -h <server> -b <basedn>

maxnoe avatar May 22 '18 09:05 maxnoe

@blizzz Thank you for pointing me in the right direction! I have LDAP users showing up in NextCloud now.

For the record, I did have to manually fill out the LDAP queries on the Login Attributes, Users, and Groups tabs (in addition to entering my bind info on the Server tab. In case anyone with the same issue ever finds this thread, here are the filters that I used (yours may differ depending on your LDAP setup):

  • Users - (&(ObjectClass=inetOrgPerson))
  • Login Attributes - (&(uid=%uid))
  • Groups - (&(ObjectClass=posixGroup))

jkuester avatar May 30 '18 13:05 jkuester

I got it working reasonably fast with setting the page size to 50 instead of 500 and providing filters for users and groups.

So maybe it's an issue of documentation / better defaults and not a bug.

maxnoe avatar Jun 11 '18 09:06 maxnoe

Hey, this issue has been closed because the label stale is set and there were no updates for 14 days. Feel free to reopen this issue if you deem it appropriate.

(This is an automated comment from GitMate.io.)

nextcloud-bot avatar Jul 27 '18 01:07 nextcloud-bot

I'm having a similar issue setting up LDAP with NextCloud. My connection fails to LDAP when my LDAP instance is configured to force TLS.

I've confirmed in 'php occ ldap:show-config' that 'ldapTLS | 1'

When I test a connection from NextCloud, my LDAP server's slapd.log file shows 'err=13 text=TLS confidentiality required'

I am using a self-signed certificate for LDAP, which may be the problem. I'm not exactly sure how to get NextCloud to use my self-signed certificate. I do have my CA certificate reference in /etc/ldap/ldap.conf on the NextCloud instance, though.

If I disable the requirement for TLS in LDAP, the connection is successful.

seanbaker74 avatar Dec 12 '18 15:12 seanbaker74

https://docs.nextcloud.com/server/14/admin_manual/configuration_user/user_auth_ldap.html#ssl-certificate-verification-ldaps-tls

blizzz avatar Dec 13 '18 12:12 blizzz

@blizzz, thanks for the link. I did have my CA certificate referenced in /etc/ldap/ldap.conf, but I must've needed to restart PHP or something...I just restarted my NextCloud container and it's working now. Cheers.

seanbaker74 avatar Dec 13 '18 12:12 seanbaker74

I spoke too soon. With the CA certificate installed, the "test base DN" link works, and I'm able to login to NextCloud using LDAP (no TLS errors in the LDAP log). However, if I click the "detect base DN" link or navigate to the other tabs (Users, Login Attributes and Groups), I get a "could not connect" error in the NextCloud web UI and "TLS confidentiality required" in the LDAP log.

seanbaker74 avatar Dec 13 '18 13:12 seanbaker74