作り上げたLDAPサーバにクライアントPCを接続させてみる。
ubuntu18.04の場合 LDAP/Client/ubuntu

過去記事LDAP/サーバ接続181006

事前確認

既にldapサーバが用意されているなら ldapsearch コマンドで接続を確認してみます。
LDAPで作ったldapサーバは CA認証局 は自作です. なので /etc/openldap/ldap.conf には「TLS_REQCERT never」を入れる

[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を禁止にしているなら特定ユーザで検索を行う

[root@ldap-client ~]# ldapsearch  -x -H ldaps://ldap-server -b dc=sybyl,dc=local -D cn=Manager,dc=sybyl,dc=local -W

authselect

authconfigが便利だったのですが、RHEL8系からは authselect がメインのご様子. authconfig との対応とかは「man 7 authselect-migration」で確認できます

ここでは接続方法を2つ提示してます

ldapsが有効ならsssd経由でいいような気がします

接続専用アカウントの作成

anonymous接続でもいいのですが、ldap-server側で接続用アカウントを設けます. 別にposixAccountである必要はないです

[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データベースへのアクセス権を修正します. ユーザによって変更できるのはパスワード関係と使うshell. あとはgecosかな. gecosがない場合は(cn sn title)で代用される

[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

sssd経由でldapに繋ぐ.
まずは「sssd-ldap」パッケージをインストールして、「/usr/share/doc/sssd-common/sssd-example.conf」を参照しながら「/etc/sssd/sssd.conf」を作る

[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なので誰からも読めないのですが、よりセキュアにするために文字列を暗号化してみます.

[root@ldap-client ~]# sss_obfuscate -d default
Enter password:
Re-enter password:
[root@ldap-client ~]#

この「-d default」は、sssd.confに書かれている「domain/default」に由来します. パスワードの入力を終えると「/etc/sssd/sssd.conf」を書き換えます.

 :
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を起動させます

[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 ~]#

うまく拾えていないと思ったら「ldapsearch -x -H ldaps://ldap-server -b dc=sybyl,dc=local -D cn=access,ou=People,dc=sybyl,dc=local -W」で確かめる

authselect - nslcd

sssdの代わりに従来からの nslcd[Name Service LDAP Connection Daemon]を使ってみます.
https://web.chaperone.jp/w/index.php?samba/LDAP#wed2b142にも記載
「authselect list」には存在しない項目なので新規項目として作って対応します。あくまで authselect 経由

「nss-pam-ldapd」パッケージをインストールします

[root@ldap-client ~]# dnf install nss-pam-ldapd oddjob-mkhomedir

authselectのsssd profileをコピーして nslcd profile を作る

[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

このテンプレートを修正します

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」を修正します

[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の新たな候補になっているか確認します

[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 ~]#

追加されたようです.

[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から繋いでみる

「apt -y install libnss-ldapd libpam-ldapd」で設定パネルが用意されそれに従い設定を行えばいいが、

[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すれば反映されるみたい.
一応確認

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:~#

めも

sssd経由、nslcd経由でもanonymous接続だとログインシェル情報が得られないみたい. これははLDAPサーバのアクセス権でloginShellを入れたため.
それを外せば閲覧ができるのでログインシェル情報が反映される. でもユーザ側にログインシェルを変えさせたいので中継アカウントを使っている

[saber@ldap-client ~]$ getent passwd saber
saber:*:3002:2001:saber:/home/saber:
[saber@ldap-client ~]$

ユーザ視点

パスワード変更は「passwd」で行けます.

ログインシェルの変更は「ichsh」で. 参照LDAP/phpLDAPadmin#w877122e

最新の60件
2025-02-17 2025-02-15 2025-02-14 2025-02-12 2025-02-03 2025-02-02 2025-02-01 2025-01-27 2025-01-26 2025-01-25 2025-01-24 2025-01-23 2025-01-20 2025-01-13 2025-01-12 2025-01-08 2024-12-30 2024-12-29 2024-12-22 2024-12-20 2024-12-17 2024-12-15 2024-12-14 2024-12-12 2024-12-11 2024-12-10 2024-12-09 2024-12-08 2024-11-28 2024-11-22 2024-11-15 2024-11-14 2024-11-12 2024-11-06 2024-11-05 2024-11-04 2024-11-02 2024-11-01 2024-10-28 2024-10-27 2024-10-23 2024-10-18 2024-10-17 2024-10-15 2024-10-14

edit


トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2024-01-30 (火) 02:09:43