2

I have Centos 7 and next installed packages:

[root@centos7 pam.d]# rpm -qa|grep ldap
nss-pam-ldapd-0.8.13-8.el7.x86_64
openldap-2.4.44-5.el7.x86_64
openldap-clients-2.4.44-5.el7.x86_64

My configs:

/etc/nslcd.conf:

uid nslcd
gid ldap

uri ldap://<my_ldap_server_ip>

base dc=company,dc=org

binddn cn=proxy,ou=users,dc=company,dc=org
bindpw <bind_pw>

nss_initgroups_ignoreusers root,nslcd
nss_min_uid 10000

filter passwd (objectClass=posixAccount)
base passwd ou=users,dc=company,dc=org
base shadow ou=users,dc=company,dc=org
base group ou=groups,dc=company,dc=org
scope passwd one
scope shadow one
scope group one

map group member uniqueMember

ssl start_tls
TLS_REQCERT allow
tls_cacertdir /etc/openldap/cacerts

/etc/nsswitch:

. . .
passwd:     files sss ldap
shadow:     files sss ldap
group:      files sss ldap
. . .

/etc/pam.d/:

[root@centos7 pam.d]# ls -lah password-auth system-auth
lrwxrwxrwx. 1 root root 16 Aug 22 18:53 password-auth -> password-auth-ac
lrwxrwxrwx. 1 root root 14 Aug 22 18:53 system-auth -> system-auth-ac

/etc/pam.d/password-auth:

#%PAM-1.0
# This file is auto-generated.
# User changes will be destroyed the next time authconfig is run.
auth        required      pam_env.so
auth        required      pam_faildelay.so delay=2000000
auth        sufficient    pam_unix.so nullok try_first_pass
auth        requisite     pam_succeed_if.so uid >= 1000 quiet_success
auth        sufficient    pam_ldap.so use_first_pass
auth        required      pam_deny.so

account     required      pam_unix.so broken_shadow
account     sufficient    pam_localuser.so
account     sufficient    pam_succeed_if.so uid < 1000 quiet
account     [default=bad success=ok user_unknown=ignore] pam_ldap.so
account     required      pam_permit.so
password    required      pam_deny.so

password    requisite     pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type=
password    sufficient    pam_unix.so md5 shadow nullok try_first_pass use_authtok
password    sufficient    pam_ldap.so use_authtok
password    required      pam_deny.so

