Ranger、LLAP管理SparkSQL權限配置(hiveserver2)

轉載:https://zhuanlan.zhihu.com/p/35647068

概述

之前一直使用ranger管理hive的用戶權限,現在系統要集成SparkSQL(thriftserver),但是在ranger下並沒有SparkSQL的相關的插件,通過蒐集HORTONWORKS相關資料,可以給SparkSQL配置LLAP(關於LLAP的更多細節,查看https://cwiki.apache.org/confluence/display/Hive/LLAP),然後通過ranger的hive policy間接支持SparkSQL的用戶權限管理。

2. 原理

圖-1

如圖-1所示:

1)、SparkSQL接收到sql語句後,將該語句提交給HiveServer2

2)、Ranger 通過hive插件檢查access policy,並告訴SparkSQL訪問哪些表(列)不能訪問哪些表(列)

3)、SparkSQL開始嘗試通過LLAP從hdfs讀取數據

4)、LLAP收到請求,檢測到請求中包含沒有權限訪問的列,就停止處理該請求,同時返回一個權限異常給Spark

3. 配置

  • 環境

1)、HDP-2.6.3.0-235 with Spark2,non-kerberized 集羣

2)、SPARK-LLAP:集羣內部集成

  • 配置Hiveserver2 Interactive 服務

在Ambari中,定位到hive服務配置頁,並且點擊Enable Interactive Query:

隨後會跳出相關配置,這些配置和LLAP服務資源分配有關,可以保持默認,因爲目前只是爲了滿足測試需要。

保存配置,確認,繼續。

重啓影響的服務。

定位到service summary tab頁面,確保Hiveserver2 Interactive服務啓動成功:

  • 配置Spark2

在Ambari中,定位到spark2配置頁

spark2配置頁

找到 Custom spark2-defaults,

點擊 add property 並添加如下屬性:

spark.sql.hive.hiveserver2.jdbc.url= jdbc:hive2://{hiveserver-interactive-hostname}:10500/

spark.hadoop.hive.llap.daemon.service.hosts=@llap0

spark.hadoop.hive.zookeeper.quorum={some-or-all-zookeeper-hostnames}:2181

找到 Custom spark2-thrift-sparkconf,

點擊 add property 並添加和 Custom spark2-defaults相同的屬性

找到 Advanced spark2-env,

給屬性spark_thrift_cmd_opts設置值:--jars /usr/hdp/2.6.3.0-235/spark_llap/spark-llap-assembly-1.0.0.2.6.3.0-235.jar --conf spark.sql.hive.llap=true

注:在HDP-2.6.3已經內部集成了spark-llap,對於沒有集成spark-llap的HDP版本,spark_thrift_cmd_opts值應該這樣設置值:--packages com.hortonworks.spark:spark-llap-assembly_2.11:1.1.3-2.1 --repositories http://repo.hortonworks.com/content/groups/public/ --conf spark.sql.hive.llap=true

保存屬性修改,然後重啓影響的服務,完成。

  • 測試

1)、給默認database設置ranger權限(推薦)

之所以推薦這樣設置是,因爲連接ThriftServer的時候一般是jdbc:hive2://{thriftserver-host}:{thriftserver-port},如果沒有登錄default的權限,連接時將直接拒絕,更談不上執行更多的任務。

2)、測試

我的hive中現有3個庫:

而用戶**15698只對***_data_service有權限:

現在用用戶**15698連接ThriftServer,只顯示***_data_service庫:

執行explain select,已經開始走LLAP權限驗證:

測試完成。

4. 參考資料

hortonworks-spark/spark-llap​github.com圖標Error:"Unable to instantiate SparkSession with LLAP support because LLAP or Hive classes are not found" after upgrading from HDP 2.6.2 to 2.6.3 when starting Spark2 Thirft Server - Hortonworks​community.hortonworks.com

 

SparkSQL, Ranger, and LLAP via Spark Thrift Server for BI scenarios to provide row, column level security, and masking - Hortonworks​zh.hortonworks.com圖標

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章