Samba and LDAP is completely out of date

Bug #1579209 reported by Samuel Abels
26
This bug affects 4 people
Affects Status Importance Assigned to Milestone
Ubuntu Server Guide
Fix Released
Undecided
Andreas Hasenack

Bug Description

The server guide for Samba and LDAP is filed under "Ubuntu 16.04", but is completely out of date for this release.

https://help.ubuntu.com/lts/serverguide/samba-ldap.html

Almost every step does not work:

- Importing the schema appears to have changed completely; Ubuntu now ships with a complete .ldif file under a new location (/usr/share/doc/samba/examples/LDAP/samba.ldif.gz). So no conversion should be necessary, as far as I can tell.

- samba-doc does not longer exist.

- Adding the indices fails "DN does not exist". So the shown output is incompatible with the samba.ldif that ships with the package.

- smbldap-config.pl is no longer in any package I could find on packages.ubuntu.com (the named source package also no longer exists). Alternate instructions are missing. (This is where I stopped.)

I am guessing that the rest of the document is also no longer working.

Related branches

Revision history for this message
Doug Smythies (dsmythies) wrote :

Thanks for your bug report. Yes, we know there are issues, and have been trying to get them fixed.
Have a look at a pending Merge Proposal, and see if it addresses all the issues you found.

https://code.launchpad.net/~nacc/serverguide/samba/+merge/293442

Changed in serverguide:
status: New → Confirmed
Revision history for this message
Samuel Abels (knipknap) wrote :

Thanks for the info! Following the instructions with the updated docs works until the step where indices are added. Creating the indices fails on my machine:

    $ sudo ldapmodify -Q -Y EXTERNAL -H ldapi:/// -f samba_indices.ldif
    modifying entry "olcDatabase={1}hdb,cn=config"
    ldap_modify: No such object (32)
            matched DN: cn=config

I am guessing "hdb" needs to be changed to whatever your database is. In my case, I just used the Ubuntu defaults from 16.04 installation, resulting in the following dn:

    $ sudo ls /etc/ldap/slapd.d/cn\=config | grep Database= | grep db.ldif
    olcDatabase={1}mdb.ldif

However, after changing the first line in samba_indices.ldif to:

    dn: olcDatabase={1}mdb,cn=config

there are still errors:

    $ sudo ldapmodify -Q -Y EXTERNAL -H ldapi:/// -f samba_indices.ldif
    modifying entry "olcDatabase={1}mdb,cn=config"
    ldap_modify: Other (e.g., implementation specific) error (80)
        additional info: duplicate index definition for attr "uidNumber"

Revision history for this message
Samuel Abels (knipknap) wrote :

Some more info on the attributes that are causing the conflict:

$ sudo ldapsearch -Q -LLL -Y EXTERNAL -H ldapi:/// -b cn=config olcDatabase={1}mdb olcDbIndex
dn: olcDatabase={1}mdb,cn=config
olcDbIndex: objectClass eq
olcDbIndex: cn,uid eq
olcDbIndex: uidNumber,gidNumber eq
olcDbIndex: member,memberUid eq

Revision history for this message
Samuel Abels (knipknap) wrote :

The merge also does not address the problem that the smbldap-config.pl isn't there.

Revision history for this message
Nish Aravamudan (nacc) wrote :

FWIW, upstream Samba has fixed the lack of smbldap-config.pl in the source (it was a Makefile error?) I will see if I can backport the fix.

Revision history for this message
Nish Aravamudan (nacc) wrote :

FWIW, I've provided an patch for the 16.10 version of smbldap-tools in Bug: #997172. Once that's there, we can SRU the same fix back to the older versions, esp. 14.04 and 16.04, at which point we'll update the documentation to not refer to said bug (as the tool should exist again), and hopefully, Samuel you can retest then.

Revision history for this message
Nish Aravamudan (nacc) wrote :

@Samuel, the smbldap-tools change has landed in trusty-proposed, if you could test it, that'd be great!

Revision history for this message
Heidou (heidou) wrote :
Download full text (13.9 KiB)

Hello,

I spent almost 3 weeks banging my head making OpenLDAP + TLS + Samba to work. Thought I might share my experience could help someone out there.

