You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by de...@apache.org on 2023/09/07 12:36:48 UTC
[hive] branch master updated: HIVE-27461: HiveMetaStoreAuthorizer should log the root cause of checkPrivileges (#4448) (Wechar Yu, reviewed by Attila Turoczy, Denys Kuzmenko, Zhihua Deng)
This is an automated email from the ASF dual-hosted git repository.
dengzh pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hive.git
The following commit(s) were added to refs/heads/master by this push:
new 88f4336db32 HIVE-27461: HiveMetaStoreAuthorizer should log the root cause of checkPrivileges (#4448) (Wechar Yu, reviewed by Attila Turoczy, Denys Kuzmenko, Zhihua Deng)
88f4336db32 is described below
commit 88f4336db3263208ba728eb5679a21a5819ca0df
Author: Wechar Yu <yu...@gmail.com>
AuthorDate: Thu Sep 7 20:36:42 2023 +0800
HIVE-27461: HiveMetaStoreAuthorizer should log the root cause of checkPrivileges (#4448) (Wechar Yu, reviewed by Attila Turoczy, Denys Kuzmenko, Zhihua Deng)
---
.../plugin/metastore/HiveMetaStoreAuthorizer.java | 14 +++++++-------
.../plugin/metastore/TestHiveMetaStoreAuthorizer.java | 18 ++++++++++++++++++
2 files changed, 25 insertions(+), 7 deletions(-)
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/HiveMetaStoreAuthorizer.java b/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/HiveMetaStoreAuthorizer.java
index 7f4cda8d922..b5199ad45d1 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/HiveMetaStoreAuthorizer.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/HiveMetaStoreAuthorizer.java
@@ -39,14 +39,17 @@ import org.apache.hadoop.hive.metastore.api.Database;
import org.apache.hadoop.hive.metastore.api.Partition;
import org.apache.hadoop.hive.metastore.api.PartitionSpec;
import org.apache.hadoop.hive.metastore.api.TableMeta;
+import org.apache.hadoop.hive.metastore.utils.MetaStoreUtils;
import org.apache.hadoop.hive.ql.metadata.HiveException;
import org.apache.hadoop.hive.ql.metadata.HiveUtils;
import org.apache.hadoop.hive.ql.security.HiveMetastoreAuthenticationProvider;
import static org.apache.hadoop.hive.ql.security.authorization.plugin.HivePrivilegeObjectUtils.TablePrivilegeLookup;
import org.apache.hadoop.hive.ql.security.authorization.plugin.metastore.events.*;
+import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAccessControlException;
import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthorizer;
import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthorizerFactory;
import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthzContext;
+import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthzPluginException;
import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthzSessionContext;
import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveMetastoreClientFactoryImpl;
import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveOperationType;
@@ -109,7 +112,7 @@ public class HiveMetaStoreAuthorizer extends MetaStorePreEventListener implement
}
} catch (Exception e) {
LOG.error("HiveMetaStoreAuthorizer.onEvent(): failed", e);
- throw new MetaException(e.getMessage());
+ throw MetaStoreUtils.newMetaException(e);
}
LOG.debug("<== HiveMetaStoreAuthorizer.onEvent(): EventType=" + preEventContext.getEventType());
@@ -563,7 +566,8 @@ public class HiveMetaStoreAuthorizer extends MetaStorePreEventListener implement
return ret;
}
- private void checkPrivileges(final HiveMetaStoreAuthzInfo authzContext, HiveAuthorizer authorizer) throws MetaException {
+ private void checkPrivileges(final HiveMetaStoreAuthzInfo authzContext, HiveAuthorizer authorizer)
+ throws HiveAccessControlException, HiveAuthzPluginException {
LOG.debug("==> HiveMetaStoreAuthorizer.checkPrivileges(): authzContext=" + authzContext + ", authorizer=" + authorizer);
HiveOperationType hiveOpType = authzContext.getOperationType();
@@ -571,11 +575,7 @@ public class HiveMetaStoreAuthorizer extends MetaStorePreEventListener implement
List<HivePrivilegeObject> outputHObjs = authzContext.getOutputHObjs();
HiveAuthzContext hiveAuthzContext = authzContext.getHiveAuthzContext();
- try {
- authorizer.checkPrivileges(hiveOpType, inputHObjs, outputHObjs, hiveAuthzContext);
- } catch (Exception e) {
- throw new MetaException(e.getMessage());
- }
+ authorizer.checkPrivileges(hiveOpType, inputHObjs, outputHObjs, hiveAuthzContext);
LOG.debug("<== HiveMetaStoreAuthorizer.checkPrivileges(): authzContext=" + authzContext + ", authorizer=" + authorizer);
}
diff --git a/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java b/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java
index ec9a93c0837..d94764b4e5a 100644
--- a/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java
+++ b/ql/src/test/org/apache/hadoop/hive/ql/security/authorization/plugin/metastore/TestHiveMetaStoreAuthorizer.java
@@ -19,6 +19,7 @@
package org.apache.hadoop.hive.ql.security.authorization.plugin.metastore;
import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.exception.ExceptionUtils;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hive.common.FileUtils;
import org.apache.hadoop.hive.metastore.ColumnType;
@@ -39,6 +40,8 @@ import org.junit.Test;
import java.util.Map;
import java.io.File;
+import java.util.Arrays;
+import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -411,4 +414,19 @@ public class TestHiveMetaStoreAuthorizer {
fail("testU_DropDataConnector_authorizedUser() failed with " + e);
}
}
+
+ @Test
+ public void testUnAuthorizedCause() {
+ UserGroupInformation.setLoginUser(UserGroupInformation.createRemoteUser(unAuthorizedUser));
+ try {
+ Database db = new DatabaseBuilder()
+ .setName(dbName)
+ .build(conf);
+ hmsHandler.create_database(db);
+ } catch (Exception e) {
+ String[] rootCauseStackTrace = ExceptionUtils.getRootCauseStackTrace(e);
+ assertTrue(Arrays.stream(rootCauseStackTrace)
+ .anyMatch(stack -> stack.contains(DummyHiveAuthorizer.class.getName())));
+ }
+ }
}