Browse Source

[core] Sasl fixes

Need to guarantee that strings are being sent to saslwrapper.
Need to use principal defined in hive-site.xml when connecting to metastore.
Abraham Elmahrek 13 years ago
parent
commit
75d094c7b9

+ 5 - 3
apps/beeswax/src/beeswax/hive_site.py

@@ -34,6 +34,7 @@ _METASTORE_LOC_CACHE = None
 
 
 _CNF_METASTORE_LOCAL = 'hive.metastore.local'
 _CNF_METASTORE_LOCAL = 'hive.metastore.local'
 _CNF_METASTORE_URIS = 'hive.metastore.uris'
 _CNF_METASTORE_URIS = 'hive.metastore.uris'
+_CNF_METASTORE_KERBEROS_PRINCIPAL = 'hive.metastore.kerberos.principal'
 
 
 # Host is whatever up to the colon. Allow and ignore a trailing slash.
 # Host is whatever up to the colon. Allow and ignore a trailing slash.
 _THRIFT_URI_RE = re.compile("^thrift://([^:]+):(\d+)[/]?$")
 _THRIFT_URI_RE = re.compile("^thrift://([^:]+):(\d+)[/]?$")
@@ -59,9 +60,9 @@ def get_conf():
 
 
 def get_metastore():
 def get_metastore():
   """
   """
-  get_metastore() -> (is_local, host, port)
+  get_metastore() -> (is_local, host, port, kerberos_principal)
 
 
-  Look at both hive-site.xml and beeswax.conf, and return the location of the metastore.
+  Look at both hive-site.xml and beeswax.conf, and return the metastore information.
 
 
   hive-site.xml supersedes beeswax.conf.
   hive-site.xml supersedes beeswax.conf.
   - If hive-site says local metastore (default), then get host & port from beeswax.conf.
   - If hive-site says local metastore (default), then get host & port from beeswax.conf.
@@ -71,6 +72,7 @@ def get_metastore():
   global _METASTORE_LOC_CACHE
   global _METASTORE_LOC_CACHE
   if not _METASTORE_LOC_CACHE:
   if not _METASTORE_LOC_CACHE:
     is_local = get_conf().getbool(_CNF_METASTORE_LOCAL, True)
     is_local = get_conf().getbool(_CNF_METASTORE_LOCAL, True)
+    kerberos_principal = get_conf().get(_CNF_METASTORE_KERBEROS_PRINCIPAL, None)
     if is_local:
     if is_local:
       host = beeswax.conf.BEESWAX_META_SERVER_HOST.get()
       host = beeswax.conf.BEESWAX_META_SERVER_HOST.get()
       port = beeswax.conf.BEESWAX_META_SERVER_PORT.get()
       port = beeswax.conf.BEESWAX_META_SERVER_PORT.get()
@@ -86,7 +88,7 @@ def get_metastore():
           LOG.fatal('Cannot understand remote metastore uri "%s"' % (thrift_uri,))
           LOG.fatal('Cannot understand remote metastore uri "%s"' % (thrift_uri,))
         else:
         else:
           host, port = match.groups()
           host, port = match.groups()
-    _METASTORE_LOC_CACHE = (is_local, host, int(port))
+    _METASTORE_LOC_CACHE = (is_local, host, int(port), kerberos_principal)
   return _METASTORE_LOC_CACHE
   return _METASTORE_LOC_CACHE
 
 
 
 

+ 1 - 1
apps/beeswax/src/beeswax/management/commands/beeswax_server.py

@@ -90,7 +90,7 @@ class Command(NoArgsCommand):
       args.append('true')
       args.append('true')
 
 
     # Start metastore as well?
     # Start metastore as well?
-    is_local, host, port = beeswax.hive_site.get_metastore()
+    is_local, host, port, kerberos_principal = beeswax.hive_site.get_metastore()
     if not is_local:
     if not is_local:
       LOG.info("Beeswax configured to use external metastore at %s:%s" % (host, port))
       LOG.info("Beeswax configured to use external metastore at %s:%s" % (host, port))
     else:
     else:

+ 3 - 1
apps/beeswax/src/beeswax/server/beeswax_lib.py

@@ -383,8 +383,10 @@ class BeeswaxClient:
         self._encode_partition(new_part)
         self._encode_partition(new_part)
         return self._client.alter_partition(db_name, tbl_name, new_part)
         return self._client.alter_partition(db_name, tbl_name, new_part)
 
 
-    _, host, port = hive_site.get_metastore()
+    _, host, port, metastore_kerberos_principal = hive_site.get_metastore()
     use_sasl, kerberos_principal_short_name = BeeswaxClient.get_security()
     use_sasl, kerberos_principal_short_name = BeeswaxClient.get_security()
+    # Use service name from kerberos principal set in hive-site.xml
+    kerberos_principal_short_name = metastore_kerberos_principal and metastore_kerberos_principal.split('/', 1)[0] or None
     client = thrift_util.get_client(ThriftHiveMetastore.Client,
     client = thrift_util.get_client(ThriftHiveMetastore.Client,
                                     host,
                                     host,
                                     port,
                                     port,

+ 7 - 1
apps/beeswax/src/beeswax/tests.py

@@ -1299,6 +1299,11 @@ def test_hive_site():
         <name>hive.metastore.warehouse.dir</name>
         <name>hive.metastore.warehouse.dir</name>
         <value>/abc</value>
         <value>/abc</value>
       </property>
       </property>
+
+      <property>
+        <name>hive.metastore.kerberos.principal</name>
+        <value>test/test.com@TEST.COM</value>
+      </property>
     </configuration>
     </configuration>
   """
   """
 
 
@@ -1316,11 +1321,12 @@ def test_hive_site():
     saved = beeswax.conf.BEESWAX_HIVE_CONF_DIR
     saved = beeswax.conf.BEESWAX_HIVE_CONF_DIR
     beeswax.conf.BEESWAX_HIVE_CONF_DIR = Getter()
     beeswax.conf.BEESWAX_HIVE_CONF_DIR = Getter()
 
 
-    is_local, host, port = beeswax.hive_site.get_metastore()
+    is_local, host, port, kerberos_principal = beeswax.hive_site.get_metastore()
     assert_false(is_local)
     assert_false(is_local)
     assert_equal(host, 'darkside-1234')
     assert_equal(host, 'darkside-1234')
     assert_equal(port, 9999)
     assert_equal(port, 9999)
     assert_equal(beeswax.hive_site.get_conf()['hive.metastore.warehouse.dir'], u'/abc')
     assert_equal(beeswax.hive_site.get_conf()['hive.metastore.warehouse.dir'], u'/abc')
+    assert_equal(kerberos_principal, 'test/test.com@TEST.COM')
   finally:
   finally:
     if saved is not None:
     if saved is not None:
       beeswax.conf.BEESWAX_HIVE_CONF_DIR = saved
       beeswax.conf.BEESWAX_HIVE_CONF_DIR = saved

+ 2 - 2
desktop/core/src/desktop/lib/thrift_util.py

@@ -210,8 +210,8 @@ def connect_to_thrift(conf):
   if conf.use_sasl:
   if conf.use_sasl:
     def sasl_factory():
     def sasl_factory():
       saslc = sasl.Client()
       saslc = sasl.Client()
-      saslc.setAttr("host", conf.host)
-      saslc.setAttr("service", conf.kerberos_principal)
+      saslc.setAttr("host", str(conf.host))
+      saslc.setAttr("service", str(conf.kerberos_principal))
       saslc.init()
       saslc.init()
       return saslc
       return saslc