Benutzer-Werkzeuge

Webseiten-Werkzeuge


ldap

Inhaltsverzeichnis

LDAP (Lighweight Directory Access Protokoll)

Quelle: https://www.codeflow.site/de/article/how-to-install-and-configure-openldap-and-phpldapadmin-on-ubuntu-16-04

<WRAP center round info 60%> Verwendete LDAP-Ports:

Port 389 ungesichert
Port 636 TLS-Verbindungen

</WRAP>

Konfiguration eines openldap-servers unter Centos 7

Centos7 notwendige Pakete installieren

yum install openldap-servers -y

Debian 10.x notwendige Pakete

apt-get install -y slapd slapd-contrib
Originalinhalt der /etc/openldap/ldap.conf
#
# LDAP Defaults
#
 
# See ldap.conf(5) for details
# This file should be world readable but not world writable.
 
#BASE   dc=example,dc=com
#URI    ldap://ldap.example.com ldap://ldap-master.example.com:666
 
#SIZELIMIT      12
#TIMELIMIT      15
#DEREF          never
 
TLS_CACERTDIR   /etc/openldap/certs

# Turning this off breaks GSSAPI used with krb5 when rdns = false
SASL_NOCANON    on
Konfigurationsverzeichnis von Openldap
/etc/openldap

Grundsicherung von slapd.d durchführen

cd /etc/oepnldap
cp -R slapd.d slapd.d.DEFAULT -> Sicherung der Originaldateien
Firewall für LDAP anpassen
firewall-cmd --permanent --zone=lan-1 --add-port=389/tcp
firewall-cmd --permanent --zone=lan-1 --add-port=636/tcp       # SSL/TLS
firewall-cmd --reload

Auf Centos 7 notwendige Pakete installieren

yum install openldap-clients

Grundkonfiguration vornehmen

cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG
cat /var/lib/ldap/DB_CONFIG
Inhalt der /var/lib/ldap/DB_CONFIG
# $OpenLDAP$
# Example DB_CONFIG file for use with slapd(8) BDB/HDB databases.
#
# See the Oracle Berkeley DB documentation
#   <http://www.oracle.com/technology/documentation/berkeley-db/db/ref/env/db_config.html>
# for detail description of DB_CONFIG syntax and semantics.
#
# Hints can also be found in the OpenLDAP Software FAQ
#       <http://www.openldap.org/faq/index.cgi?file=2>
# in particular:
#   <http://www.openldap.org/faq/index.cgi?file=1075>
 
# Note: most DB_CONFIG settings will take effect only upon rebuilding
# the DB environment.
 
# one 0.25 GB cache
set_cachesize 0 268435456 1
 
# Data Directory
#set_data_dir db
 
# Transaction Log settings
set_lg_regionmax 262144
set_lg_bsize 2097152
#set_lg_dir logs
 
# Note: special DB_CONFIG flags are no longer needed for "quick"
# slapadd(8) or slapindex(8) access (see their -q option).
LDAP die notwendigen Rechte auf das Verzeichnis geben
chown ldap:ldap /var/lib/ldap/DB_CONFIG

LDAP-Server slapd starten

systemctl enable slapd 
systemctl start slapd

LDAP Root-Passwort setzen

/usr/sbin/slappasswd -h {SSHA}

# New password:
# Re-enter new password:
# → {SSHA}<verschlüsseltes Passwort> -> MUSS in db.ldif hinter olcRootPW eingetragen werden

LDAP-Server konfigurieren

Dateiendung = LDIF → LDAP Data Interchange Format

cd /etc/openldap
mkdir ldif
cd ldif

vi db.ldif

Inhalt der db.ldif

dn: olcDatabase={2}hdb,cn=config changetype: modify replace: olcSuffix olcSuffix: dc=fritz,dc=box

dn: olcDatabase={2}hdb,cn=config changetype: modify replace: olcRootDN olcRootDN: cn=ldapadm,dc=fritz,dc=box

dn: olcDatabase={2}hdb,cn=config changetype: modify replace: olcRootPW olcRootPW: <generiertes Passwort>

cd /etc/openldap/ldif

db.ldiff zum LDAP-Server hinzufügen
ldapmodify -Y EXTERNAL -H ldapi:/// -f db.ldif

