6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

ユーザーの管理と認証(NSS, PAM, SSSD)

Last updated at Posted at 2020-06-20

NSS(Name Service Switch)とは?

  • ユーザーやホストなどの各種情報の検索先と検索順序を指定する為に使用
  • /etc/nsswitch.confファイルに対象カテゴリのデータベースと検索先を優先順に記載
/etc/nsswitch.conf

# /etc/nsswitch.conf

# To use db, put the "db" in front of "files" for entries you want to be
# looked up first in the databases
#
# Example:
#passwd:    db files nisplus nis
#shadow:    db files nisplus nis
#group:     db files nisplus nis

passwd:     files sss
shadow:     files sss
group:      files sss
#initgroups: files sss

#hosts:     db files nisplus nis dns
hosts:      files dns myhostname

ethers:     files
netmasks:   files
networks:   files
protocols:  files
rpc:        files
services:   files sss

netgroup:   nisplus sss

publickey:  nisplus

automount:  files nisplus sss
aliases:    files nisplus
# 関連するファイルの一つを確認
cat /etc/pam.d/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        required      pam_deny.so

account     required      pam_unix.so
account     sufficient    pam_localuser.so
account     sufficient    pam_succeed_if.so uid < 1000 quiet
account     required      pam_permit.so

password    requisite     pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type=
password    sufficient    pam_unix.so sha512 shadow nullok try_first_pass 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

SSSD(System Security Service Daemon)の設定と使用

  • SSSDの導入により、OpenLDAP, Active Directory, FreeIPAなどの認証システムへのアクセスが可能になる
  • 認証情報をキャッシュし、オフラインでの利用が可能になる

SSSDを使用する為にはNSSとPAMの設定が必要

# authconfigコマンドを実行し、/etc/nsswitch.confにsssモジュールの記述を追加する
authconfig --enablesssd --enablesssdauth --update
# 実行前から既に追加されていた模様ですが、再度確認。
cat /etc/nsswitch.conf
passwd:     files sss
shadow:     files sss
group:      files sss
#initgroups: files sss
()
ethers:     files
netmasks:   files
networks:   files
protocols:  files
rpc:        files
services:   files sss

netgroup:   nisplus sss

publickey:  nisplus

automount:  files nisplus sss
aliases:    files nisplus

# /etc/pam.d/system-authと/etc/pam.d/password-authファイルを確認
cat /etc/pam.d/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        [default=1 ignore=ignore success=ok] pam_succeed_if.so uid >= 1000 quiet
auth        [default=1 ignore=ignore success=ok] pam_localuser.so
auth        sufficient    pam_unix.so nullok try_first_pass
auth        requisite     pam_succeed_if.so uid >= 1000 quiet_success
# pam_sss.soモジュール確認OK
auth        sufficient    pam_sss.so forward_pass
auth        required      pam_deny.so

account     required      pam_unix.so
account     sufficient    pam_localuser.so
account     sufficient    pam_succeed_if.so uid < 1000 quiet
# pam_sss.soモジュール確認OK
account     [default=bad success=ok user_unknown=ignore] pam_sss.so
account     required      pam_permit.so

password    requisite     pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type=
password    sufficient    pam_unix.so sha512 shadow nullok try_first_pass use_authtok
# pam_sss.soモジュール確認OK
password    sufficient    pam_sss.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
# pam_sss.soモジュール確認OK
session     optional      pam_sss.so

cat /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        [default=1 ignore=ignore success=ok] pam_succeed_if.so uid >= 1000 quiet
auth        [default=1 ignore=ignore success=ok] pam_localuser.so
auth        sufficient    pam_unix.so nullok try_first_pass
auth        requisite     pam_succeed_if.so uid >= 1000 quiet_success
# pam_sss.soモジュール確認OK
auth        sufficient    pam_sss.so forward_pass
auth        required      pam_deny.so

account     required      pam_unix.so
account     sufficient    pam_localuser.so
account     sufficient    pam_succeed_if.so uid < 1000 quiet
# pam_sss.soモジュール確認OK
account     [default=bad success=ok user_unknown=ignore] pam_sss.so
account     required      pam_permit.so

password    requisite     pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type=
password    sufficient    pam_unix.so sha512 shadow nullok try_first_pass use_authtok
# pam_sss.soモジュール確認OK
password    sufficient    pam_sss.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
# pam_sss.soモジュール確認OK
session     optional      pam_sss.so

