#author("2024-01-29T17:07:33+00:00","default:sysosa","sysosa") #author("2024-01-29T17:09:43+00:00","default:sysosa","sysosa") 作り上げたLDAPサーバにクライアントPCを接続させてみる。 &size(10){ubuntu18.04の場合 [[LDAP/Client/ubuntu]]}; &size(10){過去記事[[LDAP/サーバ接続181006]]}; ***事前確認 [#i22315cf] 既にldapサーバが用意されているなら ldapsearch コマンドで接続を確認してみます。 [[LDAP]]で作ったldapサーバは CA認証局 は自作です. なので /etc/openldap/ldap.conf には「&color(magenta){TLS_REQCERT never};」を入れる #code(nonumber){{ [root@ldap-client ~]# cat /etc/redhat-release Rocky Linux release 8.6 (Green Obsidian) [root@ldap-client ~]# dnf install openldap-clients [root@ldap-client ~]# echo "TLS_REQCERT never" >> /etc/openldap/ldap.conf [root@ldap-client ~]# ldapsearch -x -H ldaps://ldap-server -b dc=sybyl,dc=local <-- ldaps で繋げてます. ldap でも構いません }} anonymous接続を許可しているなら上記でいいが、anonymousを禁止にしているなら特定ユーザで検索を行う #code(nonumber){{ [root@ldap-client ~]# ldapsearch -x -H ldaps://ldap-server -b dc=sybyl,dc=local -D cn=Manager,dc=sybyl,dc=local -W }} ***authselect [#o17ca67e] authconfigが便利だったのですが、RHEL8系からは authselect がメインのご様子. &size(10){authconfig との対応とかは「man 7 authselect-migration」で確認できます}; ここでは接続方法を2つ提示してます -sssd経由 -nslcd経由 ldapsが有効ならsssd経由でいいような気がします ***接続専用アカウントの作成 [#m94ef75f] anonymous接続でもいいのですが、ldap-server側で接続用アカウントを設けます. &size(10){別にposixAccountである必要はないです}; #code(nonumber){{ [root@ldap-server ~]# cat ldap/access.ldif dn: cn=access,ou=people,dc=sybyl,dc=local changetype: add objectClass: inetOrgPerson cn: access sn: access userPassword: {SSHA}xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx [root@ldap-server ~]# ldapadd -x -D cn=Manager,dc=sybyl,dc=local -W -f ldap/access.ldif }} そしてLDAPデータベースへのアクセス権を修正します. &size(10){ユーザによって変更できるのはパスワード関係と使うshell. あとはgecosかな. gecosがない場合は(cn sn title)で代用される}; #code(nonumber){{ [root@ldap-server ~]# ldapvi -Y EXTERNAL -h ldapi:/// -b olcDatabase={2}mdb,cn=config olcAccess: {0}to attrs=userPassword,shadowLastChange by dn="cn=Manager,dc=sybyl,dc=local" write by anonymous auth by self write by * none ↓ olcAccess: {0}to attrs=userPassword,shadowLastChange,loginShell,gecos by dn="cn=Manager,dc=sybyl,dc=local" write by anonymous auth by self write by dn="cn=access,ou=People,dc=sybyl,dc=local" read by * none olcAccess: {1}to dn.base="" by * read olcAccess: {2}to * by dn="cn=Manager,dc=sybyl,dc=local" write by * read }} 中継役の「cn=access,ou=People,dc=sybyl,dc=local」は「userPassword,shadowLastChange,loginShell,gecos」を読めて、それ以外のも読める. その上で ***authselect - sssd [#g2ccf901] sssd経由でldapに繋ぐ. まずは「sssd-ldap」パッケージをインストールして、「/usr/share/doc/sssd-common/sssd-example.conf」を参照しながら「/etc/sssd/sssd.conf」を作る #code(nonumber){{ [root@ldap-client ~]# dnf -y install sssd-ldap oddjob-mkhomedir sssd-tools [root@ldap-client ~]# vi /etc/sssd/sssd.conf [sssd] services = nss, pam domains = default [nss] [domain/default] id_provider = ldap ldap_uri = ldaps://ldap-server/ <-- ldaps接続なら ldap_search_base = dc=sybyl,dc=local ldap_id_use_start_tls = True ldap_tls_reqcert = never ldap_default_bind_dn = cn=access,ou=People,dc=sybyl,dc=local ldap_default_authtok = xxxxxxxxxxx <--- パスワードは平文で記載 [root@ldap-client ~]# chmod 600 /etc/sssd/sssd.conf }} 「/etc/sssd/sssd.conf」は600なので誰からも読めないのですが、よりセキュアにするために文字列を暗号化してみます. #code(nonumber){{ [root@ldap-client ~]# sss_obfuscate -d default Enter password: Re-enter password: [root@ldap-client ~]# }} この「-d default」は、sssd.confに書かれている「domain/&color(magenta){default};」に由来します. パスワードの入力を終えると「/etc/sssd/sssd.conf」を書き換えます. #code(nonumber){{ : ldap_default_bind_dn = cn=access,ou=People,dc=sybyl,dc=local ldap_default_authtok = AAAQAKooYshlPbF2vEJmZVGj51mmVV25TUrl5je4(略 以下が追記されます. access_provider = permit sudo_provider = ldap auth_provider = ldap autofs_provider = ldap resolver_provider = ldap ldap_default_authtok_type = obfuscated_password }} っでsssdを起動させます #code(nonumber){{ [root@ldap-client ~]# authselect select sssd with-mkhomedir --force [root@ldap-client ~]# systemctl enable oddjobd.service --now [root@ldap-client ~]# systemctl restart sssd [root@ldap-client ~]# authselect current Profile ID: sssd Enabled features: - with-mkhomedir [root@ldap-client ~]# (接続確認) [root@ldap-client ~]# dnf install lsof [root@ldap-client ~]# lsof -i COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME : sssd_be 2327 root 21u IPv4 28757 0t0 TCP ldap-client.sybyl.local:35568->ldap-server.sybyl.local:ldaps (ESTABLISHED) : [root@ldap-client ~]# [root@ldap-client ~]# getent passwd foo foo:*:3000:2001:foo sybyl:/home/foo:/bin/bash [root@ldap-client ~]# }} &size(10){うまく拾えていないと思ったら「ldapsearch -x -H ldaps://ldap-server -b dc=sybyl,dc=local -D cn=access,ou=People,dc=sybyl,dc=local -W」で確かめる}; ***authselect - nslcd [#s99de1a1] sssdの代わりに従来からの nslcd[Name Service LDAP Connection Daemon]を使ってみます. &size(10){[[https://web.chaperone.jp/w/index.php?samba/LDAP#wed2b142>+https://web.chaperone.jp/w/index.php?samba/LDAP#wed2b142]]にも記載}; 「authselect list」には存在しない項目なので新規項目として作って対応します。あくまで authselect 経由 「nss-pam-ldapd」パッケージをインストールします #code(nonumber){{ [root@ldap-client ~]# dnf install nss-pam-ldapd oddjob-mkhomedir }} authselectのsssd profileをコピーして nslcd profile を作る #code(nonumber){{ [root@ldap-client ~]# ls -l /usr/share/authselect/default/sssd total 44 -rw-r--r--. 1 root root 540 Nov 25 2020 dconf-db -rw-r--r--. 1 root root 279 Nov 25 2020 dconf-locks -rw-r--r--. 1 root root 2080 May 19 2021 fingerprint-auth -rw-r--r--. 1 root root 393 Nov 25 2020 nsswitch.conf -rw-r--r--. 1 root root 3119 May 19 2021 password-auth -rw-r--r--. 1 root root 340 May 19 2021 postlogin -rw-r--r--. 1 root root 4372 May 19 2021 README -rw-r--r--. 1 root root 1904 Nov 25 2020 REQUIREMENTS -rw-r--r--. 1 root root 1976 May 19 2021 smartcard-auth -rw-r--r--. 1 root root 3873 May 19 2021 system-auth [root@ldap-client ~]# cp -Rp /usr/share/authselect/default/sssd /etc/authselect/custom/nslcd }} このテンプレートを修正します #code(nonumber){{ cd /etc/authselect/custom/nslcd sed -i 's/sss/ldap/g' fingerprint-auth sed -i 's/sss/ldap/g' password-auth sed -i 's/sss/ldap/g' smartcard-auth sed -i 's/sss/ldap/g' system-auth sed -i 's/sss/ldap/g' nsswitch.conf sed -i 's/SSSD/NSLCD/g' REQUIREMENTS echo "Enable nslcd for system authentication" > README }} 加えて「/etc/nslcd.conf」を修正します #code(nonumber){{ [root@ldap-client ~]# cp -i /etc/nslcd.conf /etc/nslcd.conf.orig [root@ldap-client ~]# sed '/^#/d' /etc/nslcd.conf.orig | sed '/^$/d' > /etc/nslcd.conf [root@ldap-client ~]# vi /etc/nslcd.conf uid nslcd gid ldap uri ldaps://ldap-server/ base dc=sybyl,dc=local tls_reqcert never binddn cn=access,ou=People,dc=sybyl,dc=local bindpw xxxxxxxxx <-- パスワードは平文で記載 [root@ldap-client ~]# ls -l /etc/nslcd.conf -rw-------. 1 root root 123 Nov 27 18:59 /etc/nslcd.conf [root@ldap-client ~]# }} authselectの新たな候補になっているか確認します #code(nonumber){{ [root@ldap-client ~]# authselect list - minimal Local users only for minimal installations - nis Enable NIS for system authentication - sssd Enable SSSD for system authentication (also for local users only) - winbind Enable winbind for system authentication - custom/nslcd Enable nslcd for system authentication [root@ldap-client ~]# }} 追加されたようです. #code(nonumber){{ [root@ldap-client ~]# authselect select custom/nslcd with-mkhomedir --force [root@ldap-client ~]# systemctl enable oddjobd.service --now [root@ldap-client ~]# systemctl enable nslcd --now [root@ldap-client ~]# getent passwd foo foo:*:3000:2001:foo sybyl:/home/foo:/bin/bash [root@ldap-client ~]# }} ***ubuntu20.04から繋いでみる [#r6800a38] 「apt -y install libnss-ldapd libpam-ldapd」で設定パネルが用意されそれに従い設定を行えばいいが、 #code(nonumber){{ [root@ldap-client ~]# apt -y install libnss-ldapd libpam-ldapd LDAP server URI: --> ldaps://ldap-server/ LDAP server search base: --> dc=sybyl,dc=local Name services to configure: --> passwd, group, shadow を有効に [root@ldap-client ~]# cp -i /etc/nslcd.conf /etc/nslcd.conf.orig [root@ldap-client ~]# sed '/^#/d' /etc/nslcd.conf.orig | sed '/^$/d' > /etc/nslcd.conf [root@ldap-client ~]# vi /etc/nslcd.con uid nslcd gid nslcd uri ldap://ldap-server/ base dc=sybyl,dc=local #tls_cacertfile /etc/ssl/certs/ca-certificates.crt tls_reqcert never [root@ldap-client ~]# reboot }} 即座には反映しないようで、rebootすれば反映されるみたい. 一応確認 #code(nonumber){{ root@ldap-client:~# lsof -i : nslcd 906 nslcd 7u IPv4 27805 0t0 TCP ldap-client.sybyl.local:49594->ldap-server.sybyl.local:ldaps (ESTABLISHED) : root@ldap-client:~# }} ***めも [#ed50dfad] sssd経由、nslcd経由でもanonymous接続だとログインシェル情報が得られないみたい. これははLDAPサーバのアクセス権でloginShellを入れたため. それを外せば閲覧ができるのでログインシェル情報が反映される. でもユーザ側にログインシェルを変えさせたいので中継アカウントを使っている #code(nonumber){{ [saber@ldap-client ~]$ getent passwd saber saber:*:3002:2001:saber:/home/saber: [saber@ldap-client ~]$ }} ***ユーザ視点 [#nc10978f] パスワード変更は「passwd」で行けます. ログインシェルの変更は「ichsh」で. 参照[[phpLDAPadmin#w877122e]] ログインシェルの変更は「ichsh」で. 参照[[LDAP/phpLDAPadmin#w877122e]]