这绝对是可能的。见这里:https://www.percona.com/blog/2017/04/21/how-to-setup-and-troubleshoot-percona-pam-with-ldap-for-external-authentication/
在我的环境中,我没有设置 Samba 或 NSS/SSS,也没有加入 windows 域。我只是将 AD 服务器视为 LDAP 端点。所以我从上述方向的第 9 步开始。
编辑:按照 AfroThundr 的建议从上述链接添加说明
安装 Percona PAM 插件:
mysql> INSTALL PLUGIN auth_pam SONAME 'auth_pam.so';
Query OK, 0 rows affected (0.01 sec)
mysql> INSTALL PLUGIN auth_pam_compat SONAME 'auth_pam_compat.so';
Query OK, 0 rows affected (0.00 sec)
通过使用以下内容创建 /etc/pam.d/mysqld 来配置 Percona PAM 以向 LDAP 进行身份验证:
auth required pam_ldap.so
account required pam_ldap.so
创建一个将通过 auth_pam 进行身份验证的 MySQL 用户:
mysql> CREATE USER user@'%' IDENTIFIED WITH auth_pam;
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT ALL PRIVILEGES ON testdb.* TO user@'%';
Query OK, 0 rows affected (0.00 sec)
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
以该用户身份登录并检查授权:
[root@ps-20 ~]# mysql -u user
Password: <your LDAP/AD password>
Welcome to the MySQL monitor. Commands end with ; or g.
Your MySQL connection id is 22
Server version: 5.7.17-13 Percona Server (GPL), Release 13, Revision fd33d43
Copyright (c) 2009-2016 Percona LLC and/or its affiliates
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or 'h' for help. Type 'c' to clear the current input statement.
mysql> SHOW GRANTS;
+-----------------------------------------------------+
| Grants for user@% |
+-----------------------------------------------------+
| GRANT USAGE ON *.* TO 'user'@'%' |
| GRANT ALL PRIVILEGES ON `testdb`.* TO 'user'@'%' |
+---------------------------------------------------
还要小心 AppArmor - 它会阻止身份验证尝试。您可能会在/var/log/auth.log 中看到误导性错误消息:
Feb 12 13:37:36 mysqld[15164]: PAM _pam_init_handlers: no default config /etc/pam.d/other
Feb 12 13:37:36 mysqld[15164]: PAM error reading PAM configuration file
Feb 12 13:37:36 mysqld[15164]: PAM pam_start: failed to initialize handlers
您需要将以下内容添加到/etc/apparmor.d/local/usr.sbin.mysqld:
#include <abstractions/authentication>
并重新加载apparmor:
service apparmor restart
(感谢https://bugs.launchpad.net/ubuntu/+source/squid/+bug/1608984 引导我进入 AppArmor 部分)