これで systemctl start sssd を試すとエラー (/etc/sssd/sssd.conf がない)
/etc/sssd/conf.d は作成されていたがディレクトリ配下にはファイルなし

参考書通りに /etc/sssd/sssd.conf を作成する

/etc/sssd/sssd.conf

[sssd]
config_file_version = 2
service = nss, pam
domain = LOCAL

[nss]
filter_groups = root
filter_users = root
entry_cache_timeout = 300

[pam]
offline_credentials_expiration = 2
offline_failed_login_attempts = 3
offline_failed_login_delay = 5

[domain/LOCAL]
id_provider = local
auth_provider = local
access_provider = permit

が今度は /etc/sssd/sssd.conf が権限がないので読めないとかいうエラーメッセージが出力された。

  • 上位ディレクトリに実行権限はある
    • 所有者はsssdユーザー
  • その他のユーザーにファイルの読み取り権限あり
    • 所有者はrootユーザー

sssd.conf の権限を変更し、所有者、グループをsssdユーザーに変更 ⇒ エラーメッセージ出力(内容は変わらず) ← イマココ

ググってみると ssd.conf のユーザーは rootユーザーのままで良いみたいなので戻す
(パーミッションは600だという事なのでこれも変更)

chown root:root /etc/sssd/sssd.conf

chmod 600 /etc/sssd/sssd.conf

sssdを起動するとやはりエラー だがメッセージ内容が「SSSD couldn't~」に変わり、これを調べると sssd.conf の記述が間違っている可能性がある。
一度 sssd.conf の内容を変更する(usr/share/ に雛形があるらしい)

/usr/share/doc/sssd-common-1.16.4/sssd-example.conf
cat /usr/share/doc/sssd-common-1.16.4/sssd-example.conf
[sssd]
config_file_version = 2
services = nss, pam
# SSSD will not start if you do not configure any domains.
# Add new domain configurations as [domain/<NAME>] sections, and
# then add the list of domains (in the order you want them to be
# queried) to the "domains" attribute below and uncomment it.
; domains = LDAP

[nss]

[pam]

# Example LDAP domain
; [domain/LDAP]
; id_provider = ldap
; auth_provider = ldap
# ldap_schema can be set to "rfc2307", which stores group member names in the
# "memberuid" attribute, or to "rfc2307bis", which stores group member DNs in
# the "member" attribute. If you do not know this value, ask your LDAP
# administrator.
; ldap_schema = rfc2307
; ldap_uri = ldap://ldap.mydomain.org
; ldap_search_base = dc=mydomain,dc=org
# Note that enabling enumeration will have a moderate performance impact.
# Consequently, the default value for enumeration is FALSE.
# Refer to the sssd.conf man page for full details.
; enumerate = false
# Allow offline logins by locally storing password hashes (default: false).
; cache_credentials = true

# An example Active Directory domain. Please note that this configuration
# works for AD 2003R2 and AD 2008, because they use pretty much RFC2307bis
# compliant attribute names. To support UNIX clients with AD 2003 or older,
# you must install Microsoft Services For UNIX and map LDAP attributes onto
# msSFU30* attribute names.
; [domain/AD]
; id_provider = ldap
; auth_provider = krb5
; chpass_provider = krb5
;
; ldap_uri = ldap://your.ad.example.com
; ldap_search_base = dc=example,dc=com
; ldap_schema = rfc2307bis
; ldap_sasl_mech = GSSAPI
; ldap_user_object_class = user
; ldap_group_object_class = group
; ldap_user_home_directory = unixHomeDirectory
; ldap_user_principal = userPrincipalName
; ldap_account_expire_policy = ad
; ldap_force_upper_case_realm = true
;
; krb5_server = your.ad.example.com
; krb5_realm = EXAMPLE.COM

これを sssd.conf に上書きして sssd を起動しても同じエラーメッセージ出力
内容を書き換える必要があると思うがよくわからないので、元の sssd.conf に戻し設定ファイルを雛形の内容と見比べる・・・・・・

設定ファイル「domain = LOCAL」  雛形ファイル「; domains = LDAP」
sがない・・・!!

domain を domainsに書き換えて試す   

/etc/sssd/sssd.conf
[sssd]
config_file_version = 2
service = nss, pam
domains = LOCAL

[nss]
filter_groups = root
(略)

これだけの変更で起動した!!
あー疲れた。

6
6
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
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?