• HiveServer2 简单用户/密码身份验证


    前言

    Hive 通过HiveServer2对外提供服务,HiveServer2 是一种能使客户端执行 Hive 查询的服务。HiveServer2 是 HiveServer1 的改进版,HiveServer1 已经被废弃。HiveServer2 对 HiveServer 进行了重写来解决上述问题。

    HiveServer2 作为复合服在单个进程中运行,其中包括基于 Thrift 的 Hive 服务(TCP或HTTP)以及用于 Web UI的 Jetty Web 服务。HiveServer2 可以支持多客户端并发和身份认证。旨在为开放API客户端(如JDBC和ODBC)提供更好的支持。

    架构

    HiveServer2 实现了一个新的基于 Thrift 的 RPC 接口,该接口可以处理客户端并发请求。当前版本支持 Kerberos,LDAP 以及自定义可插拔身份验证。新的 RPC 接口也是 JDBC 和 ODBC 客户端更好的选择,尤其是对于元数据访问。

    hive身份认证的三种方式

    NONE:即不做身份校验;

    LDAP: 使用基于 LDAP/AD 的用户身份校验;

    KERBEROS: 使用 Kerberos/GSSAPI 做身份校验;

    CUSTOM:自定义认证

    针对当前简单应用场景,采用CUSTOM就可满足

    配置CUSTOM身份认证流程

    1.首先需要编写用户权限验证的类

    1. import org.apache.hadoop.conf.Configurable;
    2. import org.apache.hadoop.hive.conf.HiveConf;
    3. import org.apache.hive.service.auth.PasswdAuthenticationProvider;
    4. import org.slf4j.Logger;
    5. import org.slf4j.LoggerFactory;
    6. import org.apache.hadoop.conf.Configuration;
    7. import javax.security.sasl.AuthenticationException;
    8. /**
    9. * @author liguiping
    10. * @version 1.0.0
    11. * @since 2022-09-28 10:00
    12. **/
    13. public class AuthLogin implements PasswdAuthenticationProvider, Configurable {
    14. private static Logger LOG = LoggerFactory.getLogger(AuthLogin.class);
    15. private String user;
    16. private String pwd;
    17. private Configuration conf = null;
    18. public AuthLogin() {
    19. user = getConf().get("hive.auth.user");
    20. pwd = getConf().get("hive.auth.pwd");
    21. }
    22. @Override
    23. public void setConf(Configuration configuration) {
    24. }
    25. @Override
    26. public Configuration getConf() {
    27. if (this.conf == null) {
    28. HiveConf conf = new HiveConf();
    29. this.conf = new Configuration(conf);
    30. }
    31. return this.conf;
    32. }
    33. @Override
    34. public void Authenticate(String username, String password) throws AuthenticationException {
    35. if (username == null || password == null) {
    36. throw new AuthenticationException("error.");
    37. }
    38. LOG.info("user: " + username + " try login.");
    39. if (!user.equals(username)) {
    40. String message = "user name not exist:";
    41. throw new AuthenticationException(message);
    42. } else {
    43. if (!password.equals(pwd)) {
    44. String message = "user name and password is mismaPasswdAuthenticationProvidertch. user:" + username;
    45. throw new AuthenticationException(message);
    46. }
    47. }
    48. LOG.info("user " + username + " login system successfully.");
    49. }
    50. }

    pom依赖

    1. <?xml version="1.0" encoding="UTF-8"?>
    2. <project xmlns="http://maven.apache.org/POM/4.0.0"
    3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    4. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    5. <modelVersion>4.0.0</modelVersion>
    6. <groupId>cn.li</groupId>
    7. <artifactId>hive-auth</artifactId>
    8. <version>1.0</version>
    9. <dependencies>
    10. <dependency>
    11. <groupId>org.apache.hadoop</groupId>
    12. <artifactId>hadoop-common</artifactId>
    13. <version>3.3.1</version>
    14. </dependency>
    15. <!-- https://mvnrepository.com/artifact/org.apache.hive/hive-common -->
    16. <dependency>
    17. <groupId>org.apache.hive</groupId>
    18. <artifactId>hive-common</artifactId>
    19. <version>3.1.2</version>
    20. </dependency>
    21. <dependency>
    22. <groupId>commons-logging</groupId>
    23. <artifactId>commons-logging</artifactId>
    24. <version>1.2</version>
    25. </dependency>
    26. <dependency>
    27. <groupId>org.apache.hive</groupId>
    28. <artifactId>hive-service</artifactId>
    29. <version>3.1.2</version>
    30. </dependency>
    31. </dependencies>
    32. </project>

    将以上文件打包

    mvn install

    2.配置及复制jar包

    将上面的程序打包的hive-auth-1.0.jar,放到$HIVE_HOME/lib下

    配置hive-site.xml,追加以下文件

    1. <property>
    2. <name>hive.server2.authentication</name>
    3. <value>CUSTOM</value>
    4. </property>
    5. <property>
    6. <name>hive.server2.custom.authentication.class</name>
    7. <value>AuthLogin</value>
    8. </property>
    9. <property>
    10. <name>hive.auth.user</name>
    11. <value>admin</value>
    12. </property>
    13. <property>
    14. <name>hive.auth.pwd</name>
    15. <value>Aa123456</value>
    16. </property>

    hive.auth.user为用户名

    hive.auth.pwd为密码

  • 相关阅读:
    python+django新生入学报到迎新系统nodejs+vue+elementui
    SpringCloud Alibaba微服务实战五 - 配置隔离
    【前端设计模式】之装饰模式
    Memtester框架是什么
    MapReduce执行流程
    vue2升级vue3的新变化
    【C++ STL容器】:vector存放数据以及存放自定义的数据类型
    iOS获取当前网络连接状态WiFi、5G、4G、3G、2G
    unix:///var/tmp/supervisor.sock no such file
    【一篇就够】异步相关(一)
  • 原文地址:https://blog.csdn.net/weixin_38751513/article/details/127089564