{{Out_of_date|pam_ldap/nss_ldap are deprecated in favor of {{pkg|nss-pam-ldapd}}; {{pkg|pambase}} obsoletes most of the pam section}}

+

{{Merge|LDAP Authentication}}

== Introduction and Concepts ==

== Introduction and Concepts ==

−

This guide is composed from bits and pieces of LDAP guides and forums around the net. I borrowed very heavily from Eliott's (cactus) OpenLDAP guide [[http://solarblue.net/docs/ldap.htm Ldap Server Setup]] which is very well written. Unfortunately Arch Linux has some differences in the way things are setup. It is also the case that most LDAP guides online fall into one of 3 categories: too general, outdated or uses distro specific tools (i.e. authconfig). This guide is written specifically with Arch linux in mind and will try to illustrate both LDAP concepts and implementation from the point of view of someone who has never used LDAP before (i.e. the author).

+

This is a guide on how to configure an Archlinux installation to authenticate against an OpenLDAP server.The openldap backend can be either local (installed on the same computer) or network (i.e in a lab environment where central authentication is desired).

+

The guide will be divided in two parts. The first part deals with how to setup OpenLDAP locally and the second with how to setup the NSS and PAM modules required for the authentication scheme to work. If you just want to configure Arch to authenticated against an already excisting LDAP server then you can skip to the second part.

=== OpenLDAP ===

=== OpenLDAP ===

−

UNDER CONSTRUCTION!

+

OpenLDAP is an open-source server implementation of the LDAP protocol. It is mainly used as an authentication backend to various services (the most famous one being Samba, which is used to emulate a domain controller) and basically holds the user data.

+

The closest analogue to real life, would be the telephone directory. Another generalised explanation of what an LDAP server does is that it is a database (which it basically is, but it is not relational) which is optimised for accessing the data and not writing them.

+

+

Commands relate to OpenLDAP that begin with ldap (like ldapsearch) are client-side utilities while commands that begin with slap (like slapcat) are server-side. Arch packages both in the {{pkg|openldap}} package, so you need to install it regardless of o local or network OpenLDAP install.

=== NSS and PAM ===

=== NSS and PAM ===

−

UNDER CONSTRUCTION!

+

NSS (which stands for Name Service Switch) is a system mechanism to configure different sources for common configuration databases. For example, {{ic|/etc/passwd}} is a {{ic|file}} type source for the passwd database.

−

−

== Server Setup ==

−

−

=== Install OpenLDAP ===

−

The OpenLDAP server (slapd) and clients are bundled together in the openldap package.

+

PAM (which stands for Pluggable Authentication Module) is a machanism Linux (and most *nixes) uses to extend it's authentication schemes based on different plugins.

−

pacman -S openldap

+

So to summarize, we need to configure NSS to use the OpenLDAP server as a source for the {{ic|passwd}} {{ic|shadow}} and other configuration databases and then configure PAM to use these sources to authenticate it's users.

−

=== Configure OpenLDAP ===

+

== OpenLDAP Setup ==

−

Generate root password:

+

=== Installation ===

−

slappasswd -h {SSHA}

+

You can read about installation and basic configuration in the [[OpenLDAP]] article. After you have completed that, return here.

−

−

Edit /etc/openldap/slapd.conf

−

−

: At a minimum your slapd.conf file should include these settings:

−

include /etc/openldap/schema/core.schema

−

include /etc/openldap/schema/cosine.schema

−

include /etc/openldap/schema/inetorgperson.schema

−

pidfile /run/openldap/slapd.pid

−

argsfile /run/openldap/slapd.args

−

database bdb

−

suffix "dc=example,dc=org"

−

rootdn "cn=Manager,dc=example,dc=org"

−

rootpw {SSHA}AAAABBBBCCCCDDDD #NOTE: paste in the output of the slappasswd command above

