GSSAPI-Auth with PHP to MariaDB (Windows)

GSSAPI-Auth with PHP to MariaDB (Windows)

我目前正在研究在干净的 Windows 域环境中单点登录到数据库服务器。

并且由于 MySQL Enterprise 和 MSSQL 服务器目前没有选择,它归结为带有 GSSAPI 插件的 MariaDB。

这就是我目前拥有的:

Server:

Windows 7 x64 member of MYDOMAIN

MariaDB 10.2.14 x64

Apache2 2.4.33 x64 VC11 + mod_authnz_sspi + PHP 5.6.35 + mod_fcgid

MariaDB ODBC Driver x64

HeidiSQL (SQL-Client delivered with the MariaDB installer)

FCGID-Config 如下所示("A:" 不是我机器上的软盘驱动器,而是我实际放置 Apache2 的地方):

<IfModule !fcgid_module>
LoadModule fcgid_module modules/mod_fcgid.so

FcgidIOTimeout 64
FcgidConnectTimeout 16
FcgidMaxRequestsPerProcess 200
FcgidMaxProcesses 500
FcgidMaxRequestLen 8131072

FcgidInitialEnv PHPRC "A:/php"
FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 200
FcgidWrapper "A:/php/php-cgi.exe" .php
</IfModule>

Directory-Config 如下所示:

<Directory "${SRVROOT}/htdocs">
Options Indexes FollowSymLinks
AllowOverride None

AuthName "MYSERVER"
AuthType SSPI
SSPIAuth On
SSPIAuthoritative On
SSPIOfferBasic On
SSPIOfferSSPI On

<RequireAll>
    <RequireAny>
        Require sspi-group mygroup
    </RequireAny>
    <RequireNone>
        Require user "ANONYMOUS LOGON"
    </RequireNone>
</RequireAll>

SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=

<FilesMatch \.php>
    AddHandler fcgid-script .php
</FilesMatch>

Options +ExecCGI
</Directory>

没有对 php.ini 做任何花哨的事情,只是采用示例 php.ini-development(在 PHP zip 包中提供)并启用 php_mysql,php_mysqli、php_mbstring 和 php_ldap 扩展。

我当前的 MariaDBs my.ini 如下所示:

[mysqld]
datadir=M:/data
port=3306

key_buffer_size = 384M
max_allowed_packet = 512M
table_open_cache = 512

read_buffer_size = 256M
read_rnd_buffer_size = 128M
sort_buffer_size = 512M
query_cache_size = 32M
join_buffer_size = 128M

default-storage-engine = INNODB
innodb-page-size = 65536
innodb_buffer_pool_size = 4G
innodb_write_io_threads = 8
innodb_read_io_threads = 8
innodb_thread_concurrency = 16
innodb_log_buffer_size = 8M
innodb_log_file_size = 256M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 90
innodb_lock_wait_timeout = 120

character-set-server=utf8

thread_concurrency = 8
thread_cache_size = 8

[client]
port = 3306
plugin-dir = M:/lib/plugin

[mysqldump]
quick
max_allowed_packet = 512M

[mysql]
no-auto-rehash
safe-updates

Client:

Windows 10 x64 member of MYDOMAIN

Internet Explorer 11

MySQL Workbench 6.0 CE (6.0.7.11215)

设置完所有内容后,我将 VIA HeidiSQL(或任何 SQL-Client)连接到具有根帐户的 MariaDB-Server,并按照此处所述创建实际用户 https://mariadb.com/kb/en/library/authentication-plugin-gssapi/

CREATE USER myuser IDENTIFIED VIA gssapi AS 'myuser@MYDOMAIN';

现在在与 HeidiSQL 连接时或在 MySQL Workbench 提供 auth_gssapi_client.dll 之后(并且进程 运行ning 作为 myuser)我连接到 MariaDB-Server 没问题。

在尝试连接 PHP 之前,我查看了 phpinfo(); $_SERVER 变量 REMOTE_USER、PHP_AUTH_USER 和 PHP_AUTH_PW,一切看起来都和预期的一样。 这是我的 index.php:

<?php
    //phpinfo(); exit;
    $m = mysql_connect("localhost", $_SERVER["PHP_AUTH_USER"]);
    $mi = mysqli_connect("localhost", $_SERVER["PHP_AUTH_USER"]);
    $c = odbc_connect("MariaDB", $_SERVER["PHP_AUTH_USER"], "");
?>

正如您有时看到的那样,我使用 MariaDB ODBC 连接器设置了一个 SystemDSN,并将其命名为 MariaDB,它指向 MariaDBs 插件目录。

有了它,我至少可以尝试让它正常工作,然后再担心这些:

Warning: mysql_connect(): The server requested authentication method unknown to the client [auth_gssapi_client] in A:\htdocs\index.php on line 3
Warning: mysql_connect(): The server requested authentication method unknown to the client in A:\htdocs\index.php on line 3
Warning: mysqli_connect(): The server requested authentication method unknown to the client [auth_gssapi_client] in A:\htdocs\index.php on line 4
Warning: mysqli_connect(): (HY000/2054): The server requested authentication method unknown to the client in A:\htdocs\index.php on line 4

我找不到任何关于如何指向 mysql 或 mysqli 的 php 扩展的解决方案(或者我也测试了相同的结果 pdo_mysql ) 到 MariaDB 的 auth_gssapi_client.dll 插件。 因此,如果有人能指出我那里,那也将不胜感激。

但真正的问题,我也(很可能)运行 进入 mysql 和 mysqli,是 odbc 连接的结果......:

Warning: odbc_connect(): SQL error: [ma-3.0.3]GSSAPI name mismatch, requested 'myuser@MYDOMAIN', actual name 'myserver$@MYDOMAIN', SQL state 28000 in SQLConnect in A:\htdocs\index.php on line 5

进程本身 运行ning 作为本地系统,遗憾的是 GSSAPI 只对用户 运行ning 进程感兴趣,而不对经过身份验证的用户感兴趣。

我正在互联网上搜索并尝试了大约一个星期的时间来让它工作,尽管仍然没有任何有效的结果(或者关于下一步在这方面尝试什么的任何剩余想法)。

因此,如果有人对如何实现该功能有任何想法,那就太好了。

问候 TheSkyGuy

Warning: odbc_connect(): SQL error: [ma-3.0.3]GSSAPI name mismatch, requested 'myuser@MYDOMAIN', actual name 'myserver$@MYDOMAIN', SQL state 28000 in SQLConnect in A:\htdocs\index.php on line 5

这意味着您的应用程序 (apache?) 连接到计算机帐户,可能 运行 作为 NetworkService 用户,或类似的。如果您可以 运行 它在域用户 "myuser" 凭据下,那么它将连接。

或者,您可以创建与机器帐户对应的 MariaDB 用户帐户,并使用它进行连接。