Hive授权(Security配置)

摘:https://cwiki.apache.org/Hive/languagemanual-auth.html

       https://cwiki.apache.org/Hive/authdev.html

       http://grokbase.com/t/hive/user/11aksphhas/authorization-and-remote-connection-on-cdh3u1

     HIVE授权管理,类似于操作系统权限可以授予给不同的主题,如用户(USER),组(GROUP),角色(ROLES),Hive还是支持相当多的权限管理功能,满足一般数据仓库的使用,同时HIVE能支持自定义权限。

     HIVE授权并不是完全安全,在其目前的形式来看,授权方案的目的是主要是为了防止用户不小心好做了不合法的操作,但不承诺防止用户恶意破坏。

一、HIVE新建文件权限

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

<property>
  <name>hive.files.umask.value</name>
  <value>0002</value>
  <description>The dfs.umask value for the hive created folders</description>
</property>

 创建文件授权掩码为0002,即664权限,具体要看hadoop与hive用户配置。

扫描二维码关注公众号,回复: 737596 查看本文章

二、HIVE授权存储检查

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

<property>
  <name>hive.metastore.authorization.storage.checks</name>
  <value>true</value>
  <description>Should the metastore do authorization checks against
  the underlying storage for operations like drop-partition (disallow
  the drop-partition if the user in question doesn't have permissions
  to delete the corresponding directory on the storage).</description>
</property>

 同时,Hive会尽可能地将hive.metastore.execute.setugi设置成true。在不安全的模式,将这个属性设置为true将导致metastore执行DFS操作定义用户和组权限。

三、HIVE身份验证

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

<property>
  <name>hive.security.authorization.enabled</name> 
  <value>true</value>
  <description>Enable or disable the hive client authorization</description>
</property>

 2.表创建者用于的权限配置项

<property>
  <name>hive.security.authorization.createtable.owner.grants</name>
  <value>ALL</value>
  <description>The privileges automatically granted to the owner whenever
  a table gets created.An example like "select,drop" will grant select
  and drop privilege to the owner of the table</description>
</property>

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

四、案例说明

1.在命令行环境开启用户认证

hive> set hive.security.authorization.enabled=true;  
hive> CREATE TABLE auth_test (key int, value string);  
Authorization failed:No privilege 'Create' found for outputs { database:default}.  
Use show grant to get more details.  

提示建表需要权限了。

权限可以授予给不同的主题,如用户(USER),组(GROUP),角色(ROLES)

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

hive> set system:user.name;
system:user.name=hadoop
hive> GRANT CREATE ON DATABASE default TO USER hadoop;
hive> CREATE TABLE auth_test (key INT, value STRING);

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

hive> SHOW GRANT USER hadoop ON DATABASE default;  
database default  
principalName hadoop  
principalType USER  
privilege Create  
grantTime Wed Mar 08 19:18:10 EDT 2013  
grantor hadoop  

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

hive> CREATE TABLE auth_test_group(a int,b int);
hive> SELECT * FROM auth_test_group;
Authorization failed:No privilege 'Select' found for inputs
{ database:default, table:auth_test_group, columnName:a}.
Use show grant to get more details.
hive> GRANT SELECT on table auth_test_group to group hadoop;
hive> SELECT * FROM auth_test_group;
OK
Time taken: 0.119 seconds

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

hive> CREATE TABLE auth_test_role (a int , b int);
hive> SELECT * FROM auth_test_role;
Authorization failed:No privilege 'Select' found for inputs
{ database:default, table:auth_test_role, columnName:a}.
Use show grant to get more details.
hive> CREATE ROLE users_who_can_select_auth_test_role;
hive> GRANT ROLE users_who_can_select_auth_test_role TO USER hadoop;
hive> GRANT SELECT ON TABLE auth_test_role
> TO ROLE users_who_can_select_auth_test_role;
hive> SELECT * FROM auth_test_role;
OK
Time taken: 0.103 seconds

五、分区表级别的授权

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

hive> ALTER TABLE auth_part
> SET TBLPROPERTIES ("PARTITION_LEVEL_PRIVILEGE"="TRUE");
Authorization failed:No privilege 'Alter' found for inputs
{database:default, table:auth_part}.
Use show grant to get more details.

六、自动授权

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

<property>
  <name>hive.security.authorization.createtable.owner.grants</name>
  <value>select,drop</value>
</property>

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

<property>
  <name>hive.security.authorization.createtable.user.grants</name>
  <value>irwin,hadoop:select;tom:create</value>
</property>

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

同样的配置也可以作用于组授权和角色授权

hive.security.authorization.createtable.group.grants
hive.security.authorization.createtable.role.grants

七、删除授权

--回收用户hadoop的create授权
revoke create on database default from user hadoop;

--回收组hadoop的select授权
revoke select on database default from group hadoop;

附录:常用的授权关键字

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

 为表加载本地数据的权限

