使用 pam_succeed_if 将用户登录限制为单个组

使用 pam_succeed_if 将用户登录限制为单个组

我正在运行 Debian 9。我想要做的是将用户登录限制为属于“goodgroup”组成员的 uid。我忘记了最初从哪里得到这个解决方案,但这是我在 /etc/pam.d/common-account 中的内容:

.
.
.
# here are the per-package modules (the "Primary" block)
account [success=1 new_authtok_reqd=done default=ignore]    pam_unix.so 
# here's the fallback if no module succeeds
account requisite           pam_deny.so
# prime the stack with a positive return value if there isn't one already;
# this avoids us returning an error just because nothing sets a success code
# since the modules above will each just jump around
account required            pam_permit.so
# and here are more per-package modules (the "Additional" block)
account required            pam_krb5.so minimum_uid=1000
account sufficient          pam_localuser.so 

# >>> This is where I'm trying to do it <<<
account requisite                       pam_succeed_if.so user ingroup goodgroup

account [default=bad success=ok user_unknown=ignore]    pam_sss.so 
account [success=ok new_authtok_reqd=done ignore=ignore user_unknown=ignore auth
info_unavail=ignore default=bad]    pam_ldap.so minimum_uid=1000
# end of pam-auth-update config

假设我有一个 uid“baduid”,它不在所需的组中。我希望发生的是尝试“su baduid”作为 root 应该完全失败。实际发生的情况是 su 成功但 baduid 没有关联的主目录。

这是我执行“su baduid”时在日志文件中看到的内容:

May  3 16:08:03 myhost su[3014]: pam_succeed_if(su:account): requirement "user ingroup goodgroup" not met by user "baduid"
May  3 16:08:03 myhost su[3014]: Successful su for baduid by root
May  3 16:08:03 myhost su[3014]: + /dev/pts/0 root:baduid
May  3 16:08:03 myhost su[3014]: pam_unix(su:session): session opened for user baduid by root(uid=0)
May  3 16:08:03 myhost su[3014]: pam_systemd(su:session): Cannot create session: Already running in a session

相关内容