舒適提示:要看高清無碼套圖,請使用手機打開並單擊圖片放大查看。node
1.文檔編寫目的數據庫
本文文檔主要講述如何使用Sentry管理Hive/Impala外部表權限。oop
1.建立測試庫及外部表測試
2.建立角色並受權操作系統
3.受權測試3d
4.測試總結code
1.操做系統爲CentOS6.5blog
2.CM和CDH版本爲5.12.1圖片
3.採用root用戶操做ip
1.集羣運行正常
2.集羣已啓用Kerberos且正常使用
3.HDFS/Hive/Impala/Hue服務已與Sentry集成
4.Hive用戶爲超級用戶
友情提示:總結是精華。
2.建立測試庫及外部表
建立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/>
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.建立角色並受權
受權fayson用戶組擁有fayson庫全部權限
create role faysonall; grant all on database fayson to role faysonall; grant role faysonall to group fayson;
4.受權測試
[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/ip-172-31-6-148.fayson.com@FAYSON.COM scan complete in 2ms Connecting to jdbc:hive2://localhost:10000/;principal=hive/ip-172-31-6-148.fayson.com@FAYSON.COM 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/>
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/>
能夠查詢表數據
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/>
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乾貨,歡迎轉發和分享。