LDAP

From Hobbynet Admin Wiki
Jump to navigation Jump to search

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.