Was ist die Baron Münchhausen Universität?

Zuerst einmal ist die Baron Münchhausen Universität eines nicht: Eine real existierende Universität. (Das für die, die das noch nicht am Namen abgeleitet haben.) Viel mehr ist die Baron Münchhausen Universität oder BM Uni ein Projekt für den ⧉ HPCTech YouTube Kanal - und hier auf der Website findet Ihr Codeschnipsel und andere Textformate zum Nachlesen und Kopieren.

Code

Da wir Open-Source-Fans sind, steht der gesamte Code unter der CC BY-SA 4.0 und darf entsprechend weiterverwendet werden. Der Unterbau zu dieser Website findet sich im ⧉ zugehörigen GitHub Repository.

Impressum und Hinweise

Das Impressum der ⧉ Menzel IT GmbH, die hinter dem Projekt steht, findet Ihr ⧉ hier verlinkt. Der Kanal HPCTech wird übrigens von unserer Schwestergesellschaft ⧉ Dreieinhalb Medien umgesetzt.

Datenschutzhinweis

Es gelten die ⧉ Datenschutzhinweise der Menzel IT GmbH. Sämtliche Videolinks führen zu YouTube, sodass Daten an YouTube/google übertragen werden. Deren Datenschutzerklärungen findet Ihr ⧉ hier.

Personen an der Uni

LDAP und Kerberos

In dieser kleinen Videoreihe beschäftigen wir uns mit dem Aufbau einer Benutzer- und Authentifikationsdatenbank auf Basis von LDAP und Kerberos. Es gibt derzeit folgende Videos:

Wichtig: Alle Videolinks führen von dieser Seite weg zu YouTube!

Staffel 1

  1. Einführung (Code, Video)
  2. Aufbau des LDAP-Servers (Code und Infos, Video)
  3. ACLs (Code und Infos, Video)
  4. LDAP-Account-Manager(Code und Infos, Video)
  5. Anbindung Nextcloud (Code und Infos, Video)
  6. Anbindung Ubuntu und Telefone (Code und Infos, Video)

Staffel 2

  1. Servertuning I, Overlays
  2. Servertuning II, eigene Attribute und Klassen
  3. Kerberos-Server
  4. Kerberos-Clientanbindung

Literatur

Natürlich möchten wir Euch auch weitere Literatur zu dem Thema nicht vorenthalten:

  1. Das insgesamt sehr gute Buch ⧉ Linux-Server aus dem Rheinwerk Verlag beinhaltet auch einiges zum Thema LDAP und Kerberos.
  2. Kerberos aus dem dpunkt Verlag.
  3. openLDAP in der Praxis aus dem Hanser Verlag.

LDAP 01 | Einführung

Zum ersten Video gibt es leider keinen Code.

LDAP 02 | Einrichtung des Servers

WICHTIG: Alle Kommandos werden als root-User ausgeführt!

Optionale Vorbereitung

Das war im Video bereits passiert.

ufw allow ssh
ufw enable

Einrichtung des Hostnames

hostname="ldap.bm-uni.de"
hostnameShort=$(echo $hostname | cut -d "." -f1)
hostnamectl set-hostname $hostnameShort
sed -i "s/^127.0.1.1.*/127.0.1.1 $hostname $hostnameShort/g" /etc/hosts
bash
cat /etc/hosts

Setzen der Variablen

basedn="dc=bm-uni,dc=de"
admindn="cn=admin,$basedn"
adminpwd="hpctech1!"
echo -e "\$basedn:\t$basedn\n\$admindn:\t$admindn\n\$adminpwd:\t$adminpwd"

Installation

apt install slapd

Umzug auf statische Konfiguration

