OpenLDAP : LDAP サーバーの設定2025/11/06 |
|
各サーバー間でユーザーのアカウント情報を共有できるように LDAP サーバーを構築します。 |
|
| [1] | OpenLDAP をインストールして基本設定をします。 |
|
dlp:~ #
dlp:~ # zypper -n install openldap2_6 openldap2_6-client mv /etc/openldap/slapd.conf /etc/openldap/slapd.conf.org dlp:~ # touch /etc/openldap/slapd.conf dlp:~ # rm -rf /etc/openldap/slapd.d/* dlp:~ # slaptest -f /etc/openldap/slapd.conf -F /etc/openldap/slapd.d config file testing succeeded
dlp:~ #
vi /etc/openldap/slapd.d/cn=config/olcDatabase\={0}config.ldif # 2行目 : 行を削除 # CRC32 xxxxxxxx # 6行目 : 変更 olcAccess: {0}to * by dn.exact=gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth manage by * breakdlp:~ # chown -R ldap:ldap /etc/openldap/slapd.d dlp:~ # chmod -R 700 /etc/openldap/slapd.d
dlp:~ #
systemctl edit slapd
# 以下 追記
[Service]
ExecStart=
ExecStart=/usr/sbin/slapd -u ldap -h "ldap:/// ldaps:/// ldapi:///"
dlp:~ #
systemctl enable --now slapd
# 管理者パスワード生成 dlp:~ # slappasswd New password: Re-enter new password: {SSHA}xxxxxxxxxxxxxxxxxxxxxxxx
dlp:~ #
vi chrootpw.ldif # 新規作成 : olcRootPW には生成した管理者パスワードを指定
dn: olcDatabase={0}config,cn=config
changetype: modify
add: olcRootPW
olcRootPW: {SSHA}xxxxxxxxxxxxxxxxxxxxxxxx
ldapadd -Y EXTERNAL -H ldapi:/// -f chrootpw.ldif
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
modifying entry "olcDatabase={0}config,cn=config"
|
| [2] | 基本的なスキーマを読み込んでおきます。 |
|
dlp:~ # ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/core.ldif SASL/EXTERNAL authentication started SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth SASL SSF: 0 adding new entry "cn=core,cn=schema,cn=config"dlp:~ # ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/cosine.ldif SASL/EXTERNAL authentication started SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth SASL SSF: 0 adding new entry "cn=cosine,cn=schema,cn=config"dlp:~ # ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/nis.ldif SASL/EXTERNAL authentication started SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth SASL SSF: 0 adding new entry "cn=nis,cn=schema,cn=config"dlp:~ # ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/inetorgperson.ldif SASL/EXTERNAL authentication started SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth SASL SSF: 0 adding new entry "cn=inetorgperson,cn=schema,cn=config" |
| [3] | 自身のドメイン名を設定します。 |
|
# ディレクトリマネージャーのパスワード生成 dlp:~ # slappasswd New password: Re-enter new password: {SSHA}xxxxxxxxxxxxxxxxxxxxxxxx
dlp:~ #
vi backend.ldif # 新規作成 # [dc=***,dc=***] には自身の Suffix に置き換え # [olcRootPW: ***] には slappasswd で生成したパスワードを指定
dn: cn=module{0},cn=config
objectClass: olcModuleList
cn: module{0}
olcModulepath: /usr/lib64/openldap
olcModuleload: {0}back_mdb
dn: olcDatabase={1}mdb,cn=config
objectClass: olcDatabaseConfig
objectClass: olcMdbConfig
olcDatabase: {1}mdb
olcDbDirectory: /var/lib/ldap
olcDbIndex: objectClass eq,pres
olcDbIndex: ou,cn,mail,surname,givenname eq,pres,sub
olcSuffix: dc=srv,dc=world
olcRootDN: cn=Manager,dc=srv,dc=world
olcRootPW: {SSHA}xxxxxxxxxxxxxxxxxxxxxxxx
olcAccess: {0}to attrs=userPassword,shadowLastChange by
dn="cn=Manager,dc=srv,dc=world" write by anonymous auth by self write by * none
olcAccess: {1}to dn.base="" by * read
olcAccess: {2}to * by dn="cn=Manager,dc=srv,dc=world" write by * read
ldapadd -Y EXTERNAL -H ldapi:/// -f backend.ldif
SASL/EXTERNAL authentication started
SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth
SASL SSF: 0
adding new entry "cn=module{0},cn=config"
adding new entry "olcDatabase={1}mdb,cn=config"
dlp:~ #
vi basedomain.ldif # [dc=***,dc=***] は自身のドメイン名に置き換え dn: dc=srv,dc=world objectClass: top objectClass: dcObject objectclass: organization o: Server World dc: srv dn: cn=Manager,dc=srv,dc=world objectClass: organizationalRole cn: Manager description: Directory Manager dn: ou=People,dc=srv,dc=world objectClass: organizationalUnit ou: People dn: ou=Group,dc=srv,dc=world objectClass: organizationalUnit ou: Group ldapadd -x -D cn=Manager,dc=srv,dc=world -W -f basedomain.ldif
Enter LDAP Password: # ディレクトリマネージャーのパスワード
adding new entry "dc=srv,dc=world"
adding new entry "cn=Manager,dc=srv,dc=world"
adding new entry "ou=People,dc=srv,dc=world"
adding new entry "ou=Group,dc=srv,dc=world"
|
| [4] |
SSL/TLS を設定しておきます。当例では自己署名の証明書を作成して進めます。 |
| [5] | LDAP over SSL/TLS の設定です。 |
|
dlp:~ # mkdir /etc/openldap/certs
dlp:~ #
dlp:~ # chown ldap:ldap /etc/openldap/certs/server.key \
/etc/openldap/certs/server.crt
dlp:~ #
vi mod_ssl.ldif # 新規作成 dn: cn=config changetype: modify replace: olcTLSCertificateFile olcTLSCertificateFile: /etc/openldap/certs/server.crt - replace: olcTLSCertificateKeyFile olcTLSCertificateKeyFile: /etc/openldap/certs/server.key ldapmodify -Y EXTERNAL -H ldapi:/// -f mod_ssl.ldif SASL/EXTERNAL authentication started SASL username: gidNumber=0+uidNumber=0,cn=peercred,cn=external,cn=auth SASL SSF: 0 modifying entry "cn=config" |
| [6] | Firewalld を有効にしている場合は、LDAP サービスの許可が必要です。 |
|
dlp:~ # firewall-cmd --add-service={ldap,ldaps} success dlp:~ # firewall-cmd --runtime-to-permanent success |
| Sponsored Link |
|
|