Authentifizierung über tiss

Das tiss-Adressbuch ist ein ldap-server. Um sich auf einem Rechner mit dem TU-Konto und Passwort einloggen zu können, muss dieser Rechner die Informationen über den Nutzer vom ldap-server holen. Die technische Realisation auf dem math-Rechner wird im Folgenden beschrieben.

Voraussetzungen

Pakete unter ubuntu 14.04:

sowie

Weiters musste unter ubuntu 14.04 die gnutls-library upgegraded werden, um sichere Abfragen (ldaps://... statt ldap://..) zu ermöglichen,

Unter ubuntu 14.10 ist das nicht mehr nötig.

Als Abhängigkeit von libpam-ldap werden ldap-auth-config und ldap-auth-client installiert, die die Dateien unter /etc/pam.d sowie /etc/ldap.conf schon teilweise konfigurieren. Der Name Service Caching Daemon, nscd, wurde installiert, nachdem alles funktionierte, um die Anzahl der ldap-Anfragen an den server zu reduzieren.

Anmerkung: Es bestehen die Alternativen

Die Pakete libpam-ldap und libnss-ldap stammen von www.padl.com, die Alternativen mit *-ldapd von arthurdejong.org. Letztere von arthurdejong bieten die Möglichkeit, abgefragte ldap-Attribute durch Variablen zu setzen. Das war nötig, um für jeden user ein individuelles home-Directory erstellen zu können,

Konfiguration

Versucht sich ein Nutzer einzuloggen, wird mit einem bestehenden, in den Konfigurationsdateien hinterlegten Konto, ein bind an den ldap-server durchgeführt. Die Attribute für den Nutzer werden abgefragt und das login für Mitglieder des Institutes E322 erlaubt.

Konfigurationsdateien:

sowie, in /etc/pam.d

Die Dateien in /etc/pam.d werden größtenteils von ldap-auth-config modifiziert.

Siehe das Listing der Dateien weiter unten.

Tests

getent passwd, getent shadow sollte alle tiss-Einträge zeigen.

In pam.d die Option debug den Modulen zufügen, die dies unterstützen.
Für libnss-ldap in /etc/ldap.conf die Zeile debug 1 hinzufügen.
nslcd manuell starten, siehe man nslcd.

Unterbinden von brute-force Attacken

Es finden oft eine Vielzahl von Versuchen statt, sich durch das Erraten des Passwortes z.B. als root einzuloggen, siehe /var/log/auth.log. Eine entsprechende iptables-Regel sperrt nach 6 Versuchen innerhalb einer Minute die entsprechende IP-Adresse. (Gefunden März 2015 auf http://kvz.io/blog/2007/07/28/block-brute-force-attacks-with-iptables.) Mit den folgenden Regeln stehen die gesperrten Adressen in /proc/net/xt_recent/SSH, siehe man iptables-extensions.

/etc/network/if-up.d/iptables:

#!/bin/sh

if [ "$METHOD" = loopback ]; then
        exit 0
fi
/sbin/iptables -A INPUT -i eth0 -p tcp --dport 22 '!' -s 128.130.169.1/25 -m state --state NEW -m recent --set --name SSH
/sbin/iptables -A INPUT -i eth0 -p tcp --dport 22 '!' -s 128.130.169.1/25 -m state --state NEW -m recent --update --seconds 60 --hitcount 6 --rttl --name SSH -j DROP

In /etc/network/if-down.d/iptables steht dasselbe, mit -A ersetzt durch -D.

Konfigurationsdateien

# /etc/nslcd.conf

# The number of threads to start with. Each thread starts a separate
# connection to the ldap-server. Default: 5.
threads 1

# The user and group nslcd should run as.
uid nslcd
gid nslcd

# The location at which the LDAP server(s) should be reachable.
uri ldaps://dc.intern.tuwien.ac.at

# The search base that will be used for all queries.
base ou=tu,dc=intern,dc=tuwien,dc=ac,dc=at

# The LDAP protocol version to use.
#ldap_version 3

# The DN to bind with for normal lookups.
binddn CN=E322_LDAP,OU=interactive,OU=exchange,OU=IT-services,OU=TU,DC=intern,DC=tuwien,DC=ac,DC=at

bindpw _secret_passwd_

# SSL options
# Request a valid certificate from the server.
tls_reqcert demand

tls_cacertfile  /etc/ssl/certs/ca-certificates.crt

# The search scope.
#scope sub

# Customize certain database lookups.
base    group   ou=groups,ou=TU,dc=intern,dc=tuwien,dc=ac,dc=at
base    passwd  ou=people,ou=TU,dc=intern,dc=tuwien,dc=ac,dc=at
base    shadow  ou=people,ou=TU,dc=intern,dc=tuwien,dc=ac,dc=at
#base   shadow ou=People,dc=example,dc=com
scope   group   onelevel
#scope  hosts  sub

# Mappings for Active Directory
# Limit the amount of results returned.
pagesize 1000
referrals no
#idle_timelimit 800
filter  passwd  (&(objectClass=user)(memberOf=cn=E322,ou=groups,ou=TU,dc=intern,dc=tuwien,dc=ac,dc=at))
map     passwd  uid             sAMAccountName
map     passwd  uidNumber       employeeID
map     passwd  gecos           cn
map     passwd  homeDirectory   "/home/${sAMAccountName}"
map     passwd  gidNumber       "100"
map     passwd  loginShell      "/bin/bash"
#map    passwd  gecos           displayName
#map    passwd  homeDirectory   unixHomeDirectory
#filter shadow  (&(objectClass=user)(!(objectClass=computer))(uidNumber=*)(unixHomeDirectory=*))
filter  shadow  (&(objectClass=user)(memberOf=cn=E322,ou=groups,ou=TU,dc=intern,dc=tuwien,dc=ac,dc=at))
map     shadow  uid                     sAMAccountName
map     shadow  shadowLastChange        pwdLastSet
filter  group   (objectClass=group)

# /etc/ldap.conf

# The distinguished name of the search base.
base ou=tu,dc=intern,dc=tuwien,dc=ac,dc=at

# Another way to specify your LDAP server is to provide an
uri ldaps://dc.intern.tuwien.ac.at

# The LDAP version to use (defaults to 3
# if supported by client library)
ldap_version 3

# The distinguished name to bind to the server with.
# Optional: default is to bind anonymously.
binddn CN=E322_LDAP,OU=interactive,OU=exchange,OU=IT-services,OU=TU,DC=intern,DC=tuwien,DC=ac,DC=at

# The credentials to bind with. 
# Optional: default is no credential.
bindpw _secret_passed_

# The search scope.
scope sub
#scope one
#scope base

# man://nss_ldap: Specifies the path to the X.509
# certificate for peer authentication.
# TLS certificates (needed for GnuTLS)
# Openldap syntax, man ldap.conf
TLS_CACERT      /etc/ssl/certs/ca-certificates.crt
# pam_ldap und nss_ldap syntax, man pam_ldap, man nss_ldap
tls_cacertfile  /etc/ssl/certs/ca-certificates.crt

# The user ID attribute (defaults to uid)
pam_login_attribute     sAMAccountName

# Filter to AND with uid=%s
#pam_filter     memberOf=CN=E320,OU=groups,OU=TU,DC=intern,DC=tuwien,DC=ac,DC=at

# Group to enforce membership of
pam_groupdn     CN=E322,OU=groups,OU=TU,DC=intern,DC=tuwien,DC=ac,DC=at

# Group member attribute
pam_member_attribute member

# Redirect users to a URL or somesuch on password
# changes.
pam_password_prohibit_message Please change your password via tiss, https://iu.zid.tuwien.ac.at/AuthServ.changePassword .

In /etc/nsswitch.conf füge ldap hinzu,

passwd:         compat ldap
group:          compat
shadow:         compat ldap

Patches in /etc/pam.d:

--- pam.d.orig/common-auth      2015-03-26 13:41:52.434136244 +0100
+++ pam.d/common-auth   2015-03-26 13:45:31.650138595 +0100
@@ -13,8 +13,13 @@
 # pam-auth-update to manage selection of other modules.  See
 # pam-auth-update(8) for details.
 
+#th
+# Disallow attempts to login as root, _before_ trying to negotiate a passwd.
+auth   requisite       pam_listfile.so item=user sense=deny file=/etc/security/listfile.conf onerr=succeed
+
 # here are the per-package modules (the "Primary" block)
-auth   [success=1 default=ignore]      pam_unix.so nullok_secure
+auth   [success=2 default=ignore]      pam_unix.so
+auth   [success=1 default=ignore]      pam_ldap.so use_first_pass
 # here's the fallback if no module succeeds
 auth   requisite                       pam_deny.so
 # prime the stack with a positive return value if there isn't one already;

--- pam.d.orig/common-account   2015-03-02 16:58:06.000000000 +0100
+++ pam.d/common-account        2015-03-19 15:25:55.000000000 +0100
@@ -14,7 +14,8 @@
 #
 
 # here are the per-package modules (the "Primary" block)
-account        [success=1 new_authtok_reqd=done default=ignore]        pam_unix.so 
+account        [success=2 new_authtok_reqd=done default=ignore]        pam_unix.so
+account        [success=1 default=ignore]      pam_ldap.so 
 # here's the fallback if no module succeeds
 account        requisite                       pam_deny.so
 # prime the stack with a positive return value if there isn't one already;

--- pam.d.orig/common-password  2015-03-02 16:58:06.000000000 +0100
+++ pam.d/common-password       2015-03-11 12:52:49.000000000 +0100
@@ -23,7 +23,7 @@
 
 # here are the per-package modules (the "Primary" block)
-password       [success=1 default=ignore]      pam_unix.so obscure sha512
+password       [success=2 default=ignore]      pam_unix.so obscure sha512
+password       [success=1 user_unknown=ignore default=die]     pam_ldap.so use_authtok try_first_pass
 # here's the fallback if no module succeeds
 password       requisite                       pam_deny.so
 # prime the stack with a positive return value if there isn't one already;

--- pam.d.orig/common-session   2015-03-02 16:58:06.000000000 +0100
+++ pam.d/common-session        2015-03-23 10:55:29.000000000 +0100
@@ -27,8 +27,9 @@
 session optional                       pam_umask.so
 # and here are more per-package modules (the "Additional" block)
 session        required                        pam_unix.so
+session        optional                        pam_ldap.so 
 session        optional                        pam_systemd.so
 session        optional                        pam_ecryptfs.so unwrap
 session        optional                        pam_ck_connector.so nox11
 # end of pam-auth-update config
+session required       pam_mkhomedir.so skel=/etc/skel umask=0022