systemctl stop slapd
sed -i "s/SLAPD_CONF=.*/SLAPD_CONF=\/etc\/ldap\/slapd.conf/g" /etc/default/slapd
cat /etc/default/slapd
rm /var/lib/ldap/*.mdb

Initiale Konfiguration

adminpwdHash=$(slappasswd -h {SSHA} -s $adminpwd)

cat <<EOF >/etc/ldap/slapd.conf
# Schemata und Objektklassen
include         /etc/ldap/schema/core.schema
include         /etc/ldap/schema/cosine.schema
include         /etc/ldap/schema/inetorgperson.schema
include         /etc/ldap/schema/nis.schema
# Loglevel - 256 ist ein guter Mittelwert
# NICHT auf 0 setzen, da sonst gar nichts geloggt wird!
# https://www.openldap.org/doc/admin24/slapdconfig.html
loglevel        256
pidfile         /var/run/slapd/slapd.pid
argsfile        /var/run/slapd/slapd.args
modulepath      /usr/lib/ldap
moduleload      back_mdb
# Maximal 1000 Werte bei einer Suche zurück geben
sizelimit 1000
# Anzahl CPUs, die für das Indexing verwendet werden
tool-threads 2
#######################################################################
# Datenbank Nummer 1
database        mdb
# Der Basis-DN
suffix          "$basedn"
# Root-User
rootdn          "$admindn"
rootpw          "$adminpwdHash"
# Ablageort der Datenbank
directory       "/var/lib/ldap"
# Indices
index           objectClass eq
# Letzte Modifikation der Datenbank schreiben
lastmod         on
# Access Control Lists
access to attrs=userPassword,shadowLastChange
    by dn="$admindn" write
    by anonymous auth
    by self write
    by * none
access to *
    by dn="$admindn" write
    by * read
access to dn.base=""
    by * read
EOF
less /etc/ldap/slapd.conf
systemctl start slapd
systemctl status slapd

Erste Daten

ldapsearch -x -D "$admindn" -b $basedn -w $adminpwd

cat <<EOF >/tmp/groups-and-users.ldif
# Base erstellen
dn: $basedn
objectClass: dcObject
objectClass: organization
o: fiktive Baron Münchhausen Universität
dc: bm-uni

# Gruppen erstellen
dn: ou=groups,$basedn
ou: groups
objectClass: top
objectClass: organizationalUnit

# User erstellen
dn: ou=users,$basedn
ou: users
objectClass: top
objectClass: organizationalUnit
EOF
cat /tmp/groups-and-users.ldif

ldapadd -x -D "$admindn" -w $adminpwd -f /tmp/groups-and-users.ldif
ldapsearch -x -D "$admindn" -b $basedn -H "ldap://ldap.bm-uni.de" -w $adminpwd
echo "ZmlrdGl2ZSBCYXJvbiBNw7xuY2hoYXVzZW4gVW5pdmVyc2l0w6R0\n" | base64 -d

cat <<EOF >/tmp/posixGruppe-und-studis.ldif
# posixGruppe anlegen
dn: cn=posixGruppe,ou=groups,$basedn
cn: posixGruppe
objectClass: top
objectClass: posixGroup
gidNumber: 10000
EOF

erwinPassword=$(slappasswd -h {SSHA} -s "3rw1n3rst13")
noraPassword=$(slappasswd -h {SSHA} -s "Zi%iY8hua4coe0ain8sho!p7")
siegfriedPassword=$(slappasswd -h {SSHA} -s "daStehIchNunIchArmerToR!")
cat <<EOF >>/tmp/posixGruppe-und-studis.ldif
# Erwin Erstie anlegen
dn: uid=e.erstie,ou=users,$basedn
objectClass: top
objectClass: inetorgperson
objectClass: posixAccount
objectClass: shadowAccount
cn: Erwin Erstie
sn: Erstie
uid: e.erstie
uidNumber: 10000
gidNumber: 10000
homeDirectory: /home/e.erstie
loginShell: /bin/bash
userPassword: $erwinPassword
shadowLastChange: 0
shadowMax: 0
shadowWarning: 0

# Nora Nieda anlegen
dn: uid=n.nieda,ou=users,$basedn
objectClass: top
objectClass: inetorgperson
objectClass: posixAccount
objectClass: shadowAccount
cn: Nora Nieda
sn: Nieda
uid: n.nieda
uidNumber: 10001
gidNumber: 10000
homeDirectory: /home/n.nieda
loginShell: /bin/zsh
userPassword: $noraPassword
shadowLastChange: 0
shadowMax: 0
shadowWarning: 0

# Siegfried von Säusel anlegen
dn: uid=s.saeusel,ou=users,$basedn
objectClass: top
objectClass: inetorgperson
objectClass: posixAccount
objectClass: shadowAccount
cn: Siegfried von Säusel
sn: Siegfried
uid: s.saeusel
uidNumber: 10002
gidNumber: 10000
homeDirectory: /home/s.saeusel
loginShell: /bin/bash
userPassword: $siegfriedPassword
shadowLastChange: 0
shadowMax: 0
shadowWarning: 0
EOF

ldapadd -x -H "ldap://ldap.bm-uni.de" -D "$admindn" -w $adminpwd -f /tmp/posixGruppe-und-studis.ldif

Suchen

ldapsearch -x -H "ldap://ldap.bm-uni.de" -b $basedn -D "uid=e.erstie,ou=users,$basedn" -W
ldapsearch -x -H "ldap://ldap.bm-uni.de" -b $basedn -D "$admindn" -w $adminpwd "(uid=e.erstie)" uidNumber
ldapsearch -x -LLL -H "ldap://ldap.bm-uni.de" -b $basedn -D "$admindn" -w $adminpwd "(uid=e.erstie)" uidNumber
ldapsearch -x -LLL -H "ldap://ldap.bm-uni.de" -b $basedn -D "$admindn" -w $adminpwd "(cn=*Erstie*)" uid cn
ldapsearch -x -LLL -H "ldap://ldap.bm-uni.de" -b $basedn -D "$admindn" -w $adminpwd "(gidNumber=10000)" uid loginShell
ldapsearch -x -LLL -H "ldap://ldap.bm-uni.de" -b $basedn -D "$admindn" -w $adminpwd "(&(gidNumber=10000)(loginShell=/bin/zsh))" uid cn

LDAPS

Hinweis: Keys müsst Ihr selber besorgen!

ll /etc/ldap/*.pem
chown openldap /etc/ldap/ldapkey.pem
chmod 600 /etc/ldap/ldapkey.pem
ll /etc/ldap/*.pem

sed -i '/^tool-threads*/a TLSCertificateKeyFile \/etc\/ldap\/ldapkey.pem' /etc/ldap/slapd.conf
sed -i '/^tool-threads*/a TLSCertificateFile \/etc\/ldap\/ldapcert.pem' /etc/ldap/slapd.conf
sed -i '/^tool-threads*/a # SSL Certs' /etc/ldap/slapd.conf