cd /etc/openldap/ldif

vi monitor.ldif
Inhalt der monitor.ldif
 dn: olcDatabase={1}monitor,cn=config
 changetype: modify
 replace: olcAccess
 olcAccess: {0}to * by dn.base="gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth" read by dn.base="cn=ldapadm,dc=fritz,dc=box" read by * none

cd /etc/openldap/ldif

monitor.ldif zum LDAP-Server hinzufügen
ldapmodify -Y EXTERNAL -H ldapi:/// -f monitor.ldif
Schemata cosine, nis und inetorgperson hinzufügen
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/cosine.ldif
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/nis.ldif 
ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/inetorgperson.ldif
vi base.ldif
Inhalt der base.ldif

dn: dc=fritz,dc=box dc: fritz objectClass: top objectClass: domain

dn: cn=ldapadm,dc=fritz,dc=box objectClass: organizationalRole cn: ldapadm description: LDAP Manager

dn: ou=People,dc=fritz,dc=box objectClass: organizationalUnit ou: People

dn: ou=Group,dc=fritz,dc=box objectClass: organizationalUnit ou: Group

base.ldif zum LDAP-Server hinzufügen
ldapadd -x -W -D "cn=ldapadm,dc=fritz,dc=box" -f base.ldif -> mit PW-Abfrage auf STDIN
oder direkt mit PW: ldapadd -x -w <Passwort> -D "cn=ldapadm,dc=fritz,dc=box" -f base.ldif 
Der Inhalt des DIT zur Kontroll ausgeben
slapcat -n2
Ausgabe
dn: dc=fritz,dc=box
dc: fritz
objectClass: top
objectClass: domain
structuralObjectClass: domain
entryUUID: cbeb2cce-e398-103a-8046-b7a24d4664d2
creatorsName: cn=ldapadm,dc=fritz,dc=box
createTimestamp: 20210105115631Z
entryCSN: 20210105115631.993944Z#000000#000#000000
modifiersName: cn=ldapadm,dc=fritz,dc=box
modifyTimestamp: 20210105115631Z

dn: cn=ldapadm,dc=fritz,dc=box
objectClass: organizationalRole
cn: ldapadm
description: LDAP Manager
structuralObjectClass: organizationalRole
entryUUID: cbebc454-e398-103a-8047-b7a24d4664d2
creatorsName: cn=ldapadm,dc=fritz,dc=box
createTimestamp: 20210105115631Z
entryCSN: 20210105115631.997820Z#000000#000#000000
modifiersName: cn=ldapadm,dc=fritz,dc=box
modifyTimestamp: 20210105115631Z

dn: ou=People,dc=fritz,dc=box
objectClass: organizationalUnit
ou: People
structuralObjectClass: organizationalUnit
entryUUID: cbec285e-e398-103a-8048-b7a24d4664d2
creatorsName: cn=ldapadm,dc=fritz,dc=box
createTimestamp: 20210105115632Z
entryCSN: 20210105115632.000384Z#000000#000#000000
modifiersName: cn=ldapadm,dc=fritz,dc=box
modifyTimestamp: 20210105115632Z

dn: ou=Group,dc=fritz,dc=box
objectClass: organizationalUnit
ou: Group
structuralObjectClass: organizationalUnit
entryUUID: cbecae32-e398-103a-8049-b7a24d4664d2
creatorsName: cn=ldapadm,dc=fritz,dc=box
createTimestamp: 20210105115632Z
entryCSN: 20210105115632.003810Z#000000#000#000000
modifiersName: cn=ldapadm,dc=fritz,dc=box
modifyTimestamp: 20210105115632Z

Bei einem Fehler DIT (Directory information tree) zurücksetzen

systemctl stop slapd 

rm -rf /var/lib/ldap

mkdir /var/lib/ldap

cp /usr/share/openldap-servers/DB_CONFIG.example /var/lib/ldap/DB_CONFIG

chown -R ldap:ldap /var/lib/ldap

cd /etc/openldap

rm -rf slapd.d
cp -R slapd.d.DEFAULT slapd.d
chown -R ldap:ldap slapd.d

systemctl start slapd

Changing the RootDN Password