session     optional      pam_keyinit.so revoke
session     required      pam_limits.so
-session     optional      pam_systemd.so
session     [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
session     required      pam_unix.so
session     optional      pam_ldap.so
password    required      pam_deny.so

/etc/system-auth:

#%PAM-1.0
# This file is auto-generated.
# User changes will be destroyed the next time authconfig is run.
auth        required      pam_env.so
auth        required      pam_faildelay.so delay=2000000
auth        sufficient    pam_unix.so nullok try_first_pass
auth        requisite     pam_succeed_if.so uid >= 1000 quiet_success
auth        sufficient    pam_ldap.so use_first_pass
auth        required      pam_deny.so

account     required      pam_unix.so broken_shadow
account     sufficient    pam_localuser.so
account     sufficient    pam_succeed_if.so uid < 1000 quiet
account     [default=bad success=ok user_unknown=ignore] pam_ldap.so
account     required      pam_permit.so
password    required      pam_deny.so

password    requisite     pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type=
password    sufficient    pam_unix.so md5 shadow nullok try_first_pass use_authtok
password    sufficient    pam_ldap.so use_authtok
password    required      pam_deny.so

session     optional      pam_keyinit.so revoke
session     required      pam_limits.so
-session     optional      pam_systemd.so
session     [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid
session     required      pam_unix.so
session     optional      pam_ldap.so
password    required      pam_deny.so

When I'm doing 'su - ldapuser' I've entered.

But from ssh/console I can't login.

nslcd -d:

nslcd: [e2a9e3] DEBUG: connection from pid=4867 uid=0 gid=0
nslcd: [e2a9e3] <passwd="ldapuser"> DEBUG: myldap_search(base="ou=users,dc=company,dc=org", filter="(&(objectClass=posixAccount)(uid=ldapuser))")
nslcd: [e2a9e3] <passwd="ldapuser"> DEBUG: ldap_result(): cn=ldapuser,ou=users,dc=company,dc=org
nslcd: [e2a9e3] <passwd="ldapuser"> DEBUG: ldap_result(): end of results (1 total)
nslcd: [45e146] DEBUG: connection from pid=4867 uid=0 gid=0
nslcd: [45e146] <passwd="ldapuser"> DEBUG: myldap_search(base="ou=users,dc=company,dc=org", filter="(&(objectClass=posixAccount)(uid=ldapuser))")
nslcd: [45e146] <passwd="ldapuser"> DEBUG: ldap_result(): cn=ldapuser,ou=users,dc=company,dc=org
nslcd: [45e146] <passwd="ldapuser"> DEBUG: ldap_result(): end of results (1 total)
nslcd: [5f007c] DEBUG: connection from pid=4867 uid=0 gid=0
nslcd: [5f007c] <passwd="ldapuser"> DEBUG: myldap_search(base="ou=users,dc=company,dc=org", filter="(&(objectClass=posixAccount)(uid=ldapuser))")
nslcd: [5f007c] <passwd="ldapuser"> DEBUG: ldap_result(): cn=ldapuser,ou=users,dc=company,dc=org
nslcd: [5f007c] <passwd="ldapuser"> DEBUG: ldap_result(): end of results (1 total)
nslcd: [d062c2] DEBUG: connection from pid=4867 uid=0 gid=0
nslcd: [d062c2] <passwd="ldapuser"> DEBUG: myldap_search(base="ou=users,dc=company,dc=org", filter="(&(objectClass=posixAccount)(uid=ldapuser))")
nslcd: [d062c2] <passwd="ldapuser"> DEBUG: ldap_result(): cn=ldapuser,ou=users,dc=company,dc=org
nslcd: [d062c2] <passwd="ldapuser"> DEBUG: ldap_result(): end of results (1 total)
nslcd: [200854] DEBUG: connection from pid=4867 uid=0 gid=0
nslcd: [200854] <authc="ldapuser"> DEBUG: nslcd_pam_authc("ldapuser","sshd","***")
nslcd: [200854] <authc="ldapuser"> DEBUG: myldap_search(base="ou=users,dc=company,dc=org", filter="(&(objectClass=posixAccount)(uid=ldapuser))")
nslcd: [200854] <authc="ldapuser"> DEBUG: ldap_result(): cn=ldapuser,ou=users,dc=company,dc=org
nslcd: [200854] <authc="ldapuser"> DEBUG: myldap_search(base="cn=ldapuser,ou=users,dc=company,dc=org", filter="(objectClass=*)")
nslcd: [200854] <authc="ldapuser"> DEBUG: ldap_initialize(ldap://<my_ldap_server_ip>)
nslcd: [200854] <authc="ldapuser"> DEBUG: ldap_set_rebind_proc()
nslcd: [200854] <authc="ldapuser"> DEBUG: ldap_set_option(LDAP_OPT_PROTOCOL_VERSION,3)
nslcd: [200854] <authc="ldapuser"> DEBUG: ldap_set_option(LDAP_OPT_DEREF,0)
nslcd: [200854] <authc="ldapuser"> DEBUG: ldap_set_option(LDAP_OPT_TIMELIMIT,30)
nslcd: [200854] <authc="ldapuser"> DEBUG: ldap_set_option(LDAP_OPT_TIMEOUT,30)
nslcd: [200854] <authc="ldapuser"> DEBUG: ldap_set_option(LDAP_OPT_NETWORK_TIMEOUT,30)
nslcd: [200854] <authc="ldapuser"> DEBUG: ldap_set_option(LDAP_OPT_REFERRALS,LDAP_OPT_ON)
nslcd: [200854] <authc="ldapuser"> DEBUG: ldap_set_option(LDAP_OPT_RESTART,LDAP_OPT_ON)
nslcd: [200854] <authc="ldapuser"> DEBUG: ldap_start_tls_s()
nslcd: [200854] <authc="ldapuser"> DEBUG: set_socket_timeout(30,500000)
nslcd: [200854] <authc="ldapuser"> DEBUG: ldap_simple_bind_s("cn=ldapuser,ou=users,dc=company,dc=org","***") (uri="ldap://<my_ldap_server_ip>")
nslcd: [200854] <authc="ldapuser"> ldap_result() failed: No such object
nslcd: [200854] <authc="ldapuser"> cn=ldapuser,ou=users,dc=company,dc=org: lookup failed: No such object
nslcd: [200854] <authc="ldapuser"> DEBUG: set_socket_timeout(15,0)
nslcd: [200854] <authc="ldapuser"> DEBUG: ldap_unbind()
nslcd: [200854] <authc="ldapuser"> DEBUG: myldap_search(base="ou=users,dc=company,dc=org", filter="(&(objectClass=shadowAccount)(uid=ldapuser))")
nslcd: [200854] <authc="ldapuser"> DEBUG: ldap_result(): end of results (0 total)

journalctl -xlf:

Feb 20 20:37:24 centos7.localdomain sshd[4965]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=192.168.56.1  user=ldapuser
Feb 20 20:37:24 centos7.localdomain sshd[4965]: pam_ldap(sshd:auth): Authentication failure; user=ldapuser
Feb 20 20:37:26 centos7.localdomain sshd[4965]: Failed password for goncharuk from 192.168.56.1 port 56663 ssh2

UPD: I forgot show this links: I've read this topics and they not help me:

centos-7-ldap-authentication-permission-denied

ldap-login-fails-but-su-to-ldap-users-works

5

1 Answer 1

1

Finally, the problem has been solved.

Some brief before concrete steps. Anyone knowns that LDAP login procedure followed this steps:

Authentification:

  1. Connecting to LDAP server.
  2. 'Bind'-ing as 'search-user'.
  3. Searching necessary user.
  4. 'Bind'-ing as user from step 3 with corresponding password.

Authorization:

  1. Searching needed attributes.
  2. Login

If login is incorrect on step 3, then 'User not found' message produced.

If password on step 4 is incorrect, then 'Invalid credentials' message produced.

Indeed, NSLCD do all these steps.

Step 4 in NSLCD have one improvement about security reasons. After 'bind'-ing as found user, NSLCD trying search in user 'DN' with base as 'DN' to ensure that this 'DN' is really 'DN' of 'bind'-ing user. For instance ('ldapsearch' request):

ldapsearch -w <user_passwd> -h <ldap_server_ip> -D "cn=ldapuser,ou=users,dc=company,dc=org" -b "cn=ldapuser,ou=users,dc=company,dc=org"

This behaviour was described by author of nss-pam-ldapd in at least this sources:

issue 1

issue 2

This mean that user which want to be logged in over NSLCD must have search permissions in own LDAP 'DN'!

In NSLCD versions before 0.9.x this behaviour was not changeable.

In NSLCD version that begins from 0.9.x it's possible to skip search in own 'DN' via 'pam_authc_search NONE' option.

In my case, using 'pam_authc_search NONE' really help me, but it's need to build and install 'nss-pam-ldapd' package with new version. Now, I am testing LDAP login on VM with Centos 7. I have at least 5 different distros and building packages for each is not good solution. In addition, two-phactor login checks (bind + search) is really need security tool. So, I changed my LDAP server (OpenLDAP 2.4) ACL-s to grand search access for users in own 'DN' and now all works fine:

/etc/openldap/slapd.conf:

. . .
access to attrs=userPassword
        by self read
        by anonymous auth
        by * none

access to *
        by self read
        by dn="cn=searchuser,ou=users,dc=company,dc=org" read
        by * none
. . .

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .