LoginSignup
1
1

More than 3 years have passed since last update.

CentOS 7 x86_64 1908 LDAP Authセットアップ

Last updated at Posted at 2019-09-19

CentOS 7 x86_64 1908がリリースされたので、LDAP認証のセットアップを行った。

環境

Windows 10
VirtualBox 6.0.12 r133076 (Qt5.6.2)

インストールメディア

CentOS-7-x86_64-Minimal-1908.iso

ネットワーク設定

NATとHost Only Adapter

インストール

再起動後の設定

ssh設定

rootでssh接続できるように、sshd_configを変更する。

PermitRootLogin yes

sshdを再起動する。

# systemctl restart sshd

ネットワーク設定

IPアドレスを確認する。

# ip addr

enp0s3は10.0.2.15, enp0s8が無効になっていた。
enp0s8のONBOOTがnoになっているので、yesに変更する。


# vi /etc/sysconfig/network-scripts/ifcfg-enp0s8
ONBOOT=yes
# systemctl restart network
# ip addr

enp0s3は10.0.2.15, enp0s8は 192.168.56.105になった。

以降、Windowsからputtyなどでssh接続する。

YUMの設定

パッケージのインストール前に、日本のミラーを参照するように変更する。

# vi /etc/yum/pluginconf.d/fastestmirror.conf
include_only=.jp

tmuxを使えるようにする。

# yum -y update

# yum -y install tmux

# rpm -ql tmux | grep vim
/usr/share/doc/tmux-1.8/examples/tmux.vim
/usr/share/doc/tmux-1.8/examples/vim-keys.conf

# cp /usr/share/doc/tmux-1.8/examples/vim-keys.conf ~/.tmux.conf

# tmux

ツールのインストール

適宜インストールする。

# yum -y install wget
# yum -y install rpmdevtools

openldap server

# yum -y install openldap-servers openldap-clients
# yum -y install samba

EPEL

EPELをインストールする。普段は無効にしておくので、epel.repoのenabledを0に変更する。

# yum -y install epel-release
# vi /etc/yum.repos.d/epel.repo
enabled=0

smbldap-toolsをインストールするときは一時的にepelを有効にする。

# yum -y --enablerepo=epel install smbldap-tools

slapd.confは削除されているので新規作成する。

# vi /etc/openldap/slapd.conf

パスワードの文字列はslappasswdで常時された文字列に変更すること。

/etc/openldap/slapd.conf
#
# See slapd.conf(5) for details on configuration options.
# This file should NOT be world readable.
#
include         /etc/openldap/schema/corba.schema
include         /etc/openldap/schema/core.schema
include         /etc/openldap/schema/cosine.schema
include         /etc/openldap/schema/duaconf.schema
include         /etc/openldap/schema/dyngroup.schema
include         /etc/openldap/schema/inetorgperson.schema
include         /etc/openldap/schema/java.schema
include         /etc/openldap/schema/misc.schema
include         /etc/openldap/schema/nis.schema
include         /etc/openldap/schema/openldap.schema
include         /etc/openldap/schema/pmi.schema
include         /etc/openldap/schema/ppolicy.schema
include         /etc/openldap/schema/collective.schema
include         /etc/openldap/schema/samba.schema

# Define global ACLs to disable default read access.

# Do not enable referrals until AFTER you have a working directory
# service AND an understanding of referrals.
#referral       ldap://root.openldap.org

pidfile         /var/run/openldap/slapd.pid
argsfile        /var/run/openldap/slapd.args

# Load dynamic backend modules:
# modulepath    /usr/lib/openldap
# moduleload    back_mdb.la
# moduleload    back_ldap.la

# Certificate/SSL Section
TLSCipherSuite          DEFAULT
#TLSCertificateFile      /etc/pki/tls/certs/ldapclient.pem
#TLSCertificateKeyFile   /etc/pki/tls/certs/ldapclientkey.pem

# Sample security restrictions
#       Require integrity protection (prevent hijacking)
#       Require 112-bit (3DES or better) encryption for updates
#       Require 63-bit encryption for simple bind
# security ssf=1 update_ssf=112 simple_bind=64

# Sample access control policy:
#       Root DSE: allow anyone to read it
#       Subschema (sub)entry DSE: allow anyone to read it
#       Other DSEs:
#               Allow self write access
#               Allow authenticated users read access
#               Allow anonymous users to authenticate
#       Directives needed to implement policy:
# access to dn.base="" by * read
# access to dn.base="cn=Subschema" by * read
# access to *
#       by self write
#       by users read
#       by anonymous auth
#
# if no access controls are present, the default policy
# allows anyone and everyone to read anything but restricts
# updates to rootdn.  (e.g., "access to * by * read")
#
# rootdn can always read and write EVERYTHING!

access to attrs=userPassword,givenName,sn,photo
        by self write
        by anonymous auth
        by dn.base="cn=Manager,dc=my-domain,dc=com" write
        by * none

access to *
        by self write
        by dn.base="cn=Manager,dc=my-domain,dc=com" write
        by * read

#######################################################################
# MDB database definitions
#######################################################################

database        mdb
maxsize         1073741824
suffix          "dc=my-domain,dc=com"
rootdn          "cn=Manager,dc=my-domain,dc=com"
# Cleartext passwords, especially for the rootdn, should
# be avoid.  See slappasswd(8) and slapd.conf(5) for details.
# Use of strong authentication encouraged.
rootpw          secret
# The database directory MUST exist prior to running slapd AND
# should only be accessible by the slapd and slap tools.
# Mode 700 recommended.
directory       /var/lib/ldap
# Indices to maintain
index   objectClass     eq
index   uid             pres,eq
index   mail            pres,sub,eq
index   cn              pres,sub,eq
index   sn              pres,sub,eq
index   dc              eq

新規作成したので、ファイルの所有者を変更する。

# chown ldap:ldap /etc/openldap/slapd.conf

/etc/openldap/slapd.d/ ではなく /etc/openldap/slapd.conf を参照するようにする。

# systemctl edit slapd
[Service]
ExecStart=
ExecStart=/usr/sbin/slapd -u ldap -f /etc/openldap/slapd.conf -h "ldap:/// ldaps:/// ldapi:///"

slapdが動いていることを確認する。

# systemctl start slapd
# ps -ef | grep ldap
...

Firewall

# firewall-cmd --add-service ldap
# firewall-cmd --add-service ldap --permanent
# firewall-cmd --add-service ldaps
# firewall-cmd --add-service ldaps --permanent

試しに接続してみる。

# vi /etc/openldap/ldap.conf
BASE    dc=my-domain,dc=com
URL     ldap://localhost
# ldapsearch -H ldap://localhost -x -W -D cn=Manager,dc=my-domain,dc=com

ここまででslapdが動き、接続できることを確認できた。

smbldap-tools

ldapユーザーの登録はsmbldap-toolsで行う。

smbldap.conf編集

net getlocalsidを実行し、表示されるSIDをsmbldap.confに記入する。

# net getlocalsid
# vi /etc/smbldap-tools/smldap.conf

slapd.confの主な変更箇所は以下の通り。

#slaveLDAP="ldap://ldap.example.com/"
#masterLDAP="ldap://ldap.example.com/"
#ldapTLS="1"
#verify="require"
#cafile="/etc/pki/tls/certs/ldapserverca.pem"
#clientcert="/etc/pki/tls/certs/ldapclient.pem"
#clientkey="/etc/pki/tls/certs/ldapclientkey.pem"
suffix="dc=my-domain,dc=com"
usersdn="ou=Users,${suffix}"

smbldap_bind.conf編集

# vi /etc/smbldap-tools/smbldap_bind.conf

smbldap-populateを実行する。パスワードは smbldap_bind.conf に記載したものを使う。

smbldap-populate

# smbldap-populate
Populating LDAP directory for domain SAMBA (S-1-5-21-3023189341-518760234-3643549886)
(using builtin directory structure)

adding new entry: dc=my-domain,dc=com
adding new entry: ou=Users,dc=my-domain,dc=com
adding new entry: ou=Group,dc=my-domain,dc=com
adding new entry: ou=Computers,dc=my-domain,dc=com
adding new entry: ou=Idmap,dc=my-domain,dc=com
adding new entry: sambaDomainName=SAMBA,dc=my-domain,dc=com
adding new entry: sambaDomainName=sambaDomain,dc=my-domain,dc=com
adding new entry: uid=root,ou=Users,dc=my-domain,dc=com
adding new entry: uid=nobody,ou=Users,dc=my-domain,dc=com
adding new entry: cn=Domain Admins,ou=Group,dc=my-domain,dc=com
adding new entry: cn=Domain Users,ou=Group,dc=my-domain,dc=com
adding new entry: cn=Domain Guests,ou=Group,dc=my-domain,dc=com
adding new entry: cn=Domain Computers,ou=Group,dc=my-domain,dc=com
adding new entry: cn=Administrators,ou=Group,dc=my-domain,dc=com
adding new entry: cn=Account Operators,ou=Group,dc=my-domain,dc=com
adding new entry: cn=Print Operators,ou=Group,dc=my-domain,dc=com
adding new entry: cn=Backup Operators,ou=Group,dc=my-domain,dc=com
adding new entry: cn=Replicators,ou=Group,dc=my-domain,dc=com

Please provide a password for the domain root:
Changing UNIX and samba passwords for root
New password:
Retype new password:

追加したグループなどが表示されるか確認する。

# ldapsearch -H ldap://localhost -x -W -D cn=Manager,dc=my-domain,dc=com
・・・
# Replicators, Group, my-domain.com
dn: cn=Replicators,ou=Group,dc=my-domain,dc=com
objectClass: top
objectClass: posixGroup
objectClass: sambaGroupMapping
cn: Replicators
gidNumber: 552
description: Netbios Domain Supports file replication in a sambaDomainName
sambaSID: S-1-5-32-552
sambaGroupType: 4
displayName: Replicators

# search result
search: 2
result: 0 Success

ユーザー・グループ追加

smbldap-toolsのコマンドで登録する。

# smbldap-groupadd -a ldapusers
# smbldap-groupadd -a ldapwheel
# smbldap-useradd  -a -m -g ldapusers -G ldapwheel -c "Dummy User" dummy
# smbldap-passwd dummy

SSSD

# yum -y install sssd
# vi /etc/sssd/sssd.conf
/etc/sssd/sssd.conf
[sssd]
debug_level = 9
config_file_version = 2
services = nss, pam
domains = LDAP

[domain/LDAP]
ldap_schema = rfc2307
cache_credentials = true

id_provider     = ldap
auth_provider   = ldap
chpass_provider = ldap

ldap_uri = ldap://localhost
ldap_search_base = dc=my-domain,dc=com
ldap_user_gid_number = gidNumber
ldap_id_use_start_tls = false
ldap_tls_reqcert = never
ldap_chpass_uri = ldap://localhost
ldap_group_member = memberUid
sudo_provider = ldap
ldap_sudo_search_base = ou=Group,dc=my-domain,dc=com

enumerate = true
# chmod 600 /etc/sssd/sssd.conf
# systemctl start sssd
# id dummy
(ユーザーIDなどが表示される)

authconfig

idコマンドでユーザーが表示されても、この段階ではsshなどではログインできない。
authconfigを実行し、sshなどでログインできるようにする。

# authconfig \
    --enablesssd --enablesssdauth --enablelocauthorize \
    --disableldap --disableldapauth --disableldaptls \
    --update

Samba

# vi /etc/samba/ldap.conf
/etc/samba/ldap.conf
passdb backend = ldapsam:ldap://localhost/

ldap suffix = dc=my-domain,dc=com
ldap admin dn = cn=Manager,dc=my-domain,dc=com
ldap group suffix = ou=Group
ldap machine suffix = ou=Computers
ldap user suffix = ou=Users
ldap ssl = off
# vi /etc/samba/smb.conf
/etc/samba/smb.conf
        #passdb backend = tdbsam
        include = /etc/samba/ldap.conf
# smbpasswd -W
Setting stored password for "cn=Manager,dc=my-domain,dc=com" in secrets.tdb
New SMB password:
Retype new SMB password:
# firewall-cmd --add-service samba
success
# firewall-cmd --add-service samba --permanent
success

Windowsのエクスプローラから \\192.168.56.105\dummy にアクセスできることを確認する。

動作確認ができたら、ブート時にサービスが起動するようにする。

# systemctl enable slapd
# systemctl enable sssd
# systemctl enable smb

SELinuxが有効な場合、ホームディレクトリにファイルを作成できないので、
以下のコマンドを実行し、SELinuxの設定を変更する。

setsebool -P samba_enable_home_dirs on
setsebool -P samba_export_all_rw on

再度Windowsのエクスプローラでアクセスし、フォルダやファイルを生成できることを確認する。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1