Using Kerberos Authentication
Note: The following steps for enabling Kerberos are not required if you install HAWQ using Ambari.
You can control access to HAWQ with a Kerberos authentication server.
HAWQ supports the Generic Security Service Application Program Interface (GSSAPI) with Kerberos authentication. GSSAPI provides automatic authentication (single sign-on) for systems that support it. You specify the HAWQ users (roles) that require Kerberos authentication in the HAWQ configuration file pg_hba.conf. The login fails if Kerberos authentication is not available when a role attempts to log in to HAWQ.
Kerberos provides a secure, encrypted authentication service. It does not encrypt data exchanged between the client and database and provides no authorization services. To encrypt data exchanged over the network, you must use an SSL connection. To manage authorization for access to HAWQ databases and objects such as schemas and tables, you use settings in the pg_hba.conf file and privileges given to HAWQ users and roles within the database. For information about managing authorization privileges, see Managing Roles and Privileges.
For more information about Kerberos, see http://web.mit.edu/kerberos/.
Requirements for Using Kerberos with HAWQ
The following items are required for using Kerberos with HAWQ:
- Kerberos Key Distribution Center (KDC) server using the
krb5-serverlibrary - Kerberos version 5
krb5-libsandkrb5-workstationpackages installed on the HAWQ master host - System time on the Kerberos server and HAWQ master host must be synchronized. (Install Linux
ntppackage on both servers.) - Network connectivity between the Kerberos server and the HAWQ master
- Java 1.7.0_17 or later is required to use Kerberos-authenticated JDBC on Red Hat Enterprise Linux 6.x
- Java 1.6.0_21 or later is required to use Kerberos-authenticated JDBC on Red Hat Enterprise Linux 4.x or 5.x
Enabling Kerberos Authentication for HAWQ
Complete the following tasks to set up Kerberos authentication with HAWQ:
- Verify your system satisfies the prequisites for using Kerberos with HAWQ. See Requirements for Using Kerberos with HAWQ.
- Set up, or identify, a Kerberos Key Distribution Center (KDC) server to use for authentication. See Install and Configure a Kerberos KDC Server.
- Create and deploy principals for your HDFS cluster, and ensure that kerberos authentication is enabled and functioning for all HDFS services. See your Hadoop documentation for additional details.
- In a Kerberos database on the KDC server, set up a Kerberos realm and principals on the server. For HAWQ, a principal is a HAWQ role that uses Kerberos authentication. In the Kerberos database, a realm groups together Kerberos principals that are HAWQ roles.
Create Kerberos keytab files for HAWQ. To access HAWQ, you create a service key known only by Kerberos and HAWQ. On the Kerberos server, the service key is stored in the Kerberos database.
On the HAWQ master, the service key is stored in key tables, which are files known as keytabs. The service keys are usually stored in the keytab file
/etc/krb5.keytab. This service key is the equivalent of the service’s password, and must be kept secure. Data that is meant to be read-only by the service is encrypted using this key.Install the Kerberos client packages and the keytab file on HAWQ master.
Create a Kerberos ticket for
gpadminon the HAWQ master node using the keytab file. The ticket contains the Kerberos authentication credentials that grant access to the HAWQ.
With Kerberos authentication configured on the HAWQ, you can use Kerberos for PSQL and JDBC.
Set up HAWQ with Kerberos for PSQL
Set up HAWQ with Kerberos for JDBC
Install and Configure a Kerberos KDC Server
Steps to set up a Kerberos Key Distribution Center (KDC) server on a Red Hat Enterprise Linux host for use with HAWQ.
Follow these steps to install and configure a Kerberos Key Distribution Center (KDC) server on a Red Hat Enterprise Linux host.
Install the Kerberos server packages:
sudo yum install krb5-libs krb5-server krb5-workstationEdit the
/etc/krb5.confconfiguration file. The following example shows a Kerberos server with a defaultKRB.EXAMPLE.COMrealm.[logging] default = FILE:/var/log/krb5libs.log kdc = FILE:/var/log/krb5kdc.log admin_server = FILE:/var/log/kadmind.log [libdefaults] default_realm = KRB.EXAMPLE.COM dns_lookup_realm = false dns_lookup_kdc = false ticket_lifetime = 24h renew_lifetime = 7d forwardable = true default_tgs_enctypes = aes128-cts des3-hmac-sha1 des-cbc-crc des-cbc-md5 default_tkt_enctypes = aes128-cts des3-hmac-sha1 des-cbc-crc des-cbc-md5 permitted_enctypes = aes128-cts des3-hmac-sha1 des-cbc-crc des-cbc-md5 [realms] KRB.EXAMPLE.COM = { kdc = kerberos-gpdb:88 admin_server = kerberos-gpdb:749 default_domain = kerberos-gpdb } [domain_realm] .kerberos-gpdb = KRB.EXAMPLE.COM kerberos-gpdb = KRB.EXAMPLE.COM [appdefaults] pam = { debug = false ticket_lifetime = 36000 renew_lifetime = 36000 forwardable = true krb4_convert = false }The
kdcandadmin_serverkeys in the[realms]section specify the host (kerberos-gpdb) and port where the Kerberos server is running. IP numbers can be used in place of host names.If your Kerberos server manages authentication for other realms, you would instead add the
KRB.EXAMPLE.COMrealm in the[realms]and[domain_realm]section of thekdc.conffile. See the Kerberos documentation for information about thekdc.conffile.To create a Kerberos KDC database, run the
kdb5_util.kdb5_util create -sThe
kdb5_utilcreate option creates the database to store keys for the Kerberos realms that are managed by this KDC server. The-soption creates a stash file. Without the stash file, every time the KDC server starts it requests a password.Add an administrative user to the KDC database with the
kadmin.localutility. Because it does not itself depend on Kerberos authentication, thekadmin.localutility allows you to add an initial administrative user to the local Kerberos server. To add the usergpadminas an administrative user to the KDC database, run the following command:kadmin.local -q "addprinc gpadmin/admin"Most users do not need administrative access to the Kerberos server. They can use
kadminto manage their own principals (for example, to change their own password). For information aboutkadmin, see the Kerberos documentation.If needed, edit the
/var/kerberos/krb5kdc/kadm5.aclfile to grant the appropriate permissions togpadmin.Start the Kerberos daemons:
/sbin/service krb5kdc start /sbin/service kadmin startTo start Kerberos automatically upon restart:
/sbin/chkconfig krb5kdc on /sbin/chkconfig kadmin on
Create HAWQ Roles in the KDC Database
Add principals to the Kerberos realm for HAWQ.
Start kadmin.local in interactive mode, then add two principals to the HAWQ Realm.
Start
kadmin.localin interactive mode:kadmin.localAdd principals:
kadmin.local: addprinc gpadmin/kerberos-gpdb@KRB.EXAMPLE.COM kadmin.local: addprinc postgres/master.test.com@KRB.EXAMPLE.COMThe
addprinccommands prompt for passwords for each principal. The firstaddprinccreates a HAWQ user as a principal,gpadmin/kerberos-gpdb. The secondaddprinccommand creates thepostgresprocess on the HAWQ master host as a principal in the Kerberos KDC. This principal is required when using Kerberos authentication with HAWQ.Create a Kerberos keytab file with
kadmin.local. The following example creates a keytab filegpdb-kerberos.keytabin the current directory with authentication information for the two principals.kadmin.local: xst -k gpdb-kerberos.keytab gpadmin/kerberos-gpdb@KRB.EXAMPLE.COM postgres/master.test.com@KRB.EXAMPLE.COMYou will copy this file to the HAWQ master host.
Exit
kadmin.localinteractive mode with thequitcommand:kadmin.local: quit
Install and Configure the Kerberos Client
Steps to install the Kerberos client on the HAWQ master host.
Install the Kerberos client libraries on the HAWQ master and configure the Kerberos client.
Install the Kerberos packages on the HAWQ master.
sudo yum install krb5-libs krb5-workstationEnsure that the
/etc/krb5.conffile is the same as the one that is on the Kerberos server.Copy the
gpdb-kerberos.keytabfile that was generated on the Kerberos server to the HAWQ master host.Remove any existing tickets with the Kerberos utility
kdestroy. Run the utility as root.sudo kdestroyUse the Kerberos utility
kinitto request a ticket using the keytab file on the HAWQ master forgpadmin/kerberos-gpdb@KRB.EXAMPLE.COM. The-toption specifies the keytab file on the HAWQ master.# kinit -k -t gpdb-kerberos.keytab gpadmin/kerberos-gpdb@KRB.EXAMPLE.COMUse the Kerberos utility
klistto display the contents of the Kerberos ticket cache on the HAWQ master. The following is an example:# klist Ticket cache: FILE:/tmp/krb5cc_108061 Default principal: gpadmin/kerberos-gpdb@KRB.EXAMPLE.COM Valid starting Expires Service principal 03/28/13 14:50:26 03/29/13 14:50:26 krbtgt/KRB.EXAMPLE.COM @KRB.EXAMPLE.COM renew until 03/28/13 14:50:26
Set up HAWQ with Kerberos for PSQL
Configure a HAWQ to use Kerberos.
After you have set up Kerberos on the HAWQ master, you can configure HAWQ to use Kerberos. For information on setting up the HAWQ master, see Install and Configure the Kerberos Client.
Create a HAWQ administrator role in the database
template1for the Kerberos principal that is used as the database administrator. The following example usesgpamin/kerberos-gpdb.$ psql template1 -c 'CREATE ROLE "gpadmin/kerberos-gpdb" LOGIN SUPERUSER;'The role you create in the database
template1will be available in any new HAWQ that you create.Modify
hawq-site.xmlto specify the location of the keytab file. For example, adding this line to thehawq-site.xmlspecifies the folder /home/gpadmin as the location of the keytab filegpdb-kerberos.keytab.<property> <name>krb_server_keyfile</name> <value>/home/gpadmin/gpdb-kerberos.keytab</value> </property>Modify the HAWQ file
pg_hba.confto enable Kerberos support. Then restart HAWQ (hawq restart -a). For example, adding the following line topg_hba.confadds GSSAPI and Kerberos support. The value forkrb_realmis the Kerberos realm that is used for authentication to HAWQ.host all all 0.0.0.0/0 gss include_realm=0 krb_realm=KRB.EXAMPLE.COMFor information about the
pg_hba.conffile, see The pg_hba.conf file in the Postgres documentation.Create a ticket using
kinitand show the tickets in the Kerberos ticket cache withklist.As a test, log in to the database as the
gpadminrole with the Kerberos credentialsgpadmin/kerberos-gpdb:$ psql -U "gpadmin/kerberos-gpdb" -h master.test template1A username map can be defined in the
pg_ident.conffile and specified in thepg_hba.conffile to simplify logging into HAWQ. For example, thispsqlcommand logs into the default HAWQ onmdw.proddbas the Kerberos principaladminuser/mdw.proddb:$ psql -U "adminuser/mdw.proddb" -h mdw.proddbIf the default user is
adminuser, thepg_ident.conffile and thepg_hba.conffile can be configured so that theadminusercan log in to the database as the Kerberos principaladminuser/mdw.proddbwithout specifying the-Uoption:$ psql -h mdw.proddbThe
pg_ident.conffile defines the username map. This file is located in the HAWQ master data directory (identified by thehawq_master_directoryproperty value inhawq-site.xml):# MAPNAME SYSTEM-USERNAME GP-USERNAME mymap /^(.*)mdw\.proddb$ adminuserThe map can be specified in the
pg_hba.conffile as part of the line that enables Kerberos support:host all all 0.0.0.0/0 krb5 include_realm=0 krb_realm=proddb map=mymapFor more information about specifying username maps see Username maps in the Postgres documentation.
If a Kerberos principal is not a HAWQ user, a message similar to the following is displayed from the
psqlcommand line when the user attempts to log in to the database:psql: krb5_sendauth: Bad responseThe principal must be added as a HAWQ user.
Set up HAWQ with Kerberos for JDBC
Enable Kerberos-authenticated JDBC access to HAWQ.
You can configure HAWQ to use Kerberos to run user-defined Java functions.
- Ensure that Kerberos is installed and configured on the HAWQ master. See Install and Configure the Kerberos Client.
Create the file
.java.login.configin the folder/home/gpadminand add the following text to the file:pgjdbc { com.sun.security.auth.module.Krb5LoginModule required doNotPrompt=true useTicketCache=true debug=true client=true; };Create a Java application that connects to HAWQ using Kerberos authentication. The following example database connection URL uses a PostgreSQL JDBC driver and specifies parameters for Kerberos authentication:
jdbc:postgresql://mdw:5432/mytest?kerberosServerName=postgres&jaasApplicationName=pgjdbc&user=gpadmin/kerberos-gpdbThe parameter names and values specified depend on how the Java application performs Kerberos authentication.
Test the Kerberos login by running a sample Java application from HAWQ.