Hive には、ストレージに基づいた認証と標準 SQL に基づいた認証の 2つの認証モードがあります。 詳細については、Hive の『認証ガイド』をご参照ください。

両方の認証方法は競合することなく同時に設定されます。

ストレージベースの認証 (Hive メタストア向け)

クラスター内のユーザーが HDFS または Hive クライアントを介して Hive 内のデータに直接アクセスする場合は、権限制御は HDFS 内の Hive データに対して実行される必要があります。 この権限制御によって、Hive SQL に関する操作の権限が制御されます。

詳細については、Hive の『ストレージベースの認証』ガイドをご参照ください。

設定の追加

クラスター設定管理ページで、[Hive] > [設定] > [hive-site.xml] > [カスタム設定の追加] の順にクリックします。

<property>
<name>hive.metastore.pre.event.listeners</name>
    <value>org.apache.hadoop.hive.ql.security.authorization.AuthorizationPreEventListener</value>
</property>
<property>
<name>hive.security.metastore.authorization.manager</name>
    <value>org.apache.hadoop.hive.ql.security.authorization.StorageBasedAuthorizationProvider</value>
</property>
<property>
<name>hive.security.metastore.authenticator.manager</name>
    <value>org.apache.hadoop.hive.ql.security.HadoopDefaultMetastoreAuthenticator</value>
</property>

Hive メタストアの再起動

クラスター設定管理ページで Hive メタストアを再起動します。

HDFS 認証制御

E-MapReduce 内の Kerberos セキュリティクラスターの場合は、Hive ウェアハウスに対する HDFS 認証が設定されています。

非 Kerberos セキュリティクラスターの場合は、以下の手順で基本的な HDFS 認証を設定する必要があります。

  • HDFS 権限の有効化
  • Hive ウェアハウスに対する権限の設定
    hadoop fs -chmod 1771 /user/hive/warehouse
    It can be set as follows, in which 1 denotes stick bit (i.e. cannot delete files/folders created by others)
    hadoop fs -chmod 1777 /user/hive/warehouse

基本的な権限セットを使用して、フォルダウェアハウスを許可することによって、ユーザーとユーザーグループは通常どおりテーブルの作成、読み取り、および書き込みを実行します。

sudo su has
      #Grant rwx permission of folder warehouse to user test
      hadoop fs -setfacl -m user:test:rwx /user/hive/warehouse
      #Grant rwx permission of folder warehouse to user hivegrp
      hadoop fs -setfacl -m group:hivegrp:rwx /user/hive/warehouse

HDFS 許可によって、ユーザーとユーザーグループは通常どおりテーブルの作成、読み取り、および書き込みを実行します。さまざまなユーザーによって作成された Hive テーブル内のデータには作成したユーザー自身しかアクセスしません。

検証

  • test ユーザーが testtbl テーブルを作成します。
    hive> create table testtbl(a string);
    FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:Got exception: org.apache.hadoop.security.AccessControlException Permission denied: user=test, access=WRITE, inode="/user/hive/warehouse/testtbl":hadoop:hadoop:drwxrwx--t
    at org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.check(FSPermissionChecker.java:320)
    at org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.check(FSPermissionChecker.java:292)

    権限がないためエラーが発生します。 test ユーザーに権限を付与する必要があります。

    #Switch from root account to has account
    su has
    #Add ACL and grant rwx permissions of the directory warehouse to the account test.
     hadoop fs -setfacl -m user:test:rwx /user/hive/warehouse

    test アカウントがデータベースを正常に再作成します。

    hive> create table testtbl(a string);
    OK
    Time taken: 1.371 seconds
    #View the directory of testtbl in HDFS. From the permissions it can be seen that only the groups test and hadoop can read data from the table created by the user test, while other users have no permissions
    hadoop fs -ls /user/hive/warehouse
    drwxr-x---   - test hadoop          0 2017-11-25 14:51 /user/hive/warehouse/testtbl
    #Insert a record
    hive>insert into table testtbl select "hz"
  • foo ユーザーがテーブル testtbl にアクセスします。
    #drop table
    hive> drop table testtbl;
    FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:Permission denied: user=foo, access=READ, inode="/user/hive/warehouse/testtbl":test:hadoop:drwxr-x---
        at org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.check(FSPermissionChecker.java:320)
        at org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.checkPermission(FSPermissionChecker.java:219)
        at org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.checkPermission(FSPermissionChecker.java:190)
    #alter table
    hive> alter table testtbl add columns(b string);
    FAILED: SemanticException Unable to fetch table testtbl. java.security.AccessControlException: Permission denied: user=foo, access=READ, inode="/user/hive/warehouse/testtbl":test:hadoop:drwxr-x---
        at org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.check(FSPermissionChecker.java:320)
        at org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.checkPermission(FSPermissionChecker.java:219)
        at org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.checkPermission(FSPermissionChecker.java:190)
        at org.apache.hadoop.hdfs.server.namenode.FSDirectory.checkPermission(FSDirectory.java:1720)
    #select
    hive> select * from testtbl;
    FAILED: SemanticException Unable to fetch table testtbl. java.security.AccessControlException: Permission denied: user=foo, access=READ, inode="/user/hive/warehouse/testtbl":test:hadoop:drwxr-x---
        at org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.check(FSPermissionChecker.java:320)
        at org.apache.hadoop.hdfs.server.namenode.FSPermissionChecker.checkPermission(FSPermissionChecker.java:219)

    foo は test ユーザーが作成したテーブルを操作しません。 foo に権限を付与するには HDFS 認証が必要です。

    su has
    #Only read permission is granted, and write permission can also be granted as needed (for example, alter)
    #Note: -R: Set files in the folder testtbl to readable
    hadoop fs -setfacl -R -m user:foo:r-x /user/hive/warehouse/testtbl
    #The table can be selected successfully
    hive> select * from testtbl;
    OK
    hz
    Time taken: 2.134 seconds, Fetched: 1 row(s)
    Hive ユーザーグループを作成して権限付与し、Hive ユーザーグループに新しいユーザーを追加します。