LDAP Benutzerkonto Hans hinzufügen
vi /etc/openldap/ldif/user_hans.ldif
Inhalt der user_hans.ldif
dn: uid=hans,ou=People,dc=Fritz,dc=box
objectClass: top
objectClass: account
objectClass: posixAccount
objectClass: shadowAccount
cn: hans
uid: hans
uidNumber: 9999
gidNumber: 100
homeDirectory: /home/hans
loginShell: /bin/bash
gecos: hans [Admin (at) Fritz]
userPassword: {crypt}x
shadowLastChange: 17058
shadowMin: 0
shadowMax: 99999
shadowWarning: 7
Datei /etc/openldap/ldif/user_hans.ldif dem LDAP-Server hinzufügen
ldapadd -x -W -D "cn=ldapadm,dc=fritz,dc=box" -f /etc/openldap/ldif/user_hans.ldif
Passwort für LDAP-Benutzer hans setzen
ldappasswd -s <PASSWORT> -W -D "cn=ldapadm,dc=fritz,dc=box" -x "uid=hans,ou=People,dc=fritz,dc=box"
Ein LDAP Benutzerkonto meier hinzufügen
vi /etc/openldap/ldif/user_meier.ldif
Inhalt der Datei /etc/openldap/ldif/user_meier.ldif
dn: uid=meier,ou=Group,dc=fritz,dc=box
objectClass: top
objectClass: account
objectClass: posixAccount
objectClass: shadowAccount
cn: meier
uid: meier
uidNumber: 9998
gidNumber: 101
homeDirectory: /home/meier
loginShell: /bin/bash
gecos: meier [Admin (at) fritz]
userPassword: {crypt}x
shadowLastChange: 17058
shadowMin: 0
shadowMax: 99999
shadowWarning: 7
User meier der Domain fritz.box hinzufügen
ldapadd -x -W -D "cn=ldapadm,dc=fritz,dc=box" -f /etc/openldap/ldif/user_meier.ldif
Ein Passwort für LDAP-Benutzer meier setzen
ldappasswd -s <PASSWORT> -W -D "cn=ldapadm,dc=fritz,dc=box" -x "uid=meier,ou=Group,dc=fritz,dc=box"
LDAP Eintrag überprüfen
ldapsearch -x cn=meier -b dc=fritz,dc=box

How To Change Account Passwords on an OpenLDAP Server: //www.digitalocean.com/community/tutorials/how-to-change-account-passwords-on-an-openldap-server OpenLDAP using OLC (cn=config): use-security

LogLevel für openldap konfigurieren

vi /etc/openldap/ldif/loglevel.ldif
Inhalt der Datei /etc/openldap/ldif/loglevel.ldif
dn: cn=config
changetype: modify
add: olcLogLevel
olcLogLevel: <LOGLEVEL> # z. B -1 (any 	enable all debugging ) oder 0 (no debugging

Level Keyword Description


-1 any enable all debugging 0 no debugging 1 (0x1 trace) trace function calls 2 (0x2 packets) debug packet handling 4 (0x4 args) heavy trace debugging 8 (0x8 conns) connection management 16 (0x10 BER) print out packets sent and received 32 (0x20 filter) search filter processing 64 (0x40 config) configuration processing 128 (0x80 ACL) access control list processing 256 (0x100 stats) stats log connections/operations/results 512 (0x200 stats2) stats log entries sent 1024 (0x400 shell) print communication with shell backends 2048 (0x800 parse) print entry parsing debugging 16384 (0x4000 sync) syncrepl consumer processing 32768 (0x8000 none) only messages that get logged whatever log level is set

–> Die Loglevel sind mischbar, als z. B. 129= Loglevel 1 + Loglevel 128

== Datei /etc/openldap/ldif/loglevel.ldif der LDAP-Domäne hinzufügen:

cd /etc/openldap/ldif
ldapmodify -Y EXTERNAL -H ldapi:/// -f loglevel.ldif

LDAP-Client Konfiguration:

Doku: https://www.digitalocean.com/community/tutorials/how-to-use-ldif-files-to-make-changes-to-an-openldap-system

Debian 10.x: ldap-client Paket installieren

apt install ldapscripts

LDAP-Server Einträge anpassen