cat /etc/ldap/slapd.conf

sed -i 's/SLAPD_SERVICES=.*/SLAPD_SERVICES="ldapi:\/\/\/ ldaps:\/\/\/"/g' /etc/default/slapd
systemctl restart slapd
ss -tlpn

ldapsearch -x -LLL -H "ldap://ldap.bm-uni.de" -b $basedn -D "$admindn" -w $adminpwd "(cn=*Erstie*)" uid cn
ldapsearch -x -LLL -H "ldaps://ldap.bm-uni.de" -b $basedn -D "$admindn" -w $adminpwd "(cn=*Erstie*)" uid cn

Firewall einstellen

ufw allow ldaps
ufw deny ldap
ufw status

LDAP 03 | Einrichtung von ACLs

WICHTIG: Alle Kommandos werden als root-User ausgeführt!

Nutzernamen POSIX-compliant machen

cat <<EOF >/tmp/modify-users.ldif
#uid ändern
dn: uid=s.saeusel,ou=users,$basedn
changetype: modrdn
newrdn: uid=ssaeusel
deleteoldrdn: 1

#home
dn: uid=ssaeusel,ou=users,$basedn
changetype: modify
replace: homeDirectory
homeDirectory: /home/ssauesel

#mail
dn: uid=ssaeusel,ou=users,$basedn
changetype: modify
add: mail
mail: ssauesel@stud.${domain}

#password
dn: uid=ssaeusel,ou=users,$basedn
changetype: modify
delete: userPassword
EOF

cat <<EOF >>/tmp/modify-users.ldif
#uid ändern
dn: uid=n.nieda,ou=users,$basedn
changetype: modrdn
newrdn: uid=nnieda
deleteoldrdn: 1

#mail
dn: uid=nnieda,ou=users,$basedn
changetype: modify
add: mail
mail: nnieda@stud.${domain}

#home
dn: uid=nnieda,ou=users,$basedn
changetype: modify
replace: homeDirectory
homeDirectory: /home/nnieda

#uid ändern
dn: uid=e.erstie,ou=users,$basedn
changetype: modrdn
newrdn: uid=eerstie
deleteoldrdn: 1

