jdbc - 使用带有 kerberos keytab 的 jdbc 访问配置单元 Metastore

标签 jdbc hadoop hive kerberos

我正在尝试连接到已配置为使用 Kerberos 进行身份验证的配置单元元存储。当我不尝试使用 keytab 文件时,这对我有用,即当程序在身份验证过程中提示我输入密码时。当我更改配置以使用 key 表时,我得到一个很长的堆栈跟踪,其中包含以下语句:

Additional pre-authentication required (25) - Need to use PA-ENC-TIMESTAMP/PA-PK-AS-REQ

任何人都可以就我做错的地方提出任何建议吗?

如果相关的话,我的问题的上下文是我想从 mapreduce 作业访问 hive metastore,当然,mapreduce 作业无法回答提示。

我的程序是这样的:

package com.test;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class HiveJDBC {

   public static void main(String[] args) throws Exception {

      Class.forName("org.apache.hive.jdbc.HiveDriver");
      System.setProperty("java.security.auth.login.config","gss-jaas.conf");
      System.setProperty("sun.security.jgss.debug","true");
      System.setProperty("javax.security.auth.useSubjectCredsOnly","false");
      System.setProperty("java.security.krb5.conf","krb5.conf");

      Connection con = DriverManager.getConnection("jdbc:hive2://some.machine:10000/default;principal=hive/some.machine@MY_REALM");

      // Do stuff with the connection
   }
}

我的 gss-jaas.conf 文件如下所示:

com.sun.security.jgss.initiate {
   com.sun.security.auth.module.Krb5LoginModule required
   useKeyTab=true
   useTicketCache=false
   principal="my-account@MY_REALM"
   doNotPrompt=true
   keyTab="path-to-my-keytab-file"
   debug=true;
};

我的 krb5.conf 文件是这样的

[libdefaults]
default_realm = MY_REALM
dns_lookup_realm = false
dns_lookup_kdc = false
ticket_lifetime = 24h
renew_lifetime = 7d

[realms]     
 MY_REALM = {
  kdc = some.host:88
  admin_server = another.host
 }

我使用以下命令使用 ktutil 程序生成的 key 表文件

ktutil: addent -password -p username@MY_REALM -k 1 -e aes256-cts

最佳答案

显然,此错误是由于在发出 ktutil 命令时使用了错误的加密类型引起的。切换到正确的加密(我不会提及我们使用的是哪种)解决了问题。

关于jdbc - 使用带有 kerberos keytab 的 jdbc 访问配置单元 Metastore,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21375372/

相关文章:

hadoop - Serdes jar 不起作用

database - 将 Google Apps 脚本 IP 地址列入白名单的安全风险

eclipse - 如何使用Eclipse为hadoop创建可运行的jar

java - 建议使用示例配置单元查询,并提供示例以使用配置单元0.14创建,更新和删除表

hive - Impala:像查询一样显示表

java - 在 Windows 中使用文件路径加载数据查询配置单元

java - 流式处理结果集错误

java - 什么是更快的 : JDBC or JNDI?

java - Android 客户端 - Java 服务器 : how many clients can a server support at the same time?

hadoop - 关于HDFS复制,Oozie Libpath的正确设置是什么?