Jelajahi Sumber

HUE-2192 [core] Create parameter to choose LDAP username for HS2

Ben Gooley 11 tahun lalu
induk
melakukan
0148bbb6f9

+ 2 - 2
apps/beeswax/src/beeswax/server/hive_server2_lib.py

@@ -21,7 +21,7 @@ import re
 from operator import itemgetter
 
 from desktop.lib import thrift_util
-from desktop.conf import LDAP_PASSWORD
+from desktop.conf import LDAP_PASSWORD, LDAP_USERNAME
 from hadoop import cluster
 
 from TCLIService import TCLIService
@@ -362,7 +362,7 @@ class HiveServerClient:
       mechanism = HiveServerClient.HS2_MECHANISMS[hive_mechanism]
       impersonation_enabled = hive_site.hiveserver2_impersonation_enabled()
       if LDAP_PASSWORD.get(): # HiveServer2 supports pass-through LDAP authentication.
-        ldap_username = 'hue'
+        ldap_username = LDAP_USERNAME.get()
         ldap_password = LDAP_PASSWORD.get()
 
     return use_sasl, mechanism, kerberos_principal_short_name, impersonation_enabled, ldap_username, ldap_password

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

@@ -65,7 +65,7 @@ from beeswax.test_base import BeeswaxSampleProvider
 from beeswax.hive_site import get_metastore
 
 from desktop.lib.exceptions_renderable import PopupException
-from desktop.conf import LDAP_PASSWORD
+from desktop.conf import LDAP_USERNAME, LDAP_PASSWORD
 
 
 LOG = logging.getLogger(__name__)
@@ -2011,11 +2011,14 @@ def test_hiveserver2_get_security():
     assert_equal((True, 'PLAIN', 'hive', False, None, None), HiveServerClient(beeswax_query_server, user).get_security())
 
     # HiveServer2 LDAP passthrough
-    finish = LDAP_PASSWORD.set_for_testing('abcd')
+    finish = []
+    finish.append(LDAP_USERNAME.set_for_testing('hueabcd'))
+    finish.append(LDAP_PASSWORD.set_for_testing('abcd'))
     try:
-      assert_equal((True, 'PLAIN', 'hive', False, 'hue', 'abcd'), HiveServerClient(beeswax_query_server, user).get_security())
+      assert_equal((True, 'PLAIN', 'hive', False, 'hueabcd', 'abcd'), HiveServerClient(beeswax_query_server, user).get_security())
     finally:
-      finish()
+      for f in finish:
+        f()
 
     hive_site._HIVE_SITE_DICT[hive_site._CNF_HIVESERVER2_AUTHENTICATION] = 'NOSASL'
     hive_site._HIVE_SITE_DICT[hive_site._CNF_HIVESERVER2_IMPERSONATION] = 'true'

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

@@ -63,8 +63,9 @@
   # See http://www.openssl.org/docs/apps/ciphers.html for more information on cipher list format.
   ## ssl_cipher_list=DEFAULT:!aNULL:!eNULL:!LOW:!EXPORT:!SSLv2
 
-  # LDAP password of the hue user used for LDAP authentications. For example for LDAP Authentication with HiveServer2.
-  # ldap_password=
+  # LDAP username and password of the hue user used for LDAP authentications. For example for LDAP Authentication with HiveServer2.
+  ## ldap_username=hue
+  ## ldap_password=
 
   # Default encoding for site data
   ## default_site_encoding=utf-8

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

@@ -72,8 +72,9 @@
   # See http://www.openssl.org/docs/apps/ciphers.html for more information on cipher list format.
   ## ssl_cipher_list=DEFAULT:!aNULL:!eNULL:!LOW:!EXPORT:!SSLv2
 
-  # LDAP password of the hue user used for LDAP authentications. For example for LDAP Authentication with HiveServer2.
-  # ldap_password=
+  # LDAP username and password of the hue user used for LDAP authentications. For example for LDAP Authentication with HiveServer2.
+  ## ldap_username=hue
+  ## ldap_password=
 
   # Default encoding for site data
   ## default_site_encoding=utf-8

+ 6 - 0
desktop/core/src/desktop/conf.py

@@ -89,6 +89,12 @@ LDAP_PASSWORD = Config(
   private=True,
   default=None)
 
+LDAP_USERNAME = Config(
+  key="ldap_username",
+  help=_("LDAP username of the hue user used for LDAP authentications. For example for LDAP Authentication with HiveServer2."),
+  private=True,
+  default="hue")
+
 ENABLE_SERVER = Config(
   key="enable_server",
   help=_("If set to false, runcpserver will not actually start the web server.  Used if Apache is being used as a WSGI container."),