美文网首页
基于元数据和sql标准权限验证

基于元数据和sql标准权限验证

作者: 留年已忘却 | 来源:发表于2016-12-23 23:55 被阅读0次

    简介:

    用例:

    (1) hive做为table的存储层,spark sql,mapreduce, Presto 等等通过 Hive's HCatalog API 访问元数据信息, 进而访问hdfs数据, 此时要对hdfs访问做权限控制(hdfs 默认已经处理),元数据访问需要做权限控制。
    (2) hive sql 执行引擎, hive的一个非常普遍的用法,主要针对sql的用户和BI工具
    hive 客户端用户 (官方建议抛弃)
    ODBC/JDBC 和 HiveServer2 Api(Beeline CLI)
    针对上面的用例hive官方提供三种权限控制: 基于元数据存储、 基于sql标准、 默认的hive授权。
    本文主要讲解基于元数据存储(hive cli)和基于sql标准(hiveserver)的结合使用。

    基于元数据存储的授权:

    hivemetaserver 的引进: 具体参考hive基础架构
    此功能在hive 0.10 加入, hive 客户端执行时访问 hivemetaserver 服务来获取元数据, 此时可以根据数据库和表和分区等文件夹的权限在metaserver端来控制用户权限。

    基于sql标准的授权:

    此功能在hive 0.13.0加入, 直接通过mysql 访问metadata,通过标准的sql权限来进行访问控制, 目前不支持show databases和 show tables的权限控制

    通过配置hive.server2.enable.doAs 为false 来控制访问hdfs的文件权限, 当sql标准权限通过时,可以直接操作hdfs,不受hdfs权限影响

    通过设置
    hive.security.metastore.authorization.managerorg.apache.hadoop.hive.ql.security.authorization.MetaStoreAuthzAPIAuthorizerEmbedOnly来禁止客户端进行sql 授权操作。

    配置信息:hive-site.xml
    <property>
      <name>hive.users.in.admin.role</name>
      <value>bfd_hz</value>
    </property>
    <property>
        <name>hive.security.metastore.authorization.manager</name>
    <value>org.apache.hadoop.hive.ql.security.authorization.StorageBasedAuthorizationProvider,org.apache.hadoop.hive.ql.security.authorization.MetaStoreAuthzAPIAuthorizerEmbedOnly</value>
    </property>
    <property>
        <name>hive.security.metastore.authenticator.manager</name>
     <value>org.apache.hadoop.hive.ql.security.HadoopDefaultMetastoreAuthenticator</value>
    </property>
    <property>
        <name>hive.security.authorization.enabled</name>
        <value>true</value>
    </property>
    <property>
        <name>hive.security.authorization.manager</name>
     <value>org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdConfOnlyAuthorizerFactory</value>
    </property>
     <property>
        <name>hive.warehouse.subdir.inherit.perms</name>
        <value>false</value>
      </property>
    
    配置信息:hiveserver2-site.xml
    <property>
      <name>hive.metastore.pre.event.listeners</name>
      <value>org.apache.hadoop.hive.ql.security.authorization.AuthorizationPreEventListener</value>
      <description>List of comma separated listeners for metastore events.</description>
    </property>
     
    <property>
      <name>hive.metastore.uris</name>
      <value>thrift://172.24.3.57:9083</value>
    </property>
    
    配置信息:hivemetastore-site.xml
    <property>
        <name>hive.security.authorization.manager</name>
     <value>org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdHiveAuthorizerFactory</value>
    </property>
    <property>
        <name>hive.security.authenticator.manager</name>
        <value>org.apache.hadoop.hive.ql.security.SessionStateUserAuthenticator</value>
    </property>
    <property>
        <name>hive.server2.enable.doAs</name>
        <value>false</value>
    </property>
    <property>
        <name>hive.metastore.uris</name>
        <value/>
    </property>
    

    基于元数据存储的授权测试:

    (1) 不能进行授权
    org.apache.hadoop.hive.ql.security.authorization.MetaStoreAuthzAPIAuthorizerEmbedOnly


    Paste_Image.png

    (2) 客户端创建表的时候,自动加入自己创建表的授权。(client 端 hive-site.xml org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdConfOnlyAuthorizerFactory)


    Paste_Image.png
    Paste_Image.png

    (3) 不同组用户访问bfd_hz 创建的test1表


    Paste_Image.png

    基于sql标准的授权测试:

    bfd_hz 为管理员, wenting 和 baseline 为普通用户
    (1) 管理员可以切换成admin,进行授权, 普通用户不能。


    Paste_Image.png
    Paste_Image.png

    (2) bfd_hz 用户创建bfd_hz 库 bfd_hz1 表
    create database bfd_hz; use bfd_hz;create table bfd_hz1(id int);


    Paste_Image.png
    (3) wenting 用户创建wenting库 wenting1 表
    create database wenting; use wenting; create table wenting1(id int);
    Paste_Image.png
    (4) wenting 用户对bfd_hz 的表进行操作(没有权限)
    Paste_Image.png

    (5) bfd_hz 授权表bfd_hz1 权限给用户wenting
    set role admin; grant select on bfd_hz1 to user wenting;


    Paste_Image.png
    Paste_Image.png
    (6) 创建角色,并授权给baseline 用户,让其能够访问bfd_hz1 表
    set role admin; create role team_baseline;
    grant select on bfd_hz.bfd_hz1 to role team_baseline;
    grant team_baseline to user baseline;
    Paste_Image.png
    baseline 用户访问
    Paste_Image.png
    (7)给baseline insert权限, 不受hdfs 文件权限影响
    set role admin;
    grant insert on bfd_hz.bfd_hz1 to role team_baseline;
    Paste_Image.png

    参考网站
    https://cwiki.apache.org/confluence/display/Hive/SQL+Standard+Based+Hive+Authorization
    http://www.cnblogs.com/yurunmiao/p/4449439.html
    总结:
    阻止了客户端hive 的授权操作

    相关文章

      网友评论

          本文标题:基于元数据和sql标准权限验证

          本文链接:https://www.haomeiwen.com/subject/rgllvttx.html