ldap.conf anpassen
cp /etc/ldap/ldap.conf /etc/ldap.conf.<YYYYMMDDSSMM>
vi /etc/ldap/ldap.conf
Folgende Einträge inder Datei /etc/ldap/ldap.conf anpassen
→ BASE    dc=fritz,dc=box
→ URI     ldap://ldap.fritz.box
ldapsearch ausführen
wenn die Werte in der /etc/ldap.conf nicht gesetzt sind mit:
  ldapsearch -H ldap://ldap.fritz.box -b "dc=fritz,dc=box" -D "cn=ldapadm,dc=fritz,dc=box" "uid=hans" -x -w <Passwort>
sonst mit:
  ldapsearch -x -LLL uid=hans
Ausgabe
dn: uid=hans,ou=People,dc=fritz,dc=box
objectClass: top
objectClass: account
objectClass: posixAccount
objectClass: shadowAccount
cn: hans
uid: hans
uidNumber: 9999
gidNumber: 100
homeDirectory: /home/hans
loginShell: /bin/bash
gecos: hans [Admin (at) Fritz]
shadowLastChange: 17058
shadowMin: 0
shadowMax: 99999
shadowWarning: 7
userPassword:: e1NTSEF9Q1hTdmlqYkdJUjRjZEpHRHBYRTZoVHkwYzd0VzlxQ00=

dn: uid=meier,ou=Group,dc=fritz,dc=box
objectClass: top
objectClass: account
objectClass: posixAccount
objectClass: shadowAccount
cn: hans
uid: hans
uid: meier
uidNumber: 9998
gidNumber: 100
homeDirectory: /home/meier
loginShell: /bin/bash
gecos: meier [Admin (at) Fritz]
shadowLastChange: 17058
shadowMin: 0
shadowMax: 99999
shadowWarning: 7
userPassword:: e1NTSEF9Nkg2M2d2T2gzbHpRNUdCYU16OVlVTHJNdWw2WjVLcU8=

Bestehende LDAP-Einträge ändern

Datei /etc/openldap/ldif/user_meier.ldif erstellen
mkdir -p /etc/openldap/ldif
vi /etc/openldap/ldif/user_meier.ldif  
Inhalt der neu angelegten Datei /etc/openldap/ldif/user_meier.ldif
dn: uid=meier,ou=Group,dc=fritz,dc=box
changetype: modify
replace: gidNumber
gidNumber: 101  
ldapmodify ausführen
ldapmodify -x -D "cn=ldapadm,dc=fritz,dc=box" -W -f user_meier.ldif  -> Es kommt eine Passwortabfrage (LDAP-Admin)

Bestehende LDAP-Einträge löschen

ldapdelete ausführen
	# mit Passwortabfrage
	ldapdelete -x -D "cn=ldapadm,dc=fritz,dc=box" -W "uid=meier,ou=Group,dc=fritz,dc=box" 

	# ohne Passwortabfrage
	ldapdelete -x -D "cn=ldapadm,dc=fritz,dc=box" -w <Passwort> "uid=meier,ou=Group,dc=fritz,dc=box" 

LDAP Browser/Editor: Quelle: https://community.microfocus.com/t5/Identity-Manager-Tips/Jarek-Gawor-s-excellent-LDAP-Browser-Editor-v2-8-2/ta-p/1771772

LDAP Logs nach /var/log/slapd schreiben
cd /etc
cp rsyslogd.conf rsyslogd.conf.<YYYYMMDD>
vi rsyslogd.conf
Folgende Zeile an die /etc/rsyslogd.conf anhängen
# LOCAL4 Standardwert für syslog facility
local4.*     /var/log/slapd.log    

syslogd neu starten:

systemctl restart rsyslog

LDAP-Tools, Datenbank slapd darf nicht laufen:

slapcat -l <Dateiname> -> Gesamtkopie der Datenbank als .ldif-file

Standard-Zugriffsberechtigungen bei LDAP:

access to <was> by <wer> <Zugriffsart> -> Standard: access to * by * read

Genutzte Befehle bei laufenden sdapd:

ldappasswd
ldapadd
ldapdelete

add.ldif Beispieldatei:

