Hive Authorization Configuration 권한 설정

IT기술/hadoop family|2021. 1. 17. 12:36

2020-05-15 작성

 

Hive 권한 설정이 잘 안돼서 거의 4일을 버렸다..

hadoop설정은 버전별로 안되는 경우가 많고,

인터넷에 레퍼런스가 정확한게 많지 않아 너무 찾기 힘들었다.

열심히 해봐서 안되면 답이 없는 것이다.

하란대로 해서 안되면 답을 알 수 없는 노가다가 돼버린다. 결국 구현을 못하고 끝날수도 있다.

하지만 다행히 방법을 찾아서 포스트를 작성한다.

 

cloudera version: 5.16.1
hive version: 1.1

 

핵심 레퍼런스는 다음 url을 참고하면 된다.

https://cwiki.apache.org/confluence/display/Hive/SQL+Standard+Based+Hive+Authorization#SQLStandardBasedHiveAuthorization-ForHive0.14andNewer

 

목록 중 For Hive 0.14 and Newer에 보면 설정 방법이 나오는데, 다음을 세팅해준다.
(내용을 읽어보면 좋아서 그대로 가져왔다.)

 

Set the following in hive-site.xml: cloudera의 경우 "hive-site.xml에대한 Hive 서비스고급구성스니펫"에 입력해주면 된다.

  • hive.server2.enable.doAs to false. : cloudera에서는 hive config상에서 수정 가능하다.
  • hive.users.in.admin.role to the list of comma-separated users who need to be added to admin role. Note that a user who belongs to the admin role needs to run the "set role" command before getting the privileges of the admin role, as this role is not in current roles by default.
  • Add org.apache.hadoop.hive.ql.security.authorization.MetaStoreAuthzAPIAuthorizerEmbedOnly to hive.security.metastore.authorization.manager. (It takes a comma separated list, so you can add it along with StorageBasedAuthorization parameter, if you want to enable that as well).
    This setting disallows any of the authorization api calls to be invoked in a remote metastore. HiveServer2 can be configured to use embedded metastore, and that will allow it to invoke metastore authorization api. Hive cli and any other remote metastore users would be denied authorization when they try to make authorization api calls. This restricts the authorization api to privileged HiveServer2 process. You should also ensure that the metastore rdbms access is restricted to the metastore server and hiverserver2.
  • hive.security.authorization.manager to org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdConfOnlyAuthorizerFactory. This will ensure that any table or views created by hive-cli have default privileges granted for the owner.

Set the following in hiveserver2-site.xml: 이 파일은 존재하지 않을 수도 있다. cloudera의 경우 "hive-site.xml에대한 HiveServer2 고급구성스니펫"에 입력해주면 된다.

  • hive.security.authorization.manager=org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdHiveAuthorizerFactory
  • hive.security.authorization.enabled=true
  • hive.security.authenticator.manager=org.apache.hadoop.hive.ql.security.SessionStateUserAuthenticator
  • hive.metastore.uris=' ' : 이 설정은 설정해보니 불필요한 에러가 발생하여 제외하였다.

xml로는 다음과 같다.

hive-site.xml에대한 Hive 서비스고급구성스니펫: 
<property>
    <name>hive.users.in.admin.role</name>
    <value>admin</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.security.metastore.authorization.manager</name>
    <value>org.apache.hadoop.hive.ql.security.authorization.MetaStoreAuthzAPIAuthorizerEmbedOnly</value>
</property>

hive-site.xml에대한 HiveServer2 고급구성스니펫: 
<property>
    <name>hive.security.authorization.manager</name>
    <value>org.apache.hadoop.hive.ql.security.authorization.plugin.sqlstd.SQLStdHiveAuthorizerFactory</value>
</property>
<property>
    <name>hive.security.authorization.enabled</name>
    <value>true</value>
</property>
<property>
    <name>hive.security.authenticator.manager</name>
    <value>org.apache.hadoop.hive.ql.security.SessionStateUserAuthenticator</value>
</property>

