首页 > 解决方案 > MariaDB LDAP PAM 身份验证

问题描述

我的本地测试环境中有一个 Active Directory 和一个 MariaDB 服务器。现在我想让在 MariaDB 下使用 AD 用户登录成为可能。

我已经看过一些教程,这里几乎所有关于它的主题。

我的 /etc/nslc.conf:

    uid nslcd
    gid nslcd
    uri ldap://172.29.210.219/
    base dc=saptest,dc=local
    ldap_version 3
    binddn CN=bind,CN=Users,DC=SAPTEST,DC=LOCAL
    bindpw supersecurepassword
    ssl off
    filter passwd (objectClass=user)
    map passwd uid sAMAccountName

我的 /etc/pam.d/mariadb

auth sufficient pam_ldap.so
account sufficient pam_ldap.so

我在 MariaDB 中的步骤

INSTALL SONAME 'auth_pam';
CREATE USER 'admin'@'%' IDENTIFIED VIA pam USING 'mariadb';
GRANT ALL ON *.* TO 'admin'@'%';
FLUSH PRIVILEGES;
EXIT;

当我执行“mysql -u admin -p”时,出现以下错误:

ERROR 1045 (28000): Access denied for user 'admin'@'localhost' (using password: NO)

提前谢谢了。

标签: ldapmariadbpam

解决方案


我发现在 SLES15SP3 上的 MariaDB 实例 10.5.12 上,pam.d 中的配置文件必须称为“mysql”,并且用户创建语句末尾的“USING”选项不起作用。

https://jira.mariadb.org/browse/MDEV-26876

CREATE USER 'admin'@'%' IDENTIFIED VIA pam;

/etc/pam.d/mysql

auth required pam_ldap.so
auth required pam_warn.so
account required pam_ldap.so
account required pam_warn.so

pam_warn 会将日志消息吐出到 syslog(在我的情况下为 Journal) https://www.docs4dev.com/docs/en/linux-pam/1.1.2/reference/sag-pam_warn.html

ldap 配置必须在 /etc/ldap.conf 中:

base dc=[redacted]
binddn cn=[redacted]
bindpw [redacted]
uri ldap://[redacted]:389
pam_login_attribute sAMAccountName
pam_filter objectclass=User

推荐阅读