dn: uid=meier,ou=Group,dc=fritz,dc=box
changtype: modify
add: mail
mail: meinemail@gmail.com
ldapsearch
Beispielsuche:
ldapsearch -x -LLL -uid=hans
das 1. L beschränkt die Ausgabe der Kommentar
das 2. L verhindert die Ausgabe der LDAP-Version
-> mit der Option -b kann man die Base für die Baumsuche angeben.

PAM-Authentifizierung

<WRAP center round info 60%> PAM: Module unter /lib/security (/lib64/security) </WRAP>

Wichtige PAM Module
pam_unix nutzt die Dateien /etc/passwd und /etc/shadow,
pam_cracklib -> Sicherheit des neu gewählten Passworts prüfen
pam_limits -> Arbeitsspeicher und CPU-Zeit eines Benutzers limitieren
pam_listfile -> Listen nutzen, um den Zugriff zu verweigern oder zu erlauben

<WRAP center round important 60%> Wenn der Ordner /etc/pam.d/ exisiert wird die Datei /etc/pam.conf ignoriert </WRAP>

Centos 7 - PAM konfigurieren

Quelle: https://tylersguides.com/guides/configuring-openldap-authentication-centos-7/

Centos 7: Notwendige Module installieren:

yum install nss-pam-ldapd -y

Modul “nss-pam-ldapd” konfigurieren:

cd /etc
cp nslcd.conf nslcd.conf.DEFAULT
vi nslcd.conf -> die Einstellungen für den LDAP-Server

Folgende Einträge ändern/ergänzen inder /etc/nslcd.conf:

uri ldap://ldap.fritz.box
base dc=fritz,dc=box
base passwd ou=People,dc=fritz,dc=box
base shadow ou=People,dc=fritz,dc=box
base group ou=Group,dc=fritz,dc=box

LDAP-Dienst in den Autostart aufnehmen und starten:

systemctl enable nslcd
systemctl start nslcd

PAM für LDAP-Unterstützung konfigurieren (LOGIN)

authconfig --updateall --enableldap --enableldapaut

Debian 10: PAM für LDAP konfigurieren

Doku: https://wiki.debian.org/LDAP/PAM

Notwendige Pakete installieren:

apt install libnss-ldapd -y

Ldap authentication aktivieren

 pam-auth-update --enable ldap --enable ldapauth
 sufficient → [success=done new_authtok_reqd=done default=ignore]

Automatische Anlage des Homedirs für neue LDAP-User

Damit für einem neuen LDAP-User auch das Homedir automatngelegt wird, folgende Zeile in /etc/pam.d/login einfügen:

 session required pam_mkhomedir.so skel=/etc/skel umask=0222

User-Login bei Desktop Umgebungen über LDAP ermöglichen

In die Datei /etc/pam.d/gdm folgende Zeile hinzufügen:

session required pam_mkhomedir.so skel=/etc/skel umask=0222

Windows-Anmeldung über LDAP-Server

Windows-PC LDAP-Anmeldung: siehe Open-Source-Software

PAM Authentifizierung über SSSD

Konfigurationsdatei:

/etc/sssd.conf

Inhalt der sssd.conf:

[domain/fritz.box]
   autofs_provider = ldap
   cache_credentials = False
   ldap_search_base = dc=fritz,dc=box
   id_provider = ldap
   auth_provider = ldap
   chpass_provider = ldap
   ldap_uri = ldap://ldap.fritz.box:389
   ldap_id_use_start_tls = False
   ldap_tls_cacertdir = /etc/openldap/cacerts
   ldap_schema = rfc2307bis
   ldap_auth_disable_tls_never_use_in_production = true
   use_fully_qualified_names = True

[sssd]
   config_file_version = 2
   reconnection_retries = 3
   sbus_timeout = 30
   services = nss, pam
   domains = fritz.box
 
[nss]
   filter_groups = root
   filter_users = root
   reconnection_retries = 3
   entry_cache_timeout = 300
   entry_cache_nowait_percentage = 75
 
[pam]
   reconnection_retries = 3
   offline_credentials_expiration = 2
   offline_failed_login_attempts = 3
   offline_failed_login_delay = 5
[autofs]
ldap.txt · Zuletzt geändert: 2021/01/12 22:38 von mho

Falls nicht anders bezeichnet, ist der Inhalt dieses Wikis unter der folgenden Lizenz veröffentlicht: Public Domain
Public Domain Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki