Configuring Kerberos Authentication for Windows
You can configure your Kerberos setup so that you use the MIT Kerberos Ticket Manager to get the Ticket Granting Ticket (TGT), or configure the setup so that you can use the connector to get the ticket directly from the Key Distribution Center (KDC). Also, if a client application obtains a Subject with a TGT, it is possible to use that Subject to authenticate the connection.
Downloading and Installing MIT Kerberos for Windows
To download and install MIT Kerberos for Windows 4.0.1:
- Download the appropriate Kerberos installer:
- For a 64-bit machine, use the following download link from the MIT Kerberos website: http://web.mit.edu/kerberos/dist/kfw/4.0/kfw-4.0.1-amd64.msi.
- For a 32-bit machine, use the following download link from the MIT Kerberos website: http://web.mit.edu/kerberos/dist/kfw/4.0/kfw-4.0.1-i386.msi.
Note:The 64-bit installer includes both 32-bit and 64-bit libraries. The 32-bit installer includes 32-bit libraries only.
- To run the installer, double-click the
.msi
file that you downloaded. - Follow the instructions in the installer to complete the installation process.
- When the installation completes, click Finish.
Using the MIT Kerberos Ticket Manager to Get Tickets
Setting the KRB5CCNAME Environment Variable
You must set the KRB5CCNAME environment variable to your credential cache file.
To set the KRB5CCNAME environment variable:
- Click Start
, then right-click Computer, and then click Properties.
- Click Advanced System Settings.
- In the System Properties dialog box, on the Advanced tab, click Environment Variables.
- In the Environment Variables dialog box, under the System Variables list, click New.
- In the New System Variable dialog box, in the Variable Name field, type KRB5CCNAME.
- In the Variable Value field, type the path for your credential cache file. For example, type
C:\KerberosTickets.txt
. - Click OK to save the new variable.
- Make sure that the variable appears in the System Variables list.
- Click OK to close the Environment Variables dialog box, and then click OK to close the System Properties dialog box.
- Restart your machine.
Getting a Kerberos Ticket
To get a Kerberos ticket:
- Click Start
, then click All Programs, and then click the Kerberos for Windows (64-bit) or Kerberos for Windows (32-bit) program group.
- Click MIT Kerberos Ticket Manager.
- In the MIT Kerberos Ticket Manager, click Get Ticket.
- In the Get Ticket dialog box, type your principal name and password, and then click OK.
If the authentication succeeds, then your ticket information appears in the MIT Kerberos Ticket Manager.
Authenticating to the Hive Server
You provide this information to the connector in the connection URL. For more information about the syntax of the connection URL,
To authenticate to the Hive server:
- Use a connection URL that has the following properties defined:
AuthMech
KrbHostFQDN
KrbRealm
KrbServiceName
For detailed information about these properties, see
Using the Connector to Get Tickets
Deleting the KRB5CCNAME Environment Variable
To enable the connector to get Ticket Granting Tickets (TGTs) directly, make sure that the KRB5CCNAME environment variable has not been set.
To delete the KRB5CCNAME environment variable:
- Click the Start button
, then right-click Computer, and then click Properties.
- Click Advanced System Settings.
- In the System Properties dialog box, click the Advanced tab and then click Environment Variables.
- In the Environment Variables dialog box, check if the KRB5CCNAME variable appears in the System variables list. If the variable appears in the list, then select the variable and click Delete.
- Click OK to close the Environment Variables dialog box, and then click OK to close the System Properties dialog box.
Setting Up the Kerberos Configuration File
To set up the Kerberos configuration file:
- Create a standard
krb5.ini
file and place it in theC:\Windows
directory. - Make sure that the KDC and Admin server specified in the
krb5.ini
file can be resolved from your terminal. If necessary, modifyC:\Windows\System32\drivers\etc\hosts
.
Setting Up the JAAS Login Configuration File
To set up the JAAS login configuration file:
- Create a JAAS login configuration file that specifies a keytab file and
doNotPrompt=true
.For example:
Client {
com.sun.security.auth.module.Krb5LoginModule required
useKeyTab=true
keyTab="PathToTheKeyTab"
principal="simba@SIMBA"
doNotPrompt=true;
};
- Set the
java.security.auth.login.config
system property to the location of the JAAS file.For example:
C:\KerberosLoginConfig.ini
.
JAAS
configuration is disabled by default. To enable JAAS
configuration, please set the JDBC_ENABLE_JAAS
environment variable to 1
.
Authenticating to the Hive Server
You provide this information to the connector in the connection URL. For more information about the syntax of the connection URL,
To authenticate to the Hive server:
- Use a connection URL that has the following properties defined:
AuthMech
KrbHostFQDN
KrbRealm
KrbServiceName
For detailed information about these properties, see
Using an Existing Subject to Authenticate the Connection
If the client application obtains a Subject with a TGT, then that Subject can be used to authenticate the connection to the server.
To use an existing Subject to authenticate the connection:
- Create a PrivilegedAction for establishing the connection to the database.
For example:
// Contains logic to be executed as a privileged action
public class AuthenticateDriverAction
implements PrivilegedAction<Void>
{
// The connection, which is established as a PrivilegedAction
Connection con;
// Define a string as the connection URL
static String ConnectionURL = "jdbc:hive2://192.168.1.1:10000";
/**
* Logic executed in this method will have access to the
* Subject that is used to "doAs". The connector will get
* the Subject and use it for establishing a connection
* with the server.
*/
@Override
public Void run()
{
try
{
// Establish a connection using the connection URL
con = DriverManager.getConnection(ConnectionURL);
}
catch (SQLException e)
{
// Handle errors that are encountered during
// interaction with the data store
e.printStackTrace();
}
catch (Exception e)
{
// Handle other errors
e.printStackTrace();
}
return null;
}
}
- Run the PrivilegedAction using the existing Subject, and then use the connection.
For example:
// Create the action
AuthenticateDriverAction authenticateAction = new AuthenticateDriverAction();
// Establish the connection using the Subject for
// authentication.
Subject.doAs(loginConfig.getSubject(), authenticateAction);
// Use the established connection.
authenticateAction.con;