#home
dn: uid=eerstie,ou=users,$basedn
changetype: modify
replace: homeDirectory
homeDirectory: /home/eerstie

#mail
dn: uid=eerstie,ou=users,$basedn
changetype: modify
add: mail
mail: eerstie@stud.${domain}
EOF

ldapmodify -x -H "ldaps://ldap.bm-uni.de" -D "$admindn" -w $adminpwd -f /tmp/modify-users.ldif
ldapsearch -x -LLL -H "ldaps://ldap.bm-uni.de" -b ou=users,$basedn -D "$admindn" -w $adminpwd uid homeDirectory mail userPassword

Weitere organizational units vorbereiten

cat <<EOF >/tmp/further-units-and-users.ldif
# binduser
dn: ou=binduser,$basedn
ou: binduser
objectClass: top
objectClass: organizationalUnit

# projects
dn: ou=projects,$basedn
ou: projects
objectClass: top
objectClass: organizationalUnit

EOF

Weitere Nutzer anlegen und eintragen

adamPassword="adam"
ingoPassword="ingo"
wiebkePassword="wiebke"
cat <<EOF >>/tmp/further-units-and-users.ldif
# Adam Assistent
dn: uid=aassistent,ou=users,$basedn
objectClass: top
objectClass: inetorgperson
objectClass: posixAccount
objectClass: organizationalPerson
objectClass: shadowAccount
cn: Adam Assistent
sn: Assistent
givenName: Adam
uid: aassistent
mail: aassistent@${domain}
telephoneNumber: +49 30 23125 - 105
uidNumber: 10003
gidNumber: 10000
homeDirectory: /home/aassistent
loginShell: /bin/bash
userPassword: $(slappasswd -h {SSHA} -s $adamPassword)
shadowLastChange: 0
shadowMax: 0
shadowWarning: 0

# Ingo Ingenieur
dn: uid=iingenieur,ou=users,$basedn
objectClass: top
objectClass: inetorgperson
objectClass: posixAccount
objectClass: organizationalPerson
objectClass: shadowAccount
cn: Prof. Ingo Ingenieur
sn: Ingenieur
givenName: Ingo
uid: iingenieur
mail: iingenieur@${domain}
telephoneNumber: +49 30 23125 - 102
uidNumber: 10005
gidNumber: 10000
homeDirectory: /home/iingenieur
loginShell: /bin/bash
userPassword: $(slappasswd -h {SSHA} -s $ingoPassword)
shadowLastChange: 0
shadowMax: 0
shadowWarning: 0

# Wiebke Wimi
dn: uid=wwimi,ou=users,$basedn
objectClass: top
objectClass: inetorgperson
objectClass: posixAccount
objectClass: organizationalPerson
objectClass: shadowAccount
cn: Wiebke Wimi
sn: Wimi
givenName: Wiebke
uid: wwimi
mail: wwimi@${domain}
telephoneNumber: +49 30 23125 - 212
uidNumber: 10010
gidNumber: 10000
homeDirectory: /home/wwimi
loginShell: /bin/bash
userPassword: $(slappasswd -h {SSHA} -s $wiebkePassword)
shadowLastChange: 0
shadowMax: 0
shadowWarning: 0
EOF

ldapadd -x -H "ldaps://ldap.bm-uni.de" -D "$admindn" -w $adminpwd -f /tmp/further-units-and-users.ldif
ldapsearch -x -H "ldaps://ldap.bm-uni.de" -b $basedn -D "uid=wwimi,ou=users,$basedn" -w $wiebkePassword "(uid=wwimi)"

RFC2307bis einrichten

wget -P /etc/ldap/schema https://raw.githubusercontent.com/jtyr/rfc2307bis/master/rfc2307bis.schema
sed -i "s/nis.schema/rfc2307bis.schema/" /etc/ldap/slapd.conf
head /etc/ldap/slapd.conf
systemctl restart slapd
systemctl status slapd

Weitere Gruppen anlegen

cat <<EOF >/tmp/groups.ldif
dn: cn=professors,ou=groups,$basedn
cn: professors
objectClass: top
objectClass: groupOfNames
objectClass: posixGroup
gidNumber: 10001
member: uid=iingenieur,ou=users,$basedn

