https://wiki.archlinux.org/api.php?action=feedcontributions&user=Robohoe&feedformat=atomArchWiki - User contributions [en]2024-03-29T11:18:07ZUser contributionsMediaWiki 1.41.0https://wiki.archlinux.org/index.php?title=OpenLDAP_Authentication&diff=130253OpenLDAP Authentication2011-02-08T19:43:19Z<p>Robohoe: </p>
<hr />
<div>[[Category:Networking (English)]] [[Category:Security (English)]]<br />
== Introduction and Concepts ==<br />
<br />
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).<br />
<br />
=== OpenLDAP ===<br />
<br />
UNDER CONSTRUCTION!<br />
<br />
=== NSS and PAM ===<br />
<br />
UNDER CONSTRUCTION!<br />
<br />
== Server Setup ==<br />
<br />
=== Install OpenLDAP ===<br />
<br />
pacman -S openldap openldap-clients<br />
<br />
=== Configure OpenLDAP ===<br />
<br />
Generate root password:<br />
<br />
slappasswd -h {SSHA}<br />
<br />
Edit /etc/openldap/slapd.conf<br />
<br />
: At a minimum your slapd.conf file should include these settings: <br />
include /etc/openldap/schema/core.schema<br />
include /etc/openldap/schema/cosine.schema<br />
include /etc/openldap/schema/inetorgperson.schema<br />
pidfile /var/run/slapd.pid<br />
argsfile /var/run/slapd.args<br />
database bdb<br />
suffix "dc=example,dc=org"<br />
rootdn "cn=admin,dc=example,dc=org"<br />
rootpw {SSHA}AAAABBBBCCCCDDDD #NOTE: paste in the output of the slappasswd command above <br />
directory /var/lib/openldap/openldap-data<br />
index objectClass eq<br />
<br />
Provide a database config:<br />
cp /etc/openldap/DB_CONFIG.example /var/lib/openldap/openldap-data/DB_CONFIG<br />
<br />
Start OpenLDAP:<br />
<br />
/etc/rc.d/slapd start<br />
<br />
=== Populate LDAP Tree with Base Data ===<br />
<br />
Create a file called base.ldif with the following text:<br />
<br />
# example.org<br />
dn: dc=example,dc=org<br />
objectClass: dcObject<br />
objectClass: organization<br />
o: Example Organization<br />
dc: example<br />
<br />
# admin, example.org<br />
dn: cn=admin,dc=example,dc=org<br />
cn: admin<br />
description: LDAP administrator<br />
roleOccupant: dc=example,dc=org<br />
objectClass: organizationalRole<br />
objectClass: top<br />
<br />
# People, example.org<br />
dn: ou=People,dc=example,dc=org<br />
ou: People<br />
objectClass: top<br />
objectClass: organizationalUnit<br />
<br />
# Group, example.org<br />
dn: ou=Group,dc=example,dc=org<br />
ou: Group<br />
objectClass: top<br />
objectClass: organizationalUnit<br />
<br />
Add it to your OpenLDAP Tree:<br />
<br />
ldapadd -x -D "cn=admin,dc=example,dc=org" -W -f base.ldif<br />
<br />
Test to make sure the data was imported:<br />
<br />
ldapsearch -x -b 'dc=example,dc=org' '(objectclass=*)'<br />
<br />
<br />
*Note: I had to add "slapd: ALL" to /etc/hosts.allow before running the above command.<br />
<br />
=== Configure TLS Encryption ===<br />
<br />
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.<br />
<br />
To create a ''self-signed'' certificate, type the following:<br />
<br />
openssl req -new -x509 -nodes -out slapdcert.pem -keyout slapdkey.pem -days 365<br />
<br />
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).<br />
<br />
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.<br />
<br />
cp slapdcert.pem slapdkey.pem /etc/openldap/ssl/<br />
chmod 400 slapdkey.pem<br />
chmod 444 slapdcert.pem<br />
<br />
Edit the daemon configuration file (/etc/openldap/slapd.conf) to tell LDAP where the certificate files reside by adding the following lines:<br />
<br />
# Certificate/SSL Section<br />
TLSCipherSuite HIGH:MEDIUM:+SSLv2<br />
TLSCertificateFile /etc/openldap/ssl/slapdcert.pem<br />
TLSCertificateKeyFile /etc/openldap/ssl/slapdkey.pem<br />
<br />
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. <br />
<br />
To see which ciphers are supported by your local OpenSSL installation, type the following:<br />
<br />
openssl ciphers -v ALL<br />
<br />
In order to tell OpenLDAP to start using encryption edit /etc/rc.d/slapd and change<br />
<br />
stat_busy "Starting OpenLDAP"<br />
[ -z "$PID" ] && /usr/sbin/slapd<br />
<br />
to<br />
<br />
stat_busy "Starting OpenLDAP"<br />
[ -z "$PID" ] && `/usr/sbin/slapd -h ldaps:///`<br />
<br />
In newer builds (openldap-2.4.23), you may need to edit the /etc/conf.d/slapd file to specify the ldaps:/// portion.<br />
<br />
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:<br />
<br />
TLS_REQCERT allow<br />
<br />
Restart the server:<br />
<br />
/etc/rc.d/slapd restart<br />
<br />
Test that the server is encrypting traffic run the following command:<br />
<br />
ldapsearch -x -H ldaps://example.org -b 'dc=example,dc=org' '(objectclass=*)'<br />
<br />
<br />
== Client Setup ==<br />
<br />
=== OpenLDAP ===<br />
<br />
'''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:<br />
<br />
TLS_REQCERT allow<br />
<br />
<br />
=== NSS_LDAP ===<br />
<br />
Install the nss_ldap module:<br />
<br />
pacman -S nss_ldap<br />
<br />
Edit /etc/nss_ldap.conf:<br />
<br />
host <SERVER_IP><br />
base dc=example,dc=org<br />
rootbinddn cn=admin,dc=example,dc=org<br />
port 636<br />
pam_login_attribute uid<br />
pam_template_login_attribute uid<br />
nss_base_passwd ou=People,dc=example,dc=org?one<br />
nss_base_shadow ou=People,dc=example,dc=org?one<br />
nss_base_group ou=Group,dc=example,dc=org?one<br />
ssl start_tls<br />
ssl on<br />
<br />
# This is only needed if your using a self-signed certificate.<br />
tls_checkpeer no<br />
<br />
Edit /etc/nsswitch.conf<br />
<br />
passwd: files ldap<br />
group: files ldap<br />
shadow: files ldap<br />
<br />
=== PAM_LDAP ===<br />
<br />
Install pam_ldap module:<br />
<br />
pacman -S pam_ldap<br />
<br />
Edit /etc/pam_ldap.conf:<br />
<br />
host <SERVER_IP><br />
base dc=example,dc=org<br />
rootbinddn cn=admin,dc=example,dc=org<br />
port 636<br />
pam_login_attribute uid<br />
pam_template_login_attribute uid<br />
nss_base_passwd ou=People,dc=example,dc=org?one<br />
nss_base_shadow ou=People,dc=example,dc=org?one<br />
nss_base_group ou=Group,dc=example,dc=org?one<br />
ssl start_tls<br />
ssl on<br />
<br />
# This is only needed if your using a self-signed certificate.<br />
tls_checkpeer no<br />
<br />
Edit /etc/pam.d/login:<br />
<br />
auth requisite pam_securetty.so<br />
auth requisite pam_nologin.so<br />
auth sufficient pam_ldap.so <br />
auth required pam_env.so<br />
auth required pam_unix.so nullok try_first_pass<br />
account sufficient pam_ldap.so<br />
account required pam_access.so<br />
account required pam_unix.so<br />
session required pam_motd.so<br />
session required pam_limits.so<br />
session optional pam_mail.so dir=/var/spool/mail standard<br />
session optional pam_lastlog.so<br />
session required pam_unix.so<br />
<br />
Edit /etc/pam.d/passwd:<br />
<br />
password sufficient pam_ldap.so<br />
password required pam_unix.so shadow md5 nullok<br />
<br />
Edit /etc/pam.d/shadow:<br />
<br />
auth sufficient pam_ldap.so<br />
auth sufficient pam_rootok.so<br />
auth required pam_unix.so<br />
account sufficient pam_ldap.so<br />
account required pam_unix.so<br />
session sufficient pam_ldap.so<br />
session required pam_unix.so<br />
password sufficient pam_ldap.so<br />
password required pam_permit.so<br />
<br />
edit /etc/pam.d/su:<br />
<br />
auth sufficient pam_ldap.so<br />
auth sufficient pam_rootok.so<br />
auth required pam_unix.so use_first_pass<br />
account sufficient pam_ldap.so<br />
account required pam_unix.so<br />
session sufficient pam_ldap.so<br />
session required pam_unix.so<br />
<br />
edit /etc/pam.d/sshd:<br />
<br />
auth sufficient pam_ldap.so<br />
auth required pam_securetty.so #Disable remote root<br />
auth required pam_unix.so try_first_pass<br />
auth required pam_nologin.so<br />
auth required pam_env.so<br />
account sufficient pam_ldap.so<br />
account required pam_unix.so<br />
account required pam_time.so<br />
password sufficient pam_ldap.so<br />
password required pam_unix.so<br />
session required pam_unix_session.so<br />
session required pam_limits.so<br />
<br />
edit /etc/pam.d/other:<br />
<br />
auth sufficient pam_ldap.so<br />
auth required pam_unix.so<br />
account sufficient pam_ldap.so<br />
account required pam_unix.so<br />
password sufficient pam_ldap.so<br />
password required pam_unix.so<br />
session required pam_unix.so<br />
<br />
=== Name Service Cache Daemon ===<br />
<br />
READ THIS FIRST: [[http://bbs.archlinux.org/viewtopic.php?t=9401 NSCD Bugged in Arch Linux]]<br />
<br />
Fix nscd:<br />
<br />
mkdir -p /var/db/nscd/<br />
mkdir -p /var/run/nscd/<br />
<br />
Run nscd:<br />
<br />
/etc/rc.d/nscd start<br />
<br />
== Links and Resources ==<br />
<br />
One of the best OpenLDAP clients: [[http://phpldapadmin.sourceforge.net/ phpLDAPadmin]]<br />
<br />
Debian OpenLDAP setup: [[http://www.fatofthelan.com/articles/articles.php?pid=24 Using LDAP for single authentication]]<br />
<br />
How to integrate OpenLDAP for MacOSX, Windows and Linux: [[http://www.cs.dixie.edu/ldap/ Heterogeneous Network Authentication Introduction]]</div>Robohoe