標準 SQL ベースの認証

  • シナリオ

    クラスターユーザーは HDFS または Hive クライアントを介して Hive 内のデータにアクセスしません。アクセスする唯一の方法は HiveServer (beeline、jdbc など) を介して Hive 関連コマンドを実行することです。 標準 SQL ベース認証を使用します。

    ユーザーが Hive シェルまたは同様の方法を使用し、ユーザーのクライアント内の hive-site.xml が設定されていない場合は、以下の設定が実装されていない場合でも、通常は Hive にアクセスします。

    詳細については、Hive の『標準 SQL ベースの認証』ガイドをご参照ください。

  • 設定の追加
    • 設定は HiveServer に提供されます。
    • クラスター設定管理ページで、[Hive] > [設定] > [ hive-site.xml] > [カスタム設定の追加] の順にクリックします。
      <property>
      <name>hive.security.authorization.enabled</name>
       <value>true</value>
      </property>
       <property>
      <name>hive.users.in.admin.role</name>
       <value>hive</value>
      </property>
       <property>
      <name>hive.security.authorization.createtable.owner.grants</name>
       <value>ALL</value>
      </property>
  • HiveServer2 の再起動

    クラスター設定管理ページで HHiveServer2 を再起動します。

  • 権限操作コマンド

    コマンド操作の詳細については、『こちら』をクリックします。

  • 検証
    • foo ユーザーは beeline を介して test ユーザーのテーブル testtbl にアクセスします。
      2: jdbc:hive2://emr-header-1.cluster-xxx:10> select * from testtbl;
      Error: Error while compiling statement: FAILED: HiveAccessControlException Permission denied: Principal [name=foo, type=USER] does not have following privileges for operation QUERY [[SELECT] on Object [type=TABLE_OR_VIEW, name=default.testtbl]] (state=42000,code=40000)
    • 権限の付与
      Switch to account test to grant select permission to user foo
      hive> grant select on table testtbl to user foo;
       OK
       Time taken: 1.205 seconds
    • foo は通常は select 文を実行します。
      0: jdbc:hive2://emr-header-1.cluster-xxxxx:10> select * from testtbl;
      INFO  : OK
      +------------+--+
      | testtbl.a  |
      +------------+--+
      | hz         |
      +------------+--+
      1 row selected (0.787 seconds)
    • 権限を取り消します。
      Switch to account test, and revoke the select permission from user foo
        hive> revoke select from user foo;
          OK
          Time taken: 1.094 seconds
    • foo は testtbl のデータに対して select 文を実行しません。
      User foo cannot select data from table testtbl.
      Error: Error while compiling statement: FAILED: HiveAccessControlException Permission denied: Principal [name=foo, type=USER] does not have following privileges for operation QUERY [[SELECT] on Object [type=TABLE_OR_VIEW, name=default.testtbl]] (state=42000,code=40000)