摘:https://cwiki.apache.org/Hive/languagemanual-auth.html

       https://cwiki.apache.org/Hive/authdev.html

       http://grokbase.com/t/hive/user/11aksphhas/authorization-and-remote-connection-on-cdh3u1

     HIVE授权管理,类似于操作系统权限可以授予给不同的主题,如用户(USER),组(GROUP),角色(ROLES),Hive还是支持相当多的权限管理功能,满足一般数据仓库的使用,同时HIVE能支持自定义权限。

     HIVE授权并不是完全安全,在其目前的形式来看,授权方案的目的是主要是为了防止用户不小心好做了不合法的操作,但不承诺防止用户恶意破坏。

一、HIVE新建文件权限

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

<property>
  <name>hive.files.umask.value</name>
  <value>0002</value>
  <description>The dfs.umask value for the hive created folders</description>
</property>

 创建文件授权掩码为0002,即664权限,具体要看hadoop与hive用户配置。

二、HIVE授权存储检查

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

<property>
  <name>hive.metastore.authorization.storage.checks</name>
  <value>true</value>
  <description>Should the metastore do authorization checks against
  the underlying storage for operations like drop-partition (disallow
  the drop-partition if the user in question doesn't have permissions
  to delete the corresponding directory on the storage).</description>
</property>

 同时,Hive会尽可能地将hive.metastore.execute.setugi设置成true。在不安全的模式,将这个属性设置为true将导致metastore执行DFS操作定义用户和组权限。

三、HIVE身份验证

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

<property>
  <name>hive.security.authorization.enabled</name> 
  <value>true</value>
  <description>Enable or disable the hive client authorization</description>
</property>

 2.表创建者用于的权限配置项

<property>
  <name>hive.security.authorization.createtable.owner.grants</name>
  <value>ALL</value>
  <description>The privileges automatically granted to the owner whenever
  a table gets created.An example like "select,drop" will grant select
  and drop privilege to the owner of the table</description>
</property>

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

四、案例说明

1.在命令行环境开启用户认证

hive> set hive.security.authorization.enabled=true;  
hive> CREATE TABLE auth_test (key int, value string);  
Authorization failed:No privilege 'Create' found for outputs { database:default}.  
Use show grant to get more details.  

提示建表需要权限了。

权限可以授予给不同的主题,如用户(USER),组(GROUP),角色(ROLES)

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

hive> set system:user.name;
system:user.name=hadoop
hive> GRANT CREATE ON DATABASE default TO USER hadoop;
hive> CREATE TABLE auth_test (key INT, value STRING);

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

hive> SHOW GRANT USER hadoop ON DATABASE default;  
database default  
principalName hadoop  
principalType USER  
privilege Create  
grantTime Wed Mar 08 19:18:10 EDT 2013  
grantor hadoop  

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

hive> CREATE TABLE auth_test_group(a int,b int);
hive> SELECT * FROM auth_test_group;
Authorization failed:No privilege 'Select' found for inputs
{ database:default, table:auth_test_group, columnName:a}.
Use show grant to get more details.
hive> GRANT SELECT on table auth_test_group to group hadoop;
hive> SELECT * FROM auth_test_group;
OK
Time taken: 0.119 seconds

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

hive> CREATE TABLE auth_test_role (a int , b int);
hive> SELECT * FROM auth_test_role;
Authorization failed:No privilege 'Select' found for inputs
{ database:default, table:auth_test_role, columnName:a}.
Use show grant to get more details.
hive> CREATE ROLE users_who_can_select_auth_test_role;
hive> GRANT ROLE users_who_can_select_auth_test_role TO USER hadoop;
hive> GRANT SELECT ON TABLE auth_test_role
> TO ROLE users_who_can_select_auth_test_role;
hive> SELECT * FROM auth_test_role;
OK
Time taken: 0.103 seconds

五、分区表级别的授权

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

hive> ALTER TABLE auth_part
> SET TBLPROPERTIES ("PARTITION_LEVEL_PRIVILEGE"="TRUE");
Authorization failed:No privilege 'Alter' found for inputs
{database:default, table:auth_part}.
Use show grant to get more details.

六、自动授权

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

<property>
  <name>hive.security.authorization.createtable.owner.grants</name>
  <value>select,drop</value>
</property>

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

<property>
  <name>hive.security.authorization.createtable.user.grants</name>
  <value>irwin,hadoop:select;tom:create</value>
</property>

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

同样的配置也可以作用于组授权和角色授权

hive.security.authorization.createtable.group.grants
hive.security.authorization.createtable.role.grants

七、删除授权

--回收用户hadoop的create授权
revoke create on database default from user hadoop;

--回收组hadoop的select授权
revoke select on database default from group hadoop;

附录:常用的授权关键字

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

 为表加载本地数据的权限

猜你喜欢

转载自yugouai.iteye.com/blog/1864772
今日推荐