dn: cn=research-assistants,ou=groups,$basedn
cn: research-assistants
objectClass: top
objectClass: groupOfNames
objectClass: posixGroup
gidNumber: 10002
member: uid=wwimi,ou=users,$basedn

dn: cn=administration,ou=groups,$basedn
cn: administration
objectClass: top
objectClass: groupOfNames
objectClass: posixGroup
gidNumber: 10003
member: uid=aassistent,ou=users,$basedn

dn: cn=students,ou=groups,$basedn
cn: students
objectClass: top
objectClass: groupOfNames
objectClass: posixGroup
gidNumber: 10004
member: uid=eerstie,ou=users,$basedn
member: uid=nnieda,ou=users,$basedn
member: uid=ssaeusel,ou=users,$basedn
EOF

ldapadd -x -H "ldaps://ldap.bm-uni.de" -D "$admindn" -w $adminpwd -f /tmp/groups.ldif
ldapsearch -x -LLL -H "ldaps://ldap.bm-uni.de" -b ou=groups,$basedn cn gidNumber member

ldapcompare

ldapcompare -H "ldaps://ldap.bm-uni.de" -D "$admindn" -w $adminpwd "cn=posixGruppe,ou=groups,$basedn" gidNumber:100000
ldapcompare -H "ldaps://ldap.bm-uni.de" -D "$admindn" -w $adminpwd "cn=posixGruppe,ou=groups,$basedn" gidNumber:10000

bisherige ACLs auslagern

ldapsearch -x -LLL -H "ldaps://ldap.bm-uni.de" -b ou=users,$basedn -D "uid=wwimi,ou=users,$basedn" -w $wiebkePassword userPassword

tail -n 11 /etc/ldap/slapd.conf

cat <<EOF >/etc/ldap/acl.conf
# Access Control Lists
access to attrs=userPassword,shadowLastChange
    by dn="cn=admin,$basedn" write
    by anonymous auth
    by self write
    by * none
access to *
    by dn="cn=admin,$basedn" write
    by * read
access to dn.base=""
    by * read
EOF
head -n -10 /etc/ldap/slapd.conf > /etc/ldap/slapd.tmp.conf && mv /etc/ldap/slapd.tmp.conf /etc/ldap/slapd.conf
cat <<EOF >>/etc/ldap/slapd.conf
include         /etc/ldap/acl.conf
EOF
systemctl restart slapd
ldapsearch -x -LLL -H "ldaps://ldap.bm-uni.de" -b ou=users,$basedn -D "uid=wwimi,ou=users,$basedn" -w $wiebkePassword userPassword

dirty test: ACLs vertauschen

Einmal hin...

cat <<EOF >/etc/ldap/acl.conf
# Access Control Lists
access to *
    by dn="cn=admin,$basedn" write
    by * read
access to attrs=userPassword,shadowLastChange
    by dn="cn=admin,$basedn" write
    by anonymous auth
    by self write
    by * none
access to dn.base=""
    by * read
EOF
systemctl restart slapd
ldapsearch -x -LLL -H "ldaps://ldap.bm-uni.de" -b ou=users,$basedn -D "uid=wwimi,ou=users,$basedn" -w $wiebkePassword userPassword

... einmal her:

cat <<EOF >/etc/ldap/acl.conf
# Access Control Lists
access to attrs=userPassword,shadowLastChange
    by dn="cn=admin,$basedn" write
    by anonymous auth
    by self write
    by * none
access to *
    by dn="cn=admin,$basedn" write
    by * read
access to dn.base=""
    by * read
EOF
systemctl restart slapd
ldapsearch -x -LLL -H "ldaps://ldap.bm-uni.de" -b ou=users,$basedn -D "uid=wwimi,ou=users,$basedn" -w $wiebkePassword userPassword

unsere ACLs aufbauen und testen


cat <<EOF >/etc/ldap/acl.conf
access to dn.base="$basedn" by * read

access to attrs=userPassword,shadowLastChange
        by anonymous auth
        by self write
        by group.exact="cn=administration,ou=groups,$basedn" write
        by * none

access to dn.subtree="ou=binduser,$basedn"
        by group.exact="cn=administration,ou=groups,$basedn" write
        by * none

