Support Questions

Find answers, ask questions, and share your expertise
Celebrating as our community reaches 100,000 members! Thank you!

Hive JDBC driver with keytab authentication


Hi, I am using a 3rd party ETL application that I would like to connect to Hive as a datasource, using the Hive JDBC driver. Our Hive is kerberized so it needs a kerberos ticket to be able to connect. I am wondering if there is any way to automatically trigger a login from keytab when the application tries to connect to Hive. The tool itself is Java-based so I can set Java system properties when it starts, and I can also add config settings to the Hive JDBC connection string.

I've been able to get this to work by running a kinit before the process and setting, but I'd like to avoid this because it seems to be unreliable (sometimes when connecting to the DB the Java kerberos system ends up prompting for a username and password, even though the Kinit just ran, and I don't know why).

I have also tried setting a custom JAAS conf file as: { required



keyTab=(path to keytab)


debug=true; };

This doesn't seem to do anything. My guess is that Hadoop UserGroupInformation class, which the JDBC driver uses to handle security, ignores these JAAS settings.

So to sum it up - is there any way I can get the JDBC driver to automatically login from keytab, by either setting Java system properties or changing the JDBC connection string?




Hi @Karl Fredrickson

If you have Knox you can use it to encapsulate Kerberos authentication and use username/password.



Thanks @dvillarreal and @Abdelkrim Hadjidj, it turned out that using a gss-jaas.conf file does work to auto-login from keytab, I just had to make sure to also set

in the startup options of the ETL tool.

I forgot to mention that this was in a Windows environment, so this could help with using the Hive JDBC driver with other Windows tools.

New Contributor

If you already have a TGT available in cache, then below code worked for me

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.apache.hadoop.conf.Configuration;

class HiveBeelineTest  {

  public static void main(String args[]) throws ClassNotFoundException, SQLException {

	Configuration conf = new Configuration();
        conf.set("", "Kerberos");
	Connection con = DriverManager.getConnection(
        Statement sqlstatement = con.createStatement();
        ResultSet result = sqlstatement.executeQuery("select test_column from test_table");
	while ( {