위 설정을 추가한 후 beeline으로 접속한 후 테스트를 해본다. 위 설정에서 admin role을 admin 계정으로 주었고, hue에도 계정이 있어야 한다. 만약 문서에 나온것만으로 잘되면 다음과 같이 될 것이다. 하지만 나는 잘 안됐다.

 

[irteam@dnaa-opr-t1001 ~]$ beeline -u jdbc:hive2://[host주소]:10000 -n admin
Beeline version 1.1.0-cdh5.16.1 by Apache Hive
0: jdbc:hive2://dnaa-opr-t1001:10000> show current roles;
INFO  : OK
+---------+--+
|  role   |
+---------+--+
| public  |
+---------+--+
1 row selected (2.028 seconds)
0: jdbc:hive2://dnaa-opr-t1001:10000> select * from default.aaa; => 권한이 없어 안되는것 확인
Error: Error while compiling statement: FAILED: HiveAccessControlException Permission denied: Principal [name=admin, type=USER] does not have following privileges for operation QUERY [[SELECT] on Object [type=TABLE_OR_VIEW, name=default.aaa]] (state=42000,code=40000)
0: jdbc:hive2://dnaa-opr-t1001:10000> set role admin;
INFO  : OK
No rows affected (0.022 seconds)
0: jdbc:hive2://dnaa-opr-t1001:10000> show current roles;
INFO  : Compiling command(queryId=hive_20200515160404_c358a275-56b9-4be4-b9df-b8c0e9d0bb13): show current roles
INFO  : OK
+--------+--+
|  role  |
+--------+--+
| admin  |
+--------+--+
0: jdbc:hive2://dnaa-opr-t1001:10000> select * from default.aaa;
INFO  : OK
+---------+--+
| aaa.id  |
+---------+--+
| 222     |
| 111     |
| 333     |
+---------+--+
3 rows selected (0.169 seconds)

 

위에 썼듯이 나의 경우는 잘 안됐다. 그럴경우 다음 config 중 필요한 것을 추가해보자.

아마도 위 설정 중 Factory 관련된 것들은 다음 설정이 필요한 것 같다.
<property>
    <name>hive.security.authorization.task.factory</name>
    <value>org.apache.hadoop.hive.ql.parse.authorization.HiveAuthorizationTaskFactoryImpl</value>
</property>
 
다음 설정은 hue에서 권한 설정이 실행되지 않을 때 필요하다.
<property>
    <name>hive.security.authorization.sqlstd.confwhitelist.append</name>
    <value>hive\.server2\.proxy\.user</value>
</property>
 
다음 설정은 꼭 필요하지 않다. 권한설정이 완료되면 grant 설정이 전혀 없고 수동으로 권한을 넣어줘야 하는데, 이 설정을하면 create table 시 table owner를 기준으로 자동으로 grant 설정을 넣어준다.
<property>
    <name>hive.security.authorization.createtable.owner.grants</name>
    <value>ALL</value>
</property>

 

여기까지 완료되면 설정은 다했다.

beeline과 hue로 접속하면 권한이 없는 계정으로는 테이블에 접근할 수 없다.

누구에게나 공개하고 싶은 테이블은 public 권한을 주면 된다.

다만 hive 명령어로 접속하면 다른계정에서도 접근이 가능하니,

보안을 위해서 admin을 제외하고 hive 명령어에 접근할 수 없도록 해야한다.

 

이제 핵심 레퍼런스를 참고하여 grant로 권한을 넣고 사용하면 된다.

 

그러나 그래도 안된다면, 다음을 확인해보자.

hadoop.proxyuser.hive.groups *[default] 인지 확인
HDFS 상의 권한 설정
– sudo -u hdfs hdfs dfs -chown -R hive:hive /user/hive/warehosue
– sudo -u hdfs hdfs dfs -chmod -R 771 /user/hive/warehouse

 

참고 사이트:

https://cwiki.apache.org/confluence/display/Hive/SQL+Standard+Based+Hive+Authorization#SQLStandardBasedHiveAuthorization-ForHive0.14andNewer

https://qiita.com/bwtakacy/items/2777253ae21fc84b7543

https://www.slideshare.net/julingks/hive-authorization-michael130702

댓글()