Browse Source

HUE-7127 [backend] Fix for Python requests Kerberos/GSSAPI authentication library fails to authenticate kerberos requests to the same destination host.

current python request Kerberos library fails generating the GSSAPI authentication token with kerberos for the host which run multiple kerberised services on different port. This code change fixes the limitation.

Testing Done:
- Manual testing
  - using multiple load generator scripts
- Tested on different cluster with Python 2.6 and Python 2.7
Prakash Ranade 8 years ago
parent
commit
c2cbf189cf

+ 13 - 5
desktop/core/ext-py/requests-kerberos-0.6.1/requests_kerberos/kerberos_.py

@@ -1,6 +1,7 @@
 import kerberos
 import re
 import logging
+import threading
 
 from requests.auth import AuthBase
 from requests.models import Response
@@ -97,8 +98,13 @@ class HTTPKerberosAuth(AuthBase):
         """
         host = urlparse(response.url).hostname
 
+        # Initialize uniq key for the self.context dictionary
+        host_port_thread = "%s_%s_%s" % (urlparse(response.url).hostname,
+                                         urlparse(response.url).port,
+                                         threading.current_thread().ident)
+
         try:
-            result, self.context[host] = kerberos.authGSSClientInit(
+            result, self.context[host_port_thread] = kerberos.authGSSClientInit(
                 "{0}@{1}".format(self.service, host))
         except kerberos.GSSError:
             log.exception("generate_request_header(): authGSSClientInit() failed:")
@@ -110,7 +116,7 @@ class HTTPKerberosAuth(AuthBase):
             return None
 
         try:
-            result = kerberos.authGSSClientStep(self.context[host],
+            result = kerberos.authGSSClientStep(self.context[host_port_thread],
                                                 _negotiate_value(response))
         except kerberos.GSSError:
             log.exception("generate_request_header(): authGSSClientStep() failed:")
@@ -122,7 +128,7 @@ class HTTPKerberosAuth(AuthBase):
             return None
 
         try:
-            gss_response = kerberos.authGSSClientResponse(self.context[host])
+            gss_response = kerberos.authGSSClientResponse(self.context[host_port_thread])
         except kerberos.GSSError:
             log.exception("generate_request_header(): authGSSClientResponse() "
                       "failed:")
@@ -222,10 +228,12 @@ class HTTPKerberosAuth(AuthBase):
         log.debug("authenticate_server(): Authenticate header: {0}".format(
             _negotiate_value(response)))
 
-        host = urlparse(response.url).hostname
+        host_port_thread = "%s_%s_%s" % (urlparse(response.url).hostname,
+                                         urlparse(response.url).port,
+                                         threading.current_thread().ident)
 
         try:
-            result = kerberos.authGSSClientStep(self.context[host],
+            result = kerberos.authGSSClientStep(self.context[host_port_thread],
                                                 _negotiate_value(response))
         except kerberos.GSSError:
             log.exception("authenticate_server(): authGSSClientStep() failed:")