瀏覽代碼

HUE-8770 [spark] Send proper header to Livy when CSRF protection is enabled (#823)

Rick Bernotas 6 年之前
父節點
當前提交
b14016e671

+ 6 - 0
apps/spark/src/spark/conf.py

@@ -58,6 +58,12 @@ SECURITY_ENABLED = Config(
   default=False,
   type=coerce_bool)
 
+CSRF_ENABLED = Config(
+  key="csrf_enabled",
+  help=_t("Whether Livy requres client to have CSRF enabled."),
+  default=False,
+  type=coerce_bool)
+
 # Spark SQL
 SQL_SERVER_HOST = Config(
   key="sql_server_host",

+ 9 - 1
apps/spark/src/spark/job_server_api.py

@@ -23,7 +23,7 @@ import threading
 from desktop.lib.rest.http_client import HttpClient
 from desktop.lib.rest.resource import Resource
 
-from spark.conf import get_livy_server_url, SECURITY_ENABLED, SSL_CERT_CA_VERIFY
+from spark.conf import get_livy_server_url, SECURITY_ENABLED, SSL_CERT_CA_VERIFY, CSRF_ENABLED
 
 
 LOG = logging.getLogger(__name__)
@@ -58,11 +58,15 @@ class JobServerApi(object):
     self._client = HttpClient(self._url, logger=LOG)
     self._root = Resource(self._client)
     self._security_enabled = SECURITY_ENABLED.get()
+    self._csrf_enabled = CSRF_ENABLED.get()
     self._thread_local = threading.local()
 
     if self.security_enabled:
       self._client.set_kerberos_auth()
 
+    if self.csrf_enabled:
+      self._client.set_headers({'X-Requested-By' : 'hue'})
+
     self._client.set_verify(SSL_CERT_CA_VERIFY.get())
 
   def __str__(self):
@@ -76,6 +80,10 @@ class JobServerApi(object):
   def security_enabled(self):
     return self._security_enabled
 
+  @property
+  def csrf_enabled(self):
+    return self._csrf_enabled
+
   @property
   def user(self):
     return self._thread_local.user

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

@@ -1252,6 +1252,9 @@
   # Whether Livy requires client to perform Kerberos authentication.
   ## security_enabled=false
 
+  # Whether Livy requires client to use csrf protection.
+  ## csrf_enabled=false
+
   # Host of the Sql Server
   ## sql_server_host=localhost
 

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

@@ -1255,6 +1255,9 @@
   # Whether Livy requires client to perform Kerberos authentication.
   ## security_enabled=false
 
+  # Whether Livy requires client to use csrf protection.
+  ## csrf_enabled=false
+
   # Host of the Sql Server
   ## sql_server_host=localhost