跳到主要内容
版本: 最新版本-3.5

LDAP 身份验证

除了原生的基于密码的身份验证,StarRocks 还支持 LDAP 认证。

本文档介绍如何在 StarRocks 中使用 LDAP 手动创建用户并进行身份验证。 有关如何使用安全集成将 StarRocks 与您的 LDAP 服务集成的说明,请参阅使用安全集成进行身份验证。 有关如何在 LDAP 服务中验证用户组的更多信息,请参阅验证用户组

启用 LDAD 认证

要使用 LDAP 认证,您需要先将 LDAP 服务添加到 FE 节点配置中。

# Add the LDAP service IP address.
authentication_ldap_simple_server_host =
# Add the LDAP service port, with a default value of 389.
authentication_ldap_simple_server_port =
# Whether to allow non-encrypted connections to the LDAP server. Default value: `true`. Setting this value to `false` indicates that SSL encryption is required to access LDAP.
authentication_ldap_simple_ssl_conn_allow_insecure =
# Local path to store the SSL CA certificate of the LDAP server. Supports pem and jks formats. You do not need to set this item if the certificate is issued by a trusted organization.
authentication_ldap_simple_ssl_conn_trust_store_path =
# The password used to access the locally stored SSL CA certificate of the LDAP server. pem-formatted certificates do not require a password. Only jsk-formatted certificates do.
authentication_ldap_simple_ssl_conn_trust_store_pwd =

如果您希望通过 StarRocks 直接在 LDAP 系统中检索用户的方式来验证用户身份,您将需要**添加以下附加配置项**。

# Add the Base DN of the user, specifying the user's retrieval range.
authentication_ldap_simple_bind_base_dn =
# Add the name of the attribute that identifies the user in the LDAP object. Default: uid.
authentication_ldap_simple_user_search_attr =
# Add the DN of the administrator account to be used when retrieving users.
authentication_ldap_simple_bind_root_dn =
# Add the password of theAdministrator account to be used when retrieving users.
authentication_ldap_simple_bind_root_pwd =

使用 LDAP 创建用户

创建用户时,通过IDENTIFIED WITH authentication_ldap_simple AS 'xxx' 将身份验证方法指定为 LDAP 认证。 xxx 是用户在 LDAP 中的 DN(Distinguished Name)。

示例 1

CREATE USER tom IDENTIFIED WITH authentication_ldap_simple AS 'uid=tom,ou=company,dc=example,dc=com'

可以创建一个用户而不指定用户在 LDAP 中的 DN。 当用户登录时,StarRocks 将转到 LDAP 系统检索用户信息。 如果只有一个匹配项,则身份验证成功。

示例 2

CREATE USER tom IDENTIFIED WITH authentication_ldap_simple

在这种情况下,需要向 FE 添加额外的配置

  • authentication_ldap_simple_bind_base_dn:用户的基本 DN,指定用户的检索范围。
  • authentication_ldap_simple_user_search_attr:LDAP 对象中标识用户的属性的名称,默认为 uid。
  • authentication_ldap_simple_bind_root_dn:用于检索用户信息的管理员帐户的 DN。
  • authentication_ldap_simple_bind_root_pwd:检索用户信息时使用的管理员帐户的密码。

验证用户

LDAP 认证要求客户端将明文密码传递给 StarRocks。 有三种方法可以传递明文密码

从带有 LDAP 的 MySQL 客户端连接

执行时添加 --default-auth mysql_clear_password --enable-cleartext-plugin

mysql -utom -P8030 -h127.0.0.1 -p --default-auth mysql_clear_password --enable-cleartext-plugin

从带有 LDAP 的 JDBC 客户端连接

  • JDBC

由于 JDBC 的默认 MysqlClearPasswordPlugin 需要 SSL 传输,因此需要自定义插件。

public class MysqlClearPasswordPluginWithoutSSL extends MysqlClearPasswordPlugin {
@Override
public boolean requiresConfidentiality() {
return false;
}
}

连接后,将自定义插件配置到属性中。

...
Properties properties = new Properties();// replace xxx.xxx.xxx to your package name
properties.put("authenticationPlugins", "xxx.xxx.xxx.MysqlClearPasswordPluginWithoutSSL");
properties.put("defaultAuthenticationPlugin", "xxx.xxx.xxx.MysqlClearPasswordPluginWithoutSSL");
properties.put("disabledAuthenticationPlugins", "com.mysql.jdbc.authentication.MysqlNativePasswordPlugin");DriverManager.getConnection(url, properties);
  • ODBC

在 ODBC 的 DSN 中添加 default\_auth=mysql_clear_passwordENABLE_CLEARTEXT\_PLUGIN=1:以及用户名和密码。