access to dn.subtree="ou=groups,$basedn"
        by group.exact="cn=administration,ou=groups,$basedn" write
        by group.exact="cn=professors,ou=groups,$basedn" write
        by dn.one="ou=binduser,$basedn" read
        by * none

access to dn.subtree="ou=users,$basedn"
        by group.exact="cn=administration,ou=groups,$basedn" write
        by group.exact="cn=professors,ou=groups,$basedn" write
        by dn.one="ou=binduser,$basedn" read
        by self read
        by * none

access to * by * none
EOF
cat /etc/ldap/acl.conf
systemctl restart slapd
ldapsearch -x -LLL -H "ldaps://ldap.bm-uni.de" -b $basedn
ldapsearch -x -LLL -H "ldaps://ldap.bm-uni.de" -b $basedn -D "uid=wwimi,ou=users,$basedn" -w $wiebkePassword
ldapsearch -x -LLL -H "ldaps://ldap.bm-uni.de" -b $basedn -D "uid=aassistent,ou=users,$basedn" -w $adamPassword dn
ldapsearch -x -LLL -H "ldaps://ldap.bm-uni.de" -b $basedn -D "uid=iingenieur,ou=users,$basedn" -w $ingoPassword dn
ldapsearch -x -LLL -H "ldaps://ldap.bm-uni.de" -b "ou=users,$basedn" -D "uid=iingenieur,ou=users,$basedn" -w $ingoPassword dn userPassword
ldapsearch -x -LLL -H "ldaps://ldap.bm-uni.de" -b "ou=users,$basedn" -D "uid=aassistent,ou=users,$basedn" -w $adamPassword dn userPassword

Testbinder einfügen

testbinderPassword="testbinder"
cat <<EOF >/tmp/binder.ldif
# Testbinder
dn: cn=testbinder,ou=binduser,$basedn
objectClass: organizationalRole
objectClass: simpleSecurityObject
cn: testbinder
userPassword: $(slappasswd -h {SSHA} -s $testbinderPassword)
description: "Demo-Binder, angelegt am $(date)"
EOF

ldapadd -x -H "ldaps://ldap.bm-uni.de" -D "uid=aassistent,ou=users,$basedn" -w $adamPassword -f /tmp/binder.ldif
ldapsearch -x -LLL -H "ldaps://ldap.bm-uni.de" -b "ou=binduser,$basedn" -D "uid=aassistent,ou=users,$basedn" -w $adamPassword
ldapsearch -x -LLL -H "ldaps://ldap.bm-uni.de" -b $basedn -D "cn=testbinder,ou=binduser,$basedn" -w $testbinderPassword dn userPassword

Wiebe wird Admin

ldapsearch -x -LLL -H "ldaps://ldap.bm-uni.de" -b $basedn -D "uid=wwimi,ou=users,$basedn" -w $wiebkePassword dn userPassword

cat <<EOF >/tmp/wiebke-admin.ldif
# Wiebke soll Admin werden
dn: cn=administration,ou=groups,$basedn
changetype: modify
add: member
member: uid=wwimi,ou=users,$basedn

EOF
cat /tmp/wiebke-admin.ldif

ldapmodify -x -H "ldaps://ldap.bm-uni.de" -D "uid=iingenieur,ou=users,$basedn" -w $ingoPassword -f /tmp/wiebke-admin.ldif
ldapsearch -x -LLL -H "ldaps://ldap.bm-uni.de" -b $basedn -D "uid=wwimi,ou=users,$basedn" -w $wiebkePassword dn userPassword

LDAP 04 | LDAP Account Manager

WICHTIG: Alle Kommandos werden als root-User ausgeführt!

Grundinstallation

Dateien gibt es über die LAM-Webseite.

apt install /root/ldap-account-manager*.deb ldap-utils -y

Webserver

Apache-2-Config für den LAM

