LDAP: Difference between revisions

From Hobbynet Admin Wiki
Jump to navigation Jump to search
No edit summary
Line 16: Line 16:
Het volgende script maakt een initiële database zoals beschreven is in [http://www.howtoforge.com/install-and-configure-openldap-on-ubuntu-karmic-koala HowToForge] en de [http://www.openldap.org/doc/admin24/ OpenLDAP site]:
Het volgende script maakt een initiële database zoals beschreven is in [http://www.howtoforge.com/install-and-configure-openldap-on-ubuntu-karmic-koala HowToForge] en de [http://www.openldap.org/doc/admin24/ OpenLDAP site]:
<pre>
<pre>
#!/bin/sh
passwd=secret
dc1=example
dc2=com
hash_pw=`slappasswd -h "{MD5}" -s $passwd`
tmpdir=/tmp
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/cosine.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/inetorgperson.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/nis.ldif
#
#
# db.ldif
# Initial part.
#
#
cat <<EOF > $tmpdir/db.ldif
# Add the three main schemas
# Load dynamic backend modules
# Load the database backend module and create the database
dn: cn=module{0},cn=config
# Create the base dn and the admin account for the openldap server
objectClass: olcModuleList
# There are some acl's set in the openldap setup that prevent phpldapadmin
cn: module
# to interface with the directory, so we will remove them now and set openldap
olcModulepath: /usr/lib/ldap
# to the default cn=admin,cn=config. From this moment on the openldap can be
olcModuleload: {0}back_hdb
# configured and manipulated as before, but no longer by issuing commands like
 
# ldapadd -Y EXTERNAL -H ldapi:/// -f file
# Create the database
# but rather
dn: olcDatabase={1}hdb,cn=config
# ldapadd -x -D cn=admin,cn=config -W -f file
objectClass: olcDatabaseConfig
objectClass: olcHdbConfig
olcDatabase: {1}hdb
olcDbDirectory: /var/lib/ldap
olcSuffix: dc=$dc1,dc=$dc2
olcRootDN: cn=admin,dc=$dc1,dc=$dc2
olcRootPW: $passwd
olcDbConfig: {0}set_cachesize 0 2097152 0
olcDbConfig: {1}set_lk_max_objects 1500
olcDbConfig: {2}set_lk_max_locks 1500
olcDbConfig: {3}set_lk_max_lockers 1500
olcLastMod: TRUE
olcDbCheckpoint: 512 30
olcDbIndex: uid pres,eq
olcDbIndex: cn,sn,mail pres,eq,approx,sub
olcDbIndex: objectClass eq
EOF
 
#
#
# base.ldif
# Finally restart slapd
#
#
cat <<EOF > $tmpdir/base.ldif
# See: http://www.howtoforge.com/install-and-configure-openldap-on-ubuntu-karmic-koala
dn: dc=$dc1,dc=$dc2
objectClass: dcObject
objectclass: organization
o: $dc1.$dc2
dc: $dc1
description: My LDAP Root
 
dn: cn=admin,dc=$dc1,dc=$dc2
objectClass: simpleSecurityObject
objectClass: organizationalRole
cn: admin
userPassword: $hash_pw
description: LDAP administrator
EOF
 
#
#
# config.ldif
tmpdir=~/ldap
#
# Cleanup
cat <<EOF > $tmpdir/config.ldif
echo "Remove old databases"
dn: olcDatabase={0}config,cn=config
rm -R /var/lib/ldap/hcc/*
changetype: modify
rm -R /var/lib/ldap/hobby/*
add: olcRootDN
# Add schemas
olcRootDN: cn=admin,cn=config
echo "Add the cosine, nis and inetorgperson schema's"
 
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/cosine.ldif
dn: olcDatabase={0}config,cn=config
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/nis.ldif
changetype: modify
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/inetorgperson.ldif
add: olcRootPW
# Add database module and configure
olcRootPW: $hash_pw
echo "Add backend.ldif"
 
ldapadd -Y EXTERNAL -H ldapi:/// -f $tmpdir/backend.ldif
dn: olcDatabase={0}config,cn=config
# Add base DN
changetype: modify
echo "Add frontend.ldif"
delete: olcAccess
ldapadd -Y EXTERNAL -H ldapi:/// -f $tmpdir/frontend.ldif
EOF
# Place RootDN and remove ACLs
 
echo "Add config.ldif"
#
# acl.ldif
#
cat <<EOF > $tmpdir/acl.ldif
dn: olcDatabase={1}hdb,cn=config
add: olcAccess
olcAccess: to attrs=userPassword,shadowLastChange by dn="cn=admin,dc=$dc1,dc=$dc2" write by anonymous auth by self write by * none
olcAccess: to dn.base="" by * read
olcAccess: to * by dn="cn=admin,dc=$dc1,dc=$dc2" write by * read
EOF
 
ldapadd -Y EXTERNAL -H ldapi:/// -f $tmpdir/db.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f $tmpdir/base.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f $tmpdir/config.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f $tmpdir/config.ldif
ldapmodify -x -D cn=admin,cn=config -W -f $tmpdir/acl.ldif
# Place ACL
echo "Add acl.ldif"
ldapmodify -x -D cn=admin,cn=config -W -f acl.ldif
# Restart slapd
/etc/init.d/slapd restart
</pre>
</pre>
De drie kopregels moeten natuurlijk aangepast worden. Het oorspronkelijke script bevatte enige regels in config.ldif die problemen veroorzaken. Die zijn domweg weggelaten. Bovenaan stonden nog de volgende regels:
<pre>
dn: cn=config
changetype: modify
delete: olcAuthzRegexp


dn: olcDatabase={-1}frontend,cn=config
changetype: modify
delete: olcAccess
dn: olcDatabase={0}config,cn=config
changetype: modify
delete: olcRootDN
</pre>
==Replicatie==
==Replicatie==
Voor master/slave replicatie kan de configuratie in [https://help.ubuntu.com/10.04/serverguide/C/openldap-server.html Ubuntu Server Guide] gevonden worden.
Voor master/slave replicatie kan de configuratie in [https://help.ubuntu.com/10.04/serverguide/C/openldap-server.html Ubuntu Server Guide] gevonden worden.

Revision as of 10:22, 11 October 2011

Introductie

Om een centrale plaats te hebben om authenticatie te doen voor www.hcc.nl en sub-sites zoals een forum, is gekozen voor het gebruiken van een LDAP database/directory. Hierin wordt alleen opgeslagen wat nodig is voor het functioneren van de site. Andere persoonsgegevens en HCC specifieke gegevens komen in een (MySQL) database. Dit kan ook een tabel binnen de Drupal omgeving zijn

LDAP server keuze

De voor de hand liggen de keuze is OpenLDAP. Echter zijn er geluiden gehoord dat OpenLDAP niet zou schalen. Alternatieven zijn b.v. 389 maar die is erg slecht gesupport onder Ubuntu. Voorlopig starten we met OpenLDAP.

Loadbalanced

Er zijn twee servers (hcc-ldap-lb1 en hcc-ldap-lb2) die achter een loadbalancer in pomeleoepee mode staat zodat het verkeer altijd server1 gestuurd wordt. Beide servers houden elkaar up-to-date. In de gewone situatie zullen alle reads en writes naar server 1 gaan en server2 wordt door server1 bijgewerkt. Valt server1 weg, dan zal de loadbalancer overschakelen naar server2 waar vanaf dan de read en writes plaatsvinden. Zodra server 1 weer beschikbaar is, wordt die bijgewerkt en zal weer master worden. Dit is nog niet getest en hoe de timing precies is, is nog niet duidelijk...

installatie

installatie van OpenLDAP is simpel:

aptitude install slapd ldap-utils

De configuratie van OpenLDAP is sinds Karmic Koala iets gecompliceerder geworden. cn=config wordt nog steeds gebruikt maar tijdens installatie wordt alleen een skeleton configuratie geïnstalleerd. Er wordt niet meer gevraagd om een password tijdens de installatie en met "dpkg-reconfigure slapd" zet alleen de skeleton configuratie terug. Je moet zelf de database, root dn en acl's opzetten (als root of met sudo). Run dpkg-reconfigure slapd om terug te gaan naar een lege directory.

Initiële database

Het volgende script maakt een initiële database zoals beschreven is in HowToForge en de OpenLDAP site:

#
# Initial part.
#
# Add the three main schemas
# Load the database backend module and create the database
# Create the base dn and the admin account for the openldap server
# There are some acl's set in the openldap setup that prevent phpldapadmin
# to interface with the directory, so we will remove them now and set openldap
# to the default cn=admin,cn=config. From this moment on the openldap can be
# configured and manipulated as before, but no longer by issuing commands like
# ldapadd -Y EXTERNAL -H ldapi:/// -f file
# but rather
# ldapadd -x -D cn=admin,cn=config -W -f file
#
# Finally restart slapd
#
# See: http://www.howtoforge.com/install-and-configure-openldap-on-ubuntu-karmic-koala
#
tmpdir=~/ldap
# Cleanup
echo "Remove old databases"
rm -R /var/lib/ldap/hcc/*
rm -R /var/lib/ldap/hobby/*
# Add schemas
echo "Add the cosine, nis and inetorgperson schema's"
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/cosine.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/nis.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/ldap/schema/inetorgperson.ldif
# Add database module and configure
echo "Add backend.ldif"
ldapadd -Y EXTERNAL -H ldapi:/// -f $tmpdir/backend.ldif
# Add base DN
echo "Add frontend.ldif"
ldapadd -Y EXTERNAL -H ldapi:/// -f $tmpdir/frontend.ldif
# Place RootDN and remove ACLs
echo "Add config.ldif"
ldapadd -Y EXTERNAL -H ldapi:/// -f $tmpdir/config.ldif
# Place ACL
echo "Add acl.ldif"
ldapmodify -x -D cn=admin,cn=config -W -f acl.ldif
# Restart slapd
/etc/init.d/slapd restart

Replicatie

Voor master/slave replicatie kan de configuratie in Ubuntu Server Guide gevonden worden.

Uitbreiding tot single master

In ldap terminologie spreken we van een provider. In dit geval en single-master. De provider.ldif:

# Add indexes to the frontend db.
dn: olcDatabase={1}hdb,cn=config
changetype: modify
add: olcDbIndex
olcDbIndex: entryCSN eq
-
add: olcDbIndex
olcDbIndex: entryUUID eq

#Load the syncprov and accesslog modules.
dn: cn=module{0},cn=config
changetype: modify
add: olcModuleLoad
olcModuleLoad: syncprov
-
add: olcModuleLoad
olcModuleLoad: accesslog

# Accesslog database definitions
dn: olcDatabase={2}hdb,cn=config
objectClass: olcDatabaseConfig
objectClass: olcHdbConfig
olcDatabase: {2}hdb
olcDbDirectory: /var/lib/ldap/accesslog
olcSuffix: cn=accesslog
olcRootDN: cn=admin,dc=example,dc=com
olcDbIndex: default eq
olcDbIndex: entryCSN,objectClass,reqEnd,reqResult,reqStart

# Accesslog db syncprov.
dn: olcOverlay=syncprov,olcDatabase={2}hdb,cn=config
changetype: add
objectClass: olcOverlayConfig
objectClass: olcSyncProvConfig
olcOverlay: syncprov
olcSpNoPresent: TRUE
olcSpReloadHint: TRUE

# syncrepl Provider for primary db
dn: olcOverlay=syncprov,olcDatabase={1}hdb,cn=config
changetype: add
objectClass: olcOverlayConfig
objectClass: olcSyncProvConfig
olcOverlay: syncprov
olcSpNoPresent: TRUE

# accesslog overlay definitions for primary db
dn: olcOverlay=accesslog,olcDatabase={1}hdb,cn=config
objectClass: olcOverlayConfig
objectClass: olcAccessLogConfig
olcOverlay: accesslog
olcAccessLogDB: cn=accesslog
olcAccessLogOps: writes
olcAccessLogSuccess: TRUE
# scan the accesslog DB every day, and purge entries older than 7 days
olcAccessLogPurge: 07+00:00 01+00:00

Pas alle domein strings aan! (wordt nog tot script vertimmerd vbs20110919)

Uitbreiding tot slave

In ldap terminologie spreken we van een consumer. De consumer moet precies zo opgezet worden als de provider maar dan zonder de provider specifieke configuratie. Hiervoor in de plaats komt een consumer-specifieke configuratie.

#Load the syncprov module.
dn: cn=module{0},cn=config
changetype: modify
add: olcModuleLoad
olcModuleLoad: syncprov

# syncrepl specific indices
dn: olcDatabase={1}hdb,cn=config
changetype: modify
add: olcDbIndex
olcDbIndex: entryUUID eq
-
add: olcSyncRepl
olcSyncRepl: rid=0 provider=ldap://ldap01.example.com bindmethod=simple binddn="cn=admin,dc=example,dc=com" 
 credentials=secret searchbase="dc=example,dc=com" logbase="cn=accesslog" 
 logfilter="(&(objectClass=auditWriteObject)(reqResult=0))" schemachecking=on 
 type=refreshAndPersist retry="60 +" syncdata=accesslog
-
add: olcUpdateRef
olcUpdateRef: ldap://ldap01.example.com

Met behulp van deze werkende voorbeelden is een script ontwikkeld dat, nadat dpkg-reconfigure heeft gelopen en de /var/lib/ldap/* gewist zijn, alles opnieuw installeert. Voor dit script zie deze pagina: LDAP script.