0035-如何使用Sentry管理Hive外部表(補充)

溫馨提示:要看高清無碼套圖,請使用手機打開並單擊圖片放大查看。

1.文檔編寫目的


本文文檔主要講述如何使用Sentry管理Hive/Impala外部表權限。

  • 內容概述

1.創建測試庫及外部表

2.創建角色並授權

3.授權測試

4.測試總結

  • 測試環境

1.操作系統爲CentOS6.5

2.CM和CDH版本爲5.12.1

3.採用root用戶操作

  • 前置條件

1.集羣運行正常

2.集羣已啓用Kerberos且正常使用

3.HDFS/Hive/Impala/Hue服務已與Sentry集成

4.Hive用戶爲超級用戶

友情提示:總結是精華。

2.創建測試庫及外部表


  1. 使用hive用戶登錄Kerberos,並通過beeline登錄HiveServer2

創建fayson數據庫

0: jdbc:hive2://localhost:10000/> create database fayson;
INFO  : Compiling command(queryId=hive_20170916155353_12e7c551-6a72-4ff3-b581-353c4dbd0fb0): create database fayson
INFO  : Semantic Analysis Completed
…
INFO  : OK
No rows affected (0.232 seconds)
0: jdbc:hive2://localhost:10000/> 

0035-如何使用Sentry管理Hive外部表(補充)

2.在fayson庫下創建外部表student_hive,建表語句如下

create external table if not exists student_hive(
  name string,
  age int,
  addr string
)
ROW FORMAT DELIMITED FIELDS TERMINATED BY ','
LOCATION '/extwarehouse/student_hive';

向/extwarehouse/student_hive表put數據

[root@ip-172-31-6-148 ~]# hadoop fs -put student.txt /extwarehouse/student_hive
[root@ip-172-31-6-148 ~]# hadoop fs -ls /extwarehouse/student_hive
Found 1 items
-rw-r--r--   3 hive supergroup         59 2017-09-16 16:05 /extwarehouse/student_hive/student.txt
[root@ip-172-31-6-148 ~]# 

/extwarehouse/student_hive數據目錄不存,在創建外部表時自動生成,且數據目錄屬主爲hive。

0: jdbc:hive2://localhost:10000/> select * from student_hive;
...
INFO  : OK
+--------------------+-------------------+--------------------+--+
| student_hive.name  | student_hive.age  | student_hive.addr  |
+--------------------+-------------------+--------------------+--+
| fayson             | 23                | guangdong          |
| zhangsan           | 24                | shenzhen           |
| lisi               | 55                | guangzhou          |
+--------------------+-------------------+--------------------+--+
3 rows selected (0.216 seconds)
0: jdbc:hive2://localhost:10000/> 

3.創建角色並授權


  1. 創建faysonall角色並授權給fayson用戶組

授權fayson用戶組擁有fayson庫所有權限

create role faysonall;
grant all on database fayson to role faysonall;
grant role faysonall to group fayson;

0035-如何使用Sentry管理Hive外部表(補充)

4.授權測試


  1. 使用fayosn用戶登錄Kerberos,通過beeline連接HiveServer2
[fayson@ip-172-31-6-148 root]$ beeline 
Beeline version 1.1.0-cdh5.12.1 by Apache Hive
beeline> !connect jdbc:hive2://localhost:10000/;principal=hive/[email protected]
scan complete in 2ms
Connecting to jdbc:hive2://localhost:10000/;principal=hive/[email protected]
Connected to: Apache Hive (version 1.1.0-cdh5.12.1)
Driver: Hive JDBC (version 1.1.0-cdh5.12.1)
Transaction isolation: TRANSACTION_REPEATABLE_READ
0: jdbc:hive2://localhost:10000/> 

0035-如何使用Sentry管理Hive外部表(補充)

2.切換至fayson數據庫對student_hive表操作

可以向表中插入數據

0: jdbc:hive2://localhost:10000/> insert into student_hive values('lisi', 22, 'beijing');
...
INFO  : OK
No rows affected (22.501 seconds)
0: jdbc:hive2://localhost:10000/>

0035-如何使用Sentry管理Hive外部表(補充)

可以查詢表數據

0: jdbc:hive2://localhost:10000/> select * from student_hive;
...
INFO  : OK
+--------------------+-------------------+--------------------+--+
| student_hive.name  | student_hive.age  | student_hive.addr  |
+--------------------+-------------------+--------------------+--+
| lisi               | 22                | beijing            |
| fayson             | 23                | guangdong          |
| zhangsan           | 24                | shenzhen           |
| lisi               | 55                | guangzhou          |
+--------------------+-------------------+--------------------+--+
4 rows selected (0.215 seconds)
0: jdbc:hive2://localhost:10000/> 

0035-如何使用Sentry管理Hive外部表(補充)

3.HDFS驗證

fayson用戶可以瀏覽student_hive的數據目錄,查看數據目錄下文件內容,但沒有delete和put文件的權限。

[fayson@ip-172-31-6-148 ~]$ hadoop fs -ls /extwarehouse/student_hive
Found 2 items
-rwxr-xr-x   3 hive supergroup         16 2017-09-16 16:16 /extwarehouse/student_hive/000000_0
-rw-r--r--   3 hive supergroup         59 2017-09-16 16:05 /extwarehouse/student_hive/student.txt
[fayson@ip-172-31-6-148 ~]$ hadoop fs -rmr /extwarehouse/student_hive/student.txt
rmr: DEPRECATED: Please use 'rm -r' instead.
rmr: Failed to move to trash: hdfs://ip-172-31-6-148.fayson.com:8020/extwarehouse/student_hive/student.txt: Permission denied: user=fayson, access=WRITE, inode="/extwarehouse/student_hive":hive:supergroup:drwxr-xr-x
[fayson@ip-172-31-6-148 ~]$ hadoop fs -put student1.txt /extwarehouse/student_hive/
put: Permission denied: user=fayson, access=WRITE, inode="/extwarehouse/student_hive":hive:supergroup:drwxr-xr-x
[fayson@ip-172-31-6-148 ~]$ 

測試總結:

hive創建的外部表,通過Sentry授權後,fayson用戶組使用beeline和Hue能對該表進行查詢和插入操作。但不能對HDFS和Hue FileBrowser上的數據目錄進行新增和刪除操作,由於fayson用戶無操作數據目錄的權限。

5.測試總結


如果這個外部表的目錄沒有在cm裏配置成需要sentry管理的目錄,通過Sentry賦權後,是沒法做ACL同步的,不建議在生產系統中這樣使用。如果你需要管理外部表,那麼你就需要按照之前的標準文檔來操作。如何使用Sentry管理Hive外部表權限

醉酒鞭名馬,少年多浮誇! 嶺南浣溪沙,嘔吐酒肆下!摯友不肯放,數據玩的花!
溫馨提示:要看高清無碼套圖,請使用手機打開並單擊圖片放大查看。


推薦關注Hadoop實操,第一時間,分享更多Hadoop乾貨,歡迎轉發和分享。

0035-如何使用Sentry管理Hive外部表(補充)
原創文章,歡迎轉載,轉載請註明:轉載自微信公衆號Hadoop實操

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