浏览代码

HUE-1088 [impala] Kerberos support

Adding in hue.ini:
[impala]
   # Kerberos principal
   ## impala_principal=impala/hostname.foo.com
Romain Rigaux 12 年之前
父节点
当前提交
f03f970

+ 11 - 4
apps/beeswax/src/beeswax/server/beeswax_lib.py

@@ -34,7 +34,7 @@ from beeswax import models
 from beeswax import hive_site
 from beeswax.models import BeeswaxQueryHandle
 from beeswax.server.dbms import Table, DataTable
-
+from impala.conf import IMPALA_PRINCIPAL
 
 LOG = logging.getLogger(__name__)
 
@@ -204,10 +204,17 @@ class BeeswaxClient:
     return self.db_client.get_default_configuration(*args, **kwargs)
 
   @classmethod
-  def get_security(cls):
+  def get_security(cls, query_server=None):
     cluster_conf = hadoop.cluster.get_cluster_conf_for_job_submission()
     use_sasl = cluster_conf is not None and cluster_conf.SECURITY_ENABLED.get()
-    kerberos_principal_short_name = KERBEROS.HUE_PRINCIPAL.get().split('/', 1)[0]
+
+    if query_server is not None and query_server.get('server_name') == 'impala':
+      principal = IMPALA_PRINCIPAL.get()
+    else:
+      principal = KERBEROS.HUE_PRINCIPAL.get()
+
+    # We should integrate hive_site.get_metastore() here in the future
+    kerberos_principal_short_name = principal.split('/', 1)[0]
 
     return use_sasl, kerberos_principal_short_name
 
@@ -284,7 +291,7 @@ class BeeswaxClient:
         res = self._client.get_results_metadata(*args, **kwargs)
         return _decode_struct_attr(res, 'table_dir')
 
-    use_sasl, kerberos_principal_short_name = BeeswaxClient.get_security()
+    use_sasl, kerberos_principal_short_name = BeeswaxClient.get_security(query_server)
 
     client = thrift_util.get_client(BeeswaxService.Client,
                                     query_server['server_host'],

+ 0 - 1
apps/beeswax/src/beeswax/server/dbms.py

@@ -23,7 +23,6 @@ from django.utils.encoding import force_unicode
 from django.utils.translation import ugettext as _
 
 from filebrowser.views import location_to_url
-
 from beeswaxd.ttypes import BeeswaxException
 
 from beeswax.conf import BEESWAX_SERVER_HOST, BEESWAX_SERVER_PORT,\

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

@@ -52,8 +52,9 @@ from beeswax.design import hql_query, _strip_trailing_semicolon
 from beeswax.data_export import download
 from beeswax.models import SavedQuery, QueryHistory
 from beeswax.server import dbms
-from beeswax.server.beeswax_lib import BeeswaxDataTable
+from beeswax.server.beeswax_lib import BeeswaxDataTable, BeeswaxClient
 from beeswax.test_base import BeeswaxSampleProvider
+import hadoop
 
 
 LOG = logging.getLogger(__name__)
@@ -1471,6 +1472,25 @@ def test_search_log_line():
   assert_false(search_log_line('ql.Driver', 'FAILED: Parse Error', logs))
 
 
+def test_beeswax_get_kerberos_security():
+  query_server = {'server_name': 'beeswax'}
+  assert_equal((False, 'hue'), BeeswaxClient.get_security(query_server))
+
+  query_server = {'server_name': 'impala'}
+  assert_equal((False, 'impala'), BeeswaxClient.get_security(query_server))
+
+  cluster_conf = hadoop.cluster.get_cluster_conf_for_job_submission()
+  finish = cluster_conf.SECURITY_ENABLED.set_for_testing(True)
+  try:
+    query_server = {'server_name': 'beeswax'}
+    assert_equal((True, 'hue'), BeeswaxClient.get_security(query_server))
+
+    query_server = {'server_name': 'impala'}
+    assert_equal((True, 'impala'), BeeswaxClient.get_security(query_server))
+  finally:
+    finish()
+
+
 def search_log_line(component, expected_log, all_logs):
   """Checks if 'expected_log' can be found in one line of 'all_logs' outputed by the logging component 'component'."""
   return re.compile('.+?%(component)s(.+?)%(expected_log)s' % {'component': component, 'expected_log': expected_log}).search(all_logs)

+ 8 - 1
apps/impala/src/impala/conf.py

@@ -15,8 +15,9 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-from django.utils.translation import ugettext_lazy as _
+import socket
 
+from django.utils.translation import ugettext_lazy as _
 from desktop.lib.conf import Config
 
 
@@ -31,3 +32,9 @@ SERVER_PORT = Config(
   help=_("Port of the Impala Server."),
   default=21000,
   type=int)
+
+IMPALA_PRINCIPAL=Config(
+  key='impala_principal',
+  help=_("Kerberos principal name for Impala. Typically 'impala/hostname.foo.com'."),
+  type=str,
+  default="impala/%s" % socket.getfqdn())

+ 3 - 0
desktop/conf.dist/hue.ini

@@ -402,6 +402,9 @@
    # Port of the Impala Server
    ## server_port=21000
 
+   # Kerberos principal
+   ## impala_principal=impala/hostname.foo.com
+
 
 ###########################################################################
 # Settings to configure Job Designer

+ 3 - 0
desktop/conf/pseudo-distributed.ini.tmpl

@@ -405,6 +405,9 @@
    # Port of the Impala Server
    ## server_port=21000
 
+   # Kerberos principal
+   ## impala_principal=impala/hostname.foo.com
+
 
 ###########################################################################
 # Settings to configure Job Designer