I started having no knowledge about LDAP, followed 'OpenLDAP Server' (https://help.ubuntu.com/lts/serverguide/openldap-server.html) and 'Samba and LDAP' (https://help.ubuntu.com/lts/serverguide/samba-ldap.html) server guide pages, I failed many, many times.

I am going to list modification/enhancement points I believe it would be better/nice to have on those two guides.

1. OpenLDAP Server (https://help.ubuntu.com/lts/serverguide/openldap-server.html) Guide

1-1. I think it would be nice to have brief description of ldap URL scheme somewhere before installation section. Since confusing them could end up wasting days like me :(
Something like:
 There are three URL scheme used for LDAP. 'ldap://', 'ldapi://' and 'ldaps://'.
 - 'ldap://' instructs to use TCP/IP connection and most commonly used. Port 389 will be used, unless you specify it in URL in 'ldap://hostname:port/' form.
 - 'ldapi://' is to use UNIX domain socket, typically used in 'ldapi:///' form to indicate to connect to default server. This can be used only when you run clients on the same machine slapd is running. If you want to use it with TLS, there are some restrictions apply (see the last note on 1-4).
 - 'ldaps://' was used to establish TLS connection using port 636. The new way of TLS enabled LDAP is to use standard 'ldap://' scheme and port 389. Using of 'ldaps://' is discouraged.

1-2. I followed sections 'Installation', 'Post-install Inspection', 'Modifying/Populating your Database', 'Logging', 'TLS' and 'LDAP Authentication' only. But anywhere it refers 'hdb' in command or output, it should be replaced with 'mdb' since mdb is the default database slapd uses in current version.

1-3. In 'TLS' section, following instructions in that order end up having an error at 'ldapmodify' command, since at that time slapd does not have read permission on private key file. Correct order would be:

 <After generating keys and certificates>

 Tighten up (or loosen down?) ownership and permissions:

  sudo adduser openldap ssl-cert
  sudo chgrp ssl-cert /etc/ssl/private/ldap01_slapd_key.pem
  sudo chmod g+r /etc/ssl/private/ldap01_slapd_key.pem
  sudo chmod o-r /etc/ssl/private/ldap01_slapd_key.pem

 Restart OpenLDAP:

  sudo systemctl restart slapd.service

 Create the file certinfo.ldif with the following contents [[(adjust accordingly, our example assumes we created certs using https://www.cacert.org) I think we created cacert.pem in instructions right above. This note may not be precise? ]]:

  dn: cn=config
  add: olcTLSCACertificateFile
  olcTLSCACertificateFile: /etc/ssl/certs/cacert.pem
  -
  add: olcTLSCertificateFile
  olcTLSCertificateFile: /etc/ssl/certs/ldap01_slapd_cert.pem
  -
  add: olcTLSCertificateKeyFile
  olcTLSCertificateKeyFile: /etc/ssl/private/ldap01_slapd_key.pem

 Use the ldapmodify command to tell slapd about our TLS work via the slapd-config database: [[ modified '/etc/ssl/certinfo.ldif' to 'certinfo.ldif' ]]

  sudo ldapmodify -Y EXTERNAL -H ldapi:/// -f certinfo.ldif

1-4. Again, in 'TLS' section, t...

Revision history for this message
Heidou (heidou) wrote :

Hello again,

I made a mistake on above post. In 1-5, about 'LDAP Authentication' describing /etc/ldap.conf modification, I wrote:

> You don't need to have 'tls_cacertfile' line. System will find CA certificate by itself as long as you put it in standard certificate folder (/etc/ssl/certs/).

Turned out you actually NEED 'tls_cacertfile' line. So you have to add 2 lines in /etc/ldap.conf to use TLS enabled libnss_ldap.

  ssl start_tls
  tls_cacertfile /etc/ssl/certs/cacert.pem

Sorry about the mess.

Revision history for this message
Heidou (heidou) wrote :

So, I just found about the update-ca-certificates command and /usr/share/ca-certificates folder.
The reason libnss_ldap didn't find CA certificate might be I didn't follow standard procedures.
(Fanny thing on slapd server machine, it found it without tls_cacertfile line, but on client machine it didn't.)

I think I have to rewrite 1-5 altogether.

Revision history for this message
Heidou (heidou) wrote :

Mystery solved.

In 1-5, I wrote:

> You don't need to have 'tls_cacertfile' line. System will find CA certificate by itself as long as you put it in standard certificate folder (/etc/ssl/certs/).

That's a lie. I leaned, for a CA certificate file to be automatically found, not only it must reside in standard folder, but it also has to be named based on it's hash value.
Our CA certificate file name is not. Nobody can find it, unless we tell them where it is, in one way or another.

These are the software we used and how they find where CA certificate is.

OpenLDAP utility client (ldapsearch, ldapmodify, ...)
  -> libldap
    -> 'TLS_CACERT' line in /etc/ldap/ldap.conf

libnss_ldap
  -> 'tls_cacertfile' line in /etc/ldap.conf
    -> libldap
      -> 'TLS_CACERT' line in /etc/ldap/ldap.conf

smbd
  -> libldap
    -> 'TLS_CACERT' line in /etc/ldap/ldap.conf

smbldap-tools
  -> 'cafile' line in /etc/smbldap-tools/smbldap.conf
    -> Net::LDAP

Server machine I configured did not need 'tls_cacertfile' line in /etc/ldap.conf, because I had 'TLS_CACERT' line in /etc/ldap/ldap.conf. But, on a client machine I didn't, libnss_ldap could not find CA certificate until I put 'tls_cacertfile' line in /etc/ldap.conf.

Apparently, one way (probably a better way) to do this is to use 'update-ca-certificates' command and have hash-based CA certificate file name under /etc/ssl/certs/. But I feel describing all that may go beyond our purpose of simple OpenLDAP + TLS configuration.

So I'm going to stick with '/etc/ssl/certs/cacert.pem', and put this path in /etc/ldap/ldap.conf, regardless it's a server machine or a client. Also, 'TLS_REQCERT demand' seems good addition to make sure clients establish an encrypted communication (although OpenLDAP utility client programs ignore it).

I revise my previous report in following 2 sections.

In 1-4.
--- old lines ---
> Edit a line in /etc/ldap/ldap.conf. (GnuTLS needs it?)
>
> TLS_CACERT /etc/ssl/certs/cacert.pem
--- replaced with ---
 Edit /etc/ldap/ldap.conf and have these two lines.

  TLS_REQCERT demand
  TLS_CACERT /etc/ssl/certs/cacert.pem
--- end ---

In 1-5.
--- old lines --
 Then add a line:

  ssl start_tls

 You don't need to have 'tls_cacertfile' line. System will find CA certificate by itself as long as you put it in standard certificate folder (/etc/ssl/certs/).
--- replaced with ---
 Then add a line:

  ssl start_tls

 - Edit /etc/ldap/ldap.conf and have these two lines, if you haven't done so yet.

  TLS_REQCERT demand
  TLS_CACERT /etc/ssl/certs/cacert.pem
--- end ---

This should be sufficient.

Chao.

Revision history for this message
Paul (pacun123) wrote :

Hello,

was the indices problem ever resolved.

  $ sudo ldapmodify -Q -Y EXTERNAL -H ldapi:/// -f samba_indices.ldif
    modifying entry "olcDatabase={1}hdb,cn=config"
    ldap_modify: No such object (32)
            matched DN: cn=config

I'm struggling to add them to my config.

Thanks in advance.

Revision history for this message
Nish Aravamudan (nacc) wrote :

@Paul: this bug (based upon its title) is purely about the server guide. While we can open tasks for the samba issues, there seem to be multiple.

Can you file a bug against samba (or see if one already is) for the indices issue, and subscribe me (nacc) to it, and I will see if I can help get it resolved.

Revision history for this message
Andreas Hasenack (ahasenack) wrote :

Hi,

just a heads up. As mentioned elsewhere, this bug is highlighting a lot of issues that would be better dealt with in separate bugs. I already fixed quite a few and I'm working up to tackling the samba+ldap section soon. Once that happens, I'll go over what was mentioned here and file separate bugs where appropriate, and tackle them individually.

Revision history for this message
Andreas Hasenack (ahasenack) wrote :

If you want to check the current guide's state, you can branch lp:serverguide and build the html or pdf versions. I think https://wiki.ubuntu.com/DocumentationTeam/SystemDocumentation/BuildingDocumentation and/or https://wiki.ubuntu.com/DocumentationTeam/SystemDocumentation/Repository list the dependencies you need to install for the build.

Revision history for this message
Andreas Hasenack (ahasenack) wrote :

What is fixed already in the guide in trunk:
- backend change from hdb to mdb
- adding indexes
- SSL instructions

I'm now going over the steps to spot remaining issues.

Changed in serverguide:
assignee: nobody → Andreas Hasenack (ahasenack)
status: Confirmed → In Progress
Changed in serverguide:
status: In Progress → Fix Committed
Changed in serverguide:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.