hive权限控制

来源:互联网 发布:网络优化工程师怎么样 编辑:程序博客网 时间:2024/04/29 06:46

Hive由一个默认的设置来配置新建文件的默认权限。

Xml代码  收藏代码
  1. <property>  
  2.   <name>hive.files.umask.value</name>  
  3.   <value>0002</value>  
  4.   <description>The dfs.umask value for the hive created folders</description>  
  5. </property>  

 当hive.metastore.authorization.storage.checks属性被设置成true时,
Hive将会阻止没有权限的用户进行表删除操作。
不过这个配置的默认值是false,应该设置成true

 

Xml代码  收藏代码
  1. <property>  
  2.   <name>hive.metastore.authorization.storage.checks</name>  
  3.   <value>true</value>  
  4.   <description>Should the metastore do authorization checks against  
  5.   the underlying storage for operations like drop-partition (disallow  
  6.   the drop-partition if the user in question doesn't have permissions  
  7.   to delete the corresponding directory on the storage).</description>  
  8. </property>  

 

 同时,Hive会尽可能地将hive.metastore.execute.setugi设置成true。

 

 开启Hive的身份认证功能,默认是false

Xml代码  收藏代码
  1. <property>  
  2.   <name>hive.security.authorization.enabled</name>   
  3.   <value>true</value>  
  4.   <description>Enable or disable the hive client authorization</description>  
  5. </property>  

 另外还有一个是表格创建者用于的权限配置项:

Xml代码  收藏代码
  1. <property>  
  2.   <name>hive.security.authorization.createtable.owner.grants</name>  
  3.   <value>ALL</value>  
  4.   <description>The privileges automatically granted to the owner whenever  
  5.   a table gets created.An example like "select,drop" will grant select  
  6.   and drop privilege to the owner of the table</description>  
  7. </property>  

 这个配置默认是NULL,我们建议将其设置成ALL,让用户能够访问自己创建的表。

 

试验,在命令行环境开启用户认证

Shell代码  收藏代码
  1. hive> set hive.security.authorization.enabled=true;  
  2. hive> CREATE TABLE authorization_test (key int, value string);  
  3. Authorization failed:No privilege 'Create' found for outputs { database:default}.  
  4. Use show grant to get more details.  

 

 我们可以看到,建表需要权限了。
权限可以授予给不同的主题,如用户(USER),组(GROUP),角色(ROLES)

现在我们通过授权方式,将权限授予给当前用户:

Shell代码  收藏代码
  1. hive> set system:user.name;  
  2. system:user.name=edward  
  3. hive> GRANT CREATE ON DATABASE default TO USER edward;  
  4. hive> CREATE TABLE authorization_test (key INT, value STRING);  

 这样就可以创建表了。

 

我们可以通过SHOW GRANT命令确认我们拥有的权限:

Shell代码  收藏代码
  1. hive> SHOW GRANT USER edward ON DATABASE default;  
  2. database default  
  3. principalName edward  
  4. principalType USER  
  5. privilege Create  
  6. grantTime Mon Mar 19 09:18:10 EDT 2012  
  7. grantor edward  

 当Hive里面用于N多用户和N多张表的时候,管理员给每个用户授权每张表会让他崩溃的。
所以,这个时候就可以进行组(GROUP)授权。
Hive里的用户组的定义等价于POSIX里面的用户组。

Shell代码  收藏代码
  1. hive> CREATE TABLE authorization_test_group(a int,b int);  
  2. hive> SELECT * FROM authorization_test_group;  
  3. Authorization failed:No privilege 'Select' found for inputs  
  4. { database:default, table:authorization_test_group, columnName:a}.  
  5. Use show grant to get more details.  
  6. hive> GRANT SELECT on table authorization_test_group to group edward;  
  7. hive> SELECT * FROM authorization_test_group;  
  8. OK  
  9. Time taken: 0.119 seconds  

 当给用户组授权变得不够灵活的时候,角色(ROLES)就派上用途了。
用户可以被放在某个角色之中,然后角色可以被授权。
角色不同于用户组,是由Hadoop控制的,它是由Hive内部进行管理的。

Shell代码  收藏代码
  1. hive> CREATE TABLE authentication_test_role (a int , b int);  
  2. hive> SELECT * FROM authentication_test_role;  
  3. Authorization failed:No privilege 'Select' found for inputs  
  4. { database:default, table:authentication_test_role, columnName:a}.  
  5. Use show grant to get more details.  
  6. hive> CREATE ROLE users_who_can_select_authentication_test_role;  
  7. hive> GRANT ROLE users_who_can_select_authentication_test_role TO USER edward;  
  8. hive> GRANT SELECT ON TABLE authentication_test_role  
  9. > TO ROLE users_who_can_select_authentication_test_role;  
  10. hive> SELECT * FROM authentication_test_role;  
  11. OK  
  12. Time taken: 0.103 seconds  

 

介绍一下常用的授权关键字:

ALTER更改表结构,创建分区CREATE创建表DROP删除表,或分区INDEX创建和删除索引LOCK锁定表,保证并发SELECT查询表权限SHOW_DATABASE查看数据库权限UPDATE

 为表加载本地数据的权限

 

 

 分区表级别的授权
默认情况下,分区表的授权将会跟随表的授权
当然,也可以给每一个分区建立一个授权机制,
只需要设置表的属性PARTITION_LEVEL_PRIVILEGE设置成TRUE:

Shell代码  收藏代码
  1. hive> ALTER TABLE authorization_part  
  2. > SET TBLPROPERTIES ("PARTITION_LEVEL_PRIVILEGE"="TRUE");  
  3. Authorization failed:No privilege 'Alter' found for inputs  
  4. {database:default, table:authorization_part}.  
  5. Use show grant to get more details.  

 

 自动授权
属性hive.security.authorization.createtable.owner.grants决定了
建表者对表拥有的权限,一版情况下,有select和drop

Xml代码  收藏代码
  1. <property>  
  2.   <name>hive.security.authorization.createtable.owner.grants</name>  
  3.   <value>select,drop</value>  
  4. </property>  

 

类似的,特定的用户可以被在表创建的时候自动授予其权限。

Xml代码  收藏代码
  1. <property>  
  2.   <name>hive.security.authorization.createtable.user.grants</name>  
  3.   <value>admin1,edward:select;user1:create</value>  
  4. </property>  

 当表建立的时候,管理员admin1和用户edward授予读所有表的权限。
而user1只能创建表。

 

同样的配置也可以作用于组授权和角色授权
hive.security.authorization.createtable.group.grants
hive.security.authorization.createtable.role.grants


0 0