It's a good idea to configure TLS to encrypt the exchange of information between client and server. This way passwords, which are normally sent plain-text, cannot be easily sniffed from the wire. In order to use TLS, we must first create a certificate. You can have a certificate signed, or create your own Certificate Authority (CA), but for our purposed, a self-signed certificate will suffice. '''IMPORTANT:''' OpenLDAP cannot use a certificate that has a password associated to it.

You will be prompted for information about your ldap server. Much of the information can be left blank. The most important information is the common name. This must be set to the DNS name of your ldap server. If your LDAP server's IP address resolves to example.org but its server certificate shows a CN of bad.example.org, LDAP clients will reject the certificate and will be unable to negotiate TLS connections (apparently the results are wholly unpredictable).

−

−

Now that the certificate files have been created copy them to /etc/openldap/ssl/ (if this directory doesn't exist create it) and secure them. '''IMPORTANT:''' slapdcert.pem must be world readable because it contains the public key. slapdkey.pem on the other hand should only be readable for the ldap user for security reasons:

−

−

cp slapdcert.pem slapdkey.pem /etc/openldap/ssl/

−

chown ldap slapdkey.pem

−

chmod 400 slapdkey.pem

−

chmod 444 slapdcert.pem

−

−

Edit the daemon configuration file (/etc/openldap/slapd.conf) to tell LDAP where the certificate files reside by adding the following lines:

−

−

# Certificate/SSL Section

−

TLSCipherSuite HIGH:MEDIUM:+SSLv2

−

TLSCertificateFile /etc/openldap/ssl/slapdcert.pem

−

TLSCertificateKeyFile /etc/openldap/ssl/slapdkey.pem

−

−

The TLSCipherSuite specifies a list of OpenSSL ciphers from which slapd will choose when negotiating TLS connections, in decreasing order of preference. In addition to those specific ciphers, you can use any of the wildcards supported by OpenSSL. '''NOTE:''' HIGH, MEDIUM, and +SSLv2 are all wildcards.

−

−

To see which ciphers are supported by your local OpenSSL installation, type the following:

−

−

openssl ciphers -v ALL

−

−

In order to tell OpenLDAP to start using encryption, edit /etc/conf.d/slapd, uncomment the SLAPD_SERVICES line and set it to the following:

−

−

SLAPD_SERVICES="ldaps:///"

−

−

This will cause OpenLDAP to accept encrypted. '''IMPORTANT:''' If you created a self-signed certificate above be sure to add the following line to /etc/openldap/ldap.conf or you won't be able connect to the server to test it:

−

−

TLS_REQCERT allow

−

−

Restart the server:

−

−

/etc/rc.d/slapd restart

−

Test that the server is encrypting traffic run the following command:

+

[[pacman|Install]] {{Pkg|openldap}} from the [[official repositories]]. This is needed regardless of whether you run openldap on your machine or over the network.

There is the {{pkg|nss_ldap}} and {{pkg|pam_ldap}} from the [[Official Repositories|official repositories]]

=== OpenLDAP ===

=== OpenLDAP ===

+

Before you begin setting up PAM and NSS for ldap authentication, you should try to check if the LDAP server is available. You can do this easily with ldapsearch.

−

'''IMPORTANT:''' If you created a self-signed certificate above be sure to add the following line to /etc/openldap/ldap.conf or you won't be able connect to the server:

+

You can search an LDAP server with the following command:

−

+

{{bc|ldapsearch -x -H <URL> -b <BASE>}}

−

TLS_REQCERT allow

+

{{Tip| {{ic|-x}} is required in all client commands because SASL authentication probably hasn't been configured.}}

−

−

=== NSS_LDAP ===

+

You can add the URL and BASE settings to {{ic|/etc/openldap/ldap.conf}} in order to avoid writing the everytime. All client-side ldap utilities use this file to read some general variables.

+

{{Warning| If you created a self-signed certificate above you need to also add the following line or you will not be able connect to the server:

+

{{ic|TLS_REQCERT allow}} }}

−

Install the nss_ldap module:

+

=== NSS Configuration ===

+

NSS is a system facility which manages different sources as configuration databases. For example {{ic|/etc/passwd}} is i {{ic|file}}-type source for the {{ic|passwd}} which by default stores the user accounts. nss_ldap is a plugin which allow NSS to see an OpenLDAP server as a source for these databases.

−

pacman -S nss_ldap

+

Edit {{ic|/etc/nsswitch.conf}} which is the central configuration file for NSS. It tells NSS which sources to use for which system databases. We need to add the {{ic|ldap}} directive to the {{ic|passwd}}, {{ic|group}} and {{ic|shadow}} databases, so be sure your file looks like this:

−

−

Edit /etc/nss_ldap.conf:

−

−

host <SERVER_IP>

−

base dc=example,dc=org

−

rootbinddn cn=admin,dc=example,dc=org

−

port 636

−

pam_login_attribute uid

−

pam_template_login_attribute uid

−

nss_base_passwd ou=People,dc=example,dc=org?one

−

nss_base_shadow ou=People,dc=example,dc=org?one

−

nss_base_group ou=Group,dc=example,dc=org?one

−

ssl start_tls

−

ssl on

−

−

# This is only needed if your using a self-signed certificate.

−

tls_checkpeer no

−

−

Edit /etc/nsswitch.conf

passwd: files ldap

passwd: files ldap

Line 174:

Line 96:

shadow: files ldap

shadow: files ldap

−

=== PAM_LDAP ===

+

==== Name Service Cache Daemon ====

+

NSCD is a daemon that NSS runs that is responsible for caching lookups and queries for network backends.

−

Install pam_ldap module:

+

{{Note|It is recommended to stop the daemon when troubleshooting because it may mask problems by serving cached queries}}

Introduction and Concepts

This is a guide on how to configure an Archlinux installation to authenticate against an OpenLDAP server.The openldap backend can be either local (installed on the same computer) or network (i.e in a lab environment where central authentication is desired).
The guide will be divided in two parts. The first part deals with how to setup OpenLDAP locally and the second with how to setup the NSS and PAM modules required for the authentication scheme to work. If you just want to configure Arch to authenticated against an already excisting LDAP server then you can skip to the second part.

OpenLDAP

OpenLDAP is an open-source server implementation of the LDAP protocol. It is mainly used as an authentication backend to various services (the most famous one being Samba, which is used to emulate a domain controller) and basically holds the user data.
The closest analogue to real life, would be the telephone directory. Another generalised explanation of what an LDAP server does is that it is a database (which it basically is, but it is not relational) which is optimised for accessing the data and not writing them.

Commands relate to OpenLDAP that begin with ldap (like ldapsearch) are client-side utilities while commands that begin with slap (like slapcat) are server-side. Arch packages both in the openldap package, so you need to install it regardless of o local or network OpenLDAP install.

NSS and PAM

NSS (which stands for Name Service Switch) is a system mechanism to configure different sources for common configuration databases. For example, /etc/passwd is a file type source for the passwd database.

PAM (which stands for Pluggable Authentication Module) is a machanism Linux (and most *nixes) uses to extend it's authentication schemes based on different plugins.

So to summarize, we need to configure NSS to use the OpenLDAP server as a source for the passwdshadow and other configuration databases and then configure PAM to use these sources to authenticate it's users.

OpenLDAP Setup

Installation

You can read about installation and basic configuration in the OpenLDAP article. After you have completed that, return here.

OpenLDAP

Before you begin setting up PAM and NSS for ldap authentication, you should try to check if the LDAP server is available. You can do this easily with ldapsearch.

You can search an LDAP server with the following command:

ldapsearch -x -H <URL> -b <BASE>

Tip: -x is required in all client commands because SASL authentication probably hasn't been configured.

You can add the URL and BASE settings to /etc/openldap/ldap.conf in order to avoid writing the everytime. All client-side ldap utilities use this file to read some general variables.

Warning: If you created a self-signed certificate above you need to also add the following line or you will not be able connect to the server:
TLS_REQCERT allow

NSS Configuration

NSS is a system facility which manages different sources as configuration databases. For example /etc/passwd is i file-type source for the passwd which by default stores the user accounts. nss_ldap is a plugin which allow NSS to see an OpenLDAP server as a source for these databases.

Edit /etc/nsswitch.conf which is the central configuration file for NSS. It tells NSS which sources to use for which system databases. We need to add the ldap directive to the passwd, group and shadow databases, so be sure your file looks like this:

passwd: files ldap
group: files ldap
shadow: files ldap

Name Service Cache Daemon

NSCD is a daemon that NSS runs that is responsible for caching lookups and queries for network backends.

Note: It is recommended to stop the daemon when troubleshooting because it may mask problems by serving cached queries