社区版hiveserver2集成ldap

476 阅读2分钟

本文已参与「新人创作礼」活动,一起开启掘金创作之路。

引言

HiveServer2支持多种认证方式,通过hive.server2.authentication参数来设置,包括nosasl, none, ldap, kerberos, pam, custom。

如果是阿里云EMR的话参考:HiveServer2集成LDAP做用户认证-阿里云开发者社区

我这里是社区版本。

配置

配置备注
hive.server2.authenticationLDAP这里如果是可以是kerberos、ldap、null等等。如果是kerberos的话就是连接jdbc的时候需要使用到对应的principal。
hive.server2.authentication.ldap.urlldap://xxx.xx.xx.xxx:389ldap的url。可以填写ip或者是host。或者使用ldaps。
hive.server2.authentication.ldap.baseDNou=People,dc=dtsatck,dc=com绑定的用户的ou,这里解释可能不太准确。LDAP base DN (distinguished name).
hive.server2.authentication.ldap.userDNPatterncn=%s,ou=People,dc=dtstack,dc=com匹配下面的所有用户。A COLON-separated list of string patterns to represent the base DNs for LDAP Users. Use "%s" where the actual username is to be plugged in. See User Search List for details.

配置示例:

#新增/修改下列参数
<property>
    <name>hive.server2.authentication</name>
    <value>LDAP</value>
</property>
<property>
    <name>hive.server2.authentication.ldap.baseDN</name>
    <value>ou=People,dc=dtstack,dc=com</value>
</property>
<property>
    <name>hive.server2.authentication.ldap.url</name>
    <value>ldap://172.16.84.xx:389</value>
</property>
<property>
    <name>hive.server2.authentication.ldap.userDNPattern</name>
    <value>cn=%s,ou=People,dc=dtstack,dc=com</value>
</property>

修改完hive-site.xml配置后,重启一下HiveServer2,即可以生效。

PS:如果个人还有更多的配置需求,甚至group相关配置,可以参考官网配置:cwiki.apache.org/confluence/…

LDAP中添加账号

我这里是使用apacheds添加和修改用户的。地址:Downloads - Apache Directory

当然也可以使用命令写ldap的ldif文件去创建用户。两者都是可以的。

测试

成功。

如上可以正常连接。

如果使用的密码不正确,则会抛如下异常:
Error: Could not open client transport with JDBC Uri: jdbc:hive2://xxxx:10004/: Peer indicated failure: Error validating the login (state=08S01,code=0)

PS: 1、这里端口不要care,这里我这边是修改了hiveserver2的默认端口,改成了10004而已。默认应该是10000。 2、spark thrift server继承ldap的话,ldap的dn需要是uid=xxxx这种。因为源码里面需要去匹配uid。如果是cn=xxx的话会报错登录失败。可以改代码或者直接使用uid这种用户。