Amazon Directory ServiceとAmazon Linux2インスタンスでSSHの認証がうまくいかない


構成(やりたかったこと)

  • Amazon Directory ServiceでADを構成
  • Amazon Linux2のインスタンスでADを利用したSSHの認証を行う

AWSのガイドの通り進めてみましたが、Amazon Linux2で動きません。。
https://docs.aws.amazon.com/directoryservice/latest/admin-guide/join_linux_instance.html

状況

  • Amazon Linux1: ガイドの手順通りに進めればドメインユーザでSSHできる
  • Amazon Linux2: ガイドの手順通りに進めてもドメインユーザでSSHきない
  • Amazon Linux2: ドメインには参加できる (realm joinはOK)
  • Amazon Linux2: idは引ける(id ドメインユーザー@ドメイン)
  • Amazon Linux2: ドメインユーザにsu はできる
  • Amazon Linux2: ドメインユーザでssh試行時、/var/log/messagesにGSSAPIのエラーが吐かれる。。
    
    ip-172-30-0-162 sssd: tkey query failed: GSSAPI error: Major = Unspecified GSS failure.  Minor code may provide more information, Minor = Server not found in Kerberos database.
    ip-172-30-0-162 sssd: tkey query failed: GSSAPI error: Major = Unspecified GSS failure.  Minor code may provide more information, Minor = Server not found in Kerberos database.
    
  • Amazon Linux2: ドメインユーザでssh試行時、/var/log/secureには"authentication success"と。
    
    sshd[3709]: pam_sss(sshd:auth): authentication success; logname= uid=0 euid=0 tty=ssh ruser= rhost=localhost user=ユーザー名@ドメイン
    sshd[3709]: Failed password for ユーザ名@ドメイン from 127.0.0.1 port 59446 ssh2
    sshd[3709]: fatal: Access denied for user ユーザー名@ドメイン by PAM account configuration [preauth]
    

この状況のキーワードでググると、同じような状況の記事が。。

pamでADにログインできなくなった話。PAM(Linux認証)の動作

この記事では/etc/pam.d/password-authの以下の行をコメントアウトする、という内容でした。


account     [default=bad success=ok user_unknown=ignore] pam_sss.so

確かにaccount pam_sss.soを外せばSSHできるようになりました。
でも、accountの処理を外してしまうとパスワードの期限や有効性のチェックなど重要な処理が抜けてしまいます。
accountを外さずに動く方法を探さなくては。

解決策!!

根気強くググりまくっていると、redhatのドキュメントにそれっぽいのをようやく見つけました。

An Active Directory identity provider is properly configured in my sssd.conf file, but SSSD fails to connect to it, with GSS-API errors.

そして対処法は・・・・

SSSD can only connect with an Active Directory provider using its host name. If the host name is not given, the SSSD client cannot resolve the IP address to the host, and authentication fails.

/etc/sssd/sssd.confのドメインセクションにad_serverを追加するといいらしい。
sssd.confを見てみると、ad_domainはあったものの、ad_serverは設定されていませんでした。
試しに
ad_server = adのホスト名
と追記してsssdを再起動したところ、ドメインユーザでのsshも成功!


[sssd]
domains = ドメイン名
config_file_version = 2
services = nss, pam

[domain/ドメイン名]
ad_domain = ドメイン名
ad_server = ドメイン名

ad_server

ad_serverとはなんのための定義なのか?
Redhatのドキュメントには以下のように記載されていました。

only needed if DNS discovery is not working

manでは

The comma-separated list of IP addresses or hostnames of the AD servers to which SSSD should connect in order of preference. For more information on failover and server redundancy, see the "FAILOVER" section.
This is optional if autodiscovery is enabled. For more information on service discovery, refer to the "SERVICE DISCOVERY" section.

うーむ。そもそもAmazon Linux1ではad_server=の定義なしで動いているのですが。
realm join -U ユーザ名@ドメイン ドメイン でドメインにも参加出来ていましたし。

動きはしたものの、結局原因にはたどり着けていません。