cat <<EOF >/etc/apache2/sites-available/lam.${domain}.conf
<VirtualHost *:80>
        ServerName lam.${domain}
        Redirect permanent / https://lam.${domain}
        ErrorLog \${APACHE_LOG_DIR}/error.log
        CustomLog \${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
<VirtualHost *:443>
        ServerName lam.${domain}
        DocumentRoot /usr/share/ldap-account-manager
        SSLEngine on
        SSLCertificateFile    /etc/ssl/private/lam.${domain}/fullchain.pem
        SSLCertificateKeyFile /etc/ssl/private/lam.${domain}/key.pem
        SSLProtocol all -SSLv2 -SSLv3
        SSLCipherSuite HIGH:!aNULL:!MD5
        SSLHonorCipherOrder on
        Header set Strict-Transport-Security "max-age=15768000; preload"
        Header always append X-Frame-Options "SAMEORIGIN"
        Header set Content-Security-Policy "default-src 'self' 'unsafe-inline'; script-src 'self' 'unsafe-inline'; img-src 'self'"
        Header always set Referrer-Policy "no-referrer"
        Header set X-XSS-Protection "1; mode=block"
        Header set X-Content-Type-Options "nosniff"
        ErrorLog /var/log/apache2/lam.${domain}_error.log
        CustomLog /var/log/apache2/lam.${domain}.log combined

        $(sed '/^Alias*/s/^/#/g' /etc/apache2/conf-available/ldap-account-manager.conf)

</VirtualHost>
EOF

Module aktivieren und Firewalleinstellungen setzen

a2enmod ssl headers rewrite
a2ensite lam.${domain}.conf
a2dissite 000-default.conf
ufw allow 80
ufw allow 443
systemctl restart apache2
systemctl status apache2

LDAP-Suchen ausführen

ldapsearch -x -LLL -H "ldaps://ldap.bm-uni.de" -b ou=users,$basedn -D "$admindn" -w $adminpwd uid
ldapsearch -x -LLL -H "ldaps://ldap.bm-uni.de" -b ou=users,$basedn -D "$admindn" -w $adminpwd memberOf
ldapsearch -x -LLL -H "ldaps://ldap.bm-uni.de" -b ou=users,$basedn -D "$admindn" -w $adminpwd "(memberOf=cn=administration,ou=groups,dc=bm-uni,dc=de)" memberOf

Skript für das Versenden von Briefen

Vorbereitung

mkdir -p /opt/bm
cd /opt/bm
apt install python3-pip -f
pip install fpdf

Wrapper-Skript

Damit das auch bei Dir klappt, musst Du in Deiner Nextcloud einen public-Link anlegen. Dieser hat dann das Format https://${nextcloudurl}/index.php/s/${key} - diese beiden musst Du hier unten dann ersetzen.

key="HIERDEINKEY"
nextcloudurl="HIERDEINENEXTCLOUD"
cat <<EOF >/opt/bm/sendLetter
#!/bin/bash
/opt/bm/makeLetter \$1 \$2 \$3 \$4 \$5 \$6
echo "Brief erfolgreich erzeugt."
curl -k -T /tmp/letter.pdf -u "${key}:" -H 'X-Requested-With: XMLHttpRequest' https://${nextcloudurl}/public.php/webdav/letter.pdf
echo "Brief erfolgreich hochgeladen."
EOF
chmod +x /opt/bm/sendLetter

PDF-Erzeugung

Wir nutzen hier das Modul pyFDPF und erzeugen uns auf Basis der übergebenen Argumente aus dem Wrapper eine kleine PDF, die wir nach /tmp wegspeichern, um sie dann im Wrapper per curl hochzuladen.

cat <<EOF >/opt/bm/makeLetter
#!/usr/bin/env python3
import sys
from fpdf import FPDF
pdf = FPDF()
pdf.add_page()
pdf.set_font('Arial', '', 12)
pdf.cell(50, 10, sys.argv[1] + " " + sys.argv[2],0,1)
pdf.cell(0, 3, sys.argv[3],0,1)
pdf.cell(0, 20, "Hallo "+sys.argv[1]+",",0,1)
pdf.cell(0, 3, "Dein Nutzername ist " +sys.argv[4] + " und Dein Passwort "+sys.argv[6]+".")
pdf.output('/tmp/letter.pdf', 'F')
EOF
chmod +x /opt/bm/makeLetter

Hinweis: Mit FPDF lassen sich erstaunlich komplexe PDF-Dateien erzeugen. Die Doku der originalen PHP-Klasse zeigen hier einiges auf. Selbstverständlich könnte man natürlich auch LaTeX-Dokumente erzeugen und dann in eine PDF-Datei übersetzen lassen.

LDAP 05 | Nextcloud anbinden

Zum 5. Video gibt es leider keinen Code.

LDAP 06 | Ubuntu anbinden

Erste Abfragen

basedn=""
admindn="cn=admin,$basedn"
adminpwd=""
domain=""
ldapsearch -x -D "$admindn" -b $basedn -w $adminpwd -H ldaps://ldap.${domain} displayName telephoneNumber
ldapsearch -x -D "$admindn" -b $basedn -w $adminpwd -H ldaps://ldap.${domain} "(objectClass=inetOrgPerson)" displayName telephoneNumber
ldapsearch -x -D "$admindn" -b $basedn -w $adminpwd -H ldaps://ldap.${domain} "(&(objectClass=inetOrgPerson)(telephoneNumber=*))" displayName telephoneNumber
ldapsearch -x -D "$admindn" -b $basedn -w $adminpwd -H ldaps://ldap.${domain} "(&(objectClass=inetOrgPerson)(telephoneNumber=*23125212))" displayName telephoneNumber
cat /etc/ldap/schema/core.schema | grep "2.5.4.20" -A5 -B1

Auf dem Laptop

Ersteinrichtung

sudo su
basedn=""
admindn="cn=admin,$basedn"
adminpwd=""
domain=""
apt install sddm-theme-maldives sssd -y

cat<< EOF >/etc/sddm.conf
[Autologin]
Relogin=false
Session=
User=

[General]
HaltCommand=/bin/systemctl poweroff
InputMethod=compose
Numlock=none
RebootCommand=/bin/systemctl reboot

[Theme]
Current=maldives
CursorTheme=
DisableAvatarsThreshold=7
EnableAvatars=true
FacesDir=/usr/share/sddm/faces
ThemeDir=/usr/share/sddm/themes

[Users]
DefaultPath=/bin:/usr/bin
HideShells=
HideUsers=
MaximumUid=60000
MinimumUid=1000
RememberLastSession=true
RememberLastUser=true
ReuseSession=false

[Wayland]
EnableHiDPI=false
SessionCommand=/usr/share/sddm/scripts/wayland-session
SessionDir=/usr/share/wayland-sessions
SessionLogFile=.local/share/sddm/wayland-session.log

[X11]
DisplayCommand=/usr/share/sddm/scripts/Xsetup
DisplayStopCommand=/usr/share/sddm/scripts/Xstop
EnableHiDPI=false
MinimumVT=1
ServerArguments=-nolisten tcp
ServerPath=/usr/bin/X
SessionCommand=/etc/sddm/Xsession
SessionDir=/usr/share/xsessions
SessionLogFile=.local/share/sddm/xorg-session.log
UserAuthFile=.Xauthority
XauthPath=/usr/bin/xauth
XephyrPath=/usr/bin/Xephyr
EOF

cat <<EOF >/etc/sssd/sssd.conf
[sssd]
config_file_version = 2
services = nss, pam
domains = bm-uni.de

[nss]
[pam]
offline_credentials_expiration = 7

[domain/bm-uni.de]
id_provider = ldap
auth_provider = ldap
ldap_uri = ldaps://ldap.${domain}
ldap_schema = rfc2307bis
ldap_default_bind_dn = uid=pc-binder,ou=binduser,${basedn}
ldap_default_authtok = fmE-HiMyrXbJ
ldap_default_authtok_type = password
ldap_search_base = ${basedn}
ldap_user_search_base = ou=users,${basedn}
ldap_user_object_class = inetOrgPerson
ldap_user_name = uid
ldap_group_name = cn
ldap_user_gecos = gecos
ldap_group_search_base = ou=groups,${basedn}
ldap_group_object_class = posixgroup
cache_credentials = True
account_cache_expiration = 7
enumerate = false
EOF

chown root:root /etc/sssd/sssd.conf
chmod 600 /etc/sssd/sssd.conf
pam-auth-update --enable mkhomedir

systemctl start sssd
systemctl enable sssd
getent passwd
getent passwd eerstie

Adminrechte

echo "%administration ALL=(ALL:ALL) ALL" > /etc/sudoers.d/administration
chmod 0440 /etc/sudoers.d/administration

Zugangsbeschränkung

cat <<EOF >>/etc/sssd/sssd.conf
access_provider = simple
simple_allow_groups = professors,administration
EOF
systemctl restart sssd