HIVE授权管理,类似于操作系统权限可以授予给不同的主题,如用户(USER),组(GROUP),角色(ROLES),Hive还是支持相当多的权限管理功能,满足一般数据仓库的使用,同时HIVE能支持自定义权限。
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. Note that the default gives the creator of a table no access to the
      table (but see HIVE-8067).
    </description>
  </property>


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



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


<property>
    <name>hive.metastore.authorization.storage.checks</name>
    <value>false</value>
    <description>
      Should the metastore do authorization checks against the underlying storage (usually hdfs)
      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操作定义用户和组权限。



4、自动授权
4.1、属性hive.security.authorization.createtable.owner.grants

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

决定了

建表者对表拥有的权限,一版情况下,有select和drop



4.2、特定的用户可以被在表创建的时候自动授予其权限

<property>
    <name>hive.security.authorization.createtable.user.grants</name>
    #<value/>
    <value>irwin,hadoop:select;tom:create</value>
    <description>
      the privileges automatically granted to some users whenever a table gets created.
      An example like "userX,userY:select;userZ:create" will grant select privilege to userX and userY,
      and grant create privilege to userZ whenever a new table created.
    </description>
  </property>

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



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

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


5、授权与回收


5.1、用户、组、角色受权


GRANT ALL on database default to group hive; // hive组的用户有全部权限 
  
 GRANT ALL on database default to user hive1; // hive1用户有全部权限 
  
 GRANT SELECT on table tableName to group hive; // hive组对tableName表只有select权限 
  
 GRANT SELECT on table tableName to user hive2; // hive2用户对tableName表只有select权限


上面是组和用户的设置。还有角色的设置,与组和用户相同。




5.2、删除授权
--回收用户hadoop的create授权
revoke create on database default from user hadoop;
--回收组hadoop的select授权
revoke select on database default from group hadoop;



6、Hive超级管理员权限
开启权限控制有Hive的权限功能还有一个需要完善的地方,那就是“超级管理员”。 Hive中没有超级管理员,任何用户都可以进行Grant/Revoke操作,为了完善“超级管理员”,必须添加hive.semantic.analyzer.hook配置,并实现自己的权限控制类
JAVA代码+hive-